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.
20 #if defined TIZEN_WEARABLE
31 #include <net/route.h>
32 #include <arpa/inet.h>
35 #include <sys/ioctl.h>
36 #include <vconf-keys.h>
37 #include <syspopup_caller.h>
39 #include <bundle_internal.h>
40 #include <eventsystem.h>
45 #include "wifi-state.h"
47 #define WC_POPUP_EXTRA_DATA_KEY "http://tizen.org/appcontrol/data/connection_type"
48 #define MAC_INFO_FILEPATH "/opt/etc/.mac.info"
49 #define MAC_ADDRESS_MAX_LEN 18
51 static gboolean netconfig_device_picker_test = FALSE;
53 GKeyFile *netconfig_keyfile_load(const char *pathname)
55 GKeyFile *keyfile = NULL;
58 keyfile = g_key_file_new();
59 if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
60 DBG("Unable to open %s, error %s", pathname, error->message);
63 g_key_file_free(keyfile);
70 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
74 gchar *keydata = NULL;
75 gchar *needle = NULL, *directory = NULL;
77 directory = g_strdup(pathname);
78 needle = g_strrstr(directory, "/");
83 if (directory == NULL || (*directory) == '\0') {
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) {
97 keydata = g_key_file_to_data(keyfile, &size, &error);
98 if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
99 DBG("Unable to save %s, error %s", pathname, error->message);
103 chmod(pathname, S_IRUSR | S_IWUSR);
108 void netconfig_start_timer_seconds(guint secs,
109 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
113 if (callback == NULL) {
114 ERR("callback function is NULL");
118 if ((timer_id != NULL && *timer_id != 0)) {
119 ERR("timer already is registered");
123 t_id = g_timeout_add_seconds(secs, callback, user_data);
126 ERR("Can't add timer");
130 if (timer_id != NULL)
134 void netconfig_start_timer(guint msecs,
135 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
139 INFO("Register timer with callback pointer (%p)", callback);
141 if (callback == NULL) {
142 ERR("callback function is NULL");
146 if ((timer_id != NULL && *timer_id != 0)) {
147 ERR("timer already is registered");
151 t_id = g_timeout_add(msecs, callback, user_data);
154 ERR("Can't add timer");
158 if (timer_id != NULL)
162 void netconfig_stop_timer(guint *timer_id)
164 if (timer_id == NULL) {
165 ERR("timer is NULL");
169 if (*timer_id != 0) {
170 g_source_remove(*timer_id);
175 static gboolean __netconfig_test_device_picker()
177 char *favorite_wifi_service = NULL;
179 favorite_wifi_service = wifi_get_favorite_service();
180 if (favorite_wifi_service != NULL) {
181 ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service);
182 g_free(favorite_wifi_service);
189 static void __netconfig_pop_device_picker(void)
191 #if defined TIZEN_WEARABLE
193 app_control_h control = NULL;
195 ret = app_control_create(&control);
196 if (APP_CONTROL_ERROR_NONE != ret) {
197 DBG("failed to create app control");
201 app_control_add_extra_data(control, "viewtype", "scanlist");
203 app_control_set_app_id(control, "org.tizen.wifi");
204 ret = app_control_send_launch_request(control, NULL, NULL);
205 if (APP_CONTROL_ERROR_NONE == ret)
206 DBG("Launch request sent successfully");
208 app_control_destroy(control);
211 int wifi_ug_state = 0;
213 vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
214 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
219 DBG("Launch Wi-Fi device picker");
220 syspopup_launch("wifi-qs", b);
226 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
228 if (__netconfig_test_device_picker() == TRUE)
229 __netconfig_pop_device_picker();
234 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id)
236 static guint netconfig_wifi_device_picker_service_timer = 0;
238 if (is_set_method != TRUE)
239 return netconfig_wifi_device_picker_service_timer;
241 if (netconfig_wifi_device_picker_service_timer != timer_id)
242 netconfig_wifi_device_picker_service_timer = timer_id;
244 return netconfig_wifi_device_picker_service_timer;
247 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
249 __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
252 static guint __netconfig_wifi_device_picker_get_timer_id(void)
254 return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
257 void netconfig_wifi_enable_device_picker_test(void)
259 netconfig_device_picker_test = TRUE;
262 void netconfig_wifi_device_picker_service_start(void)
264 const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
267 if (netconfig_device_picker_test == TRUE)
268 netconfig_device_picker_test = FALSE;
272 #if defined TIZEN_WEARABLE
273 if (aul_app_is_running("org.tizen.wifi") > 0) {
274 DBG("wifi app is running");
280 vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
281 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
285 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
286 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
288 __netconfig_wifi_device_picker_set_timer_id(timer_id);
291 void netconfig_wifi_device_picker_service_stop(void)
295 timer_id = __netconfig_wifi_device_picker_get_timer_id();
299 DBG("Clear device picker timer with timer_id %d", timer_id);
301 netconfig_stop_timer(&timer_id);
303 __netconfig_wifi_device_picker_set_timer_id(timer_id);
306 gboolean netconfig_is_wifi_direct_on(void)
308 #if defined TIZEN_P2P_ENABLE
309 int wifi_direct_state = 0;
311 vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
313 DBG("Wi-Fi direct mode %d", wifi_direct_state);
314 return (wifi_direct_state != 0) ? TRUE : FALSE;
320 gboolean netconfig_is_wifi_tethering_on(void)
322 #if defined TIZEN_TETHERING_ENABLE
323 int wifi_tethering_state = 0;
325 vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
327 DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
328 if (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
334 gboolean netconfig_interface_up(const char *ifname)
339 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
343 memset(&ifr, 0, sizeof(ifr));
344 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
346 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
351 ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
352 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
359 DBG("Successfully activated wireless interface");
363 gboolean netconfig_interface_down(const char *ifname)
368 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
372 memset(&ifr, 0, sizeof(ifr));
373 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
375 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
380 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
381 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
388 DBG("Successfully de-activated wireless interface");
392 int netconfig_execute_file(const char *file_path,
393 char *const args[], char *const envs[])
399 register unsigned int index = 0;
400 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
402 while (args[index] != NULL) {
403 DBG("%s", args[index]);
407 if (!(pid = fork())) {
408 DBG("pid(%d), ppid (%d)", getpid(), getppid());
409 DBG("Inside child, exec (%s) command", file_path);
412 if (execve(file_path, args, envs) == -1) {
413 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
414 DBG("Fail to execute command (%s)", error_buf);
417 } else if (pid > 0) {
418 if (waitpid(pid, &status, 0) == -1)
419 DBG("wait pid (%u) status (%d)", pid, status);
421 if (WIFEXITED(status)) {
422 rv = WEXITSTATUS(status);
423 DBG("exited, status=%d", rv);
424 } else if (WIFSIGNALED(status)) {
425 DBG("killed by signal %d", WTERMSIG(status));
426 } else if (WIFSTOPPED(status)) {
427 DBG("stopped by signal %d", WSTOPSIG(status));
428 } else if (WIFCONTINUED(status)) {
435 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
436 DBG("failed to fork(%s)", error_buf);
440 static void on_clat_handler()
445 clat_pid = waitpid(-1, &state, WNOHANG);
447 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
450 int netconfig_execute_clatd(const char *file_path, char *const args[])
455 register unsigned int index = 0;
456 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
458 struct sigaction act;
461 act.sa_handler = on_clat_handler;
462 sigemptyset(&act.sa_mask);
465 state = sigaction(SIGCHLD, &act, 0);
467 DBG("sigaction() : %d");
471 while (args[index] != NULL) {
472 DBG("%s", args[index]);
476 if (!(pid = fork())) {
477 DBG("pid(%d), ppid (%d)", getpid(), getppid());
478 DBG("Inside child, exec (%s) command", file_path);
481 if (execvp(file_path, args) == -1) {
482 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
483 ERR("Fail to execute command (%s)", error_buf);
486 } else if (pid > 0) {
487 ERR("Success to launch clatd");
491 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
492 DBG("failed to fork(%s)", error_buf);
496 int __netconfig_get_interface_index(const char *interface_name)
501 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
503 if (interface_name == NULL) {
504 DBG("Inteface name is NULL");
509 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
511 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
512 DBG("Failed to create socket : %s", error_buf);
516 memset(&ifr, 0, sizeof(ifr));
517 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
518 result = ioctl(sock, SIOCGIFINDEX, &ifr);
522 DBG("Failed to get ifr index: %s", error_buf);
526 return ifr.ifr_ifindex;
529 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
533 struct sockaddr_in addr_in;
535 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
537 memset(&ifr, 0, sizeof(ifr));
539 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
541 if (ifr.ifr_ifindex < 0)
544 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
546 memset(&rt, 0, sizeof(rt));
548 rt.rt_flags = RTF_UP | RTF_HOST;
549 memset(&addr_in, 0, sizeof(struct sockaddr_in));
550 addr_in.sin_family = address_family;
551 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
552 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
554 memset(&addr_in, 0, sizeof(struct sockaddr_in));
555 addr_in.sin_family = address_family;
556 addr_in.sin_addr.s_addr = INADDR_ANY;
557 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
559 memset(&addr_in, 0, sizeof(struct sockaddr_in));
560 addr_in.sin_family = AF_INET;
561 addr_in.sin_addr.s_addr = inet_addr(subnet);
562 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
564 rt.rt_dev = ifr.ifr_name;
567 sock = socket(PF_INET, SOCK_DGRAM, 0);
570 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
571 DBG("Failed to create socket : %s", error_buf);
575 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
576 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
577 DBG("Failed to set route address : %s", error_buf);
587 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
591 struct sockaddr_in addr_in;
593 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
595 memset(&ifr, 0, sizeof(ifr));
596 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
598 if (ifr.ifr_ifindex < 0)
601 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
603 memset(&rt, 0, sizeof(rt));
605 rt.rt_flags = RTF_UP;
606 memset(&addr_in, 0, sizeof(struct sockaddr_in));
607 addr_in.sin_family = address_family;
608 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
609 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
611 memset(&addr_in, 0, sizeof(struct sockaddr_in));
612 addr_in.sin_family = address_family;
613 addr_in.sin_addr.s_addr = inet_addr(subnet);
614 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
615 rt.rt_dev = ifr.ifr_name;
618 sock = socket(PF_INET, SOCK_DGRAM, 0);
621 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
622 DBG("Failed to create socket : %s", error_buf);
626 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
627 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
628 DBG("Failed to set route address : %s", error_buf);
638 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
643 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
645 memset(&rt, 0, sizeof(rt));
647 rt.rtmsg_dst_len = prefix_len;
649 rt.rtmsg_flags = RTF_UP | RTF_HOST;
652 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
653 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
654 DBG("inet_pton failed : %s", error_buf);
658 if (gateway != NULL) {
659 rt.rtmsg_flags |= RTF_GATEWAY;
660 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
661 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
662 DBG("inet_pton failed : %s", error_buf);
669 fd = socket(AF_INET6, SOCK_DGRAM, 0);
671 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
672 DBG("Failed to create socket : %s", error_buf);
676 rt.rtmsg_ifindex = 0;
680 memset(&ifr, 0, sizeof(ifr));
681 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
682 ioctl(fd, SIOCGIFINDEX, &ifr);
683 rt.rtmsg_ifindex = ifr.ifr_ifindex;
686 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
687 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
688 DBG("Failed to add route: %s", error_buf);
698 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
704 memset(&rt, 0, sizeof(rt));
706 rt.rtmsg_dst_len = prefix_len;
708 rt.rtmsg_flags = RTF_UP | RTF_HOST;
710 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
715 if (gateway != NULL) {
716 rt.rtmsg_flags |= RTF_GATEWAY;
717 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
725 fd = socket(AF_INET6, SOCK_DGRAM, 0);
729 rt.rtmsg_ifindex = 0;
733 memset(&ifr, 0, sizeof(ifr));
734 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
735 ioctl(fd, SIOCGIFINDEX, &ifr);
736 rt.rtmsg_ifindex = ifr.ifr_ifindex;
739 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
740 DBG("Failed to del route: %d\n", err);
750 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
752 #if defined TIZEN_P2P_ENABLE
754 DBG("Launch Wi-Fi direct daemon");
756 const char *path = "/usr/bin/wifi-direct-server.sh";
757 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
758 char *const envs[] = { NULL };
760 ret = netconfig_execute_file(path, args, envs);
762 ERR("Failed to launch Wi-Fi direct daemon");
763 netconfig_error_wifi_direct_failed(context);
766 wifi_complete_launch_direct(wifi, context);
769 wifi_complete_launch_direct(wifi, context);
774 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
778 static gboolean is_found_noti_exists = FALSE;
779 static gboolean is_portal_noti_exists = FALSE;
782 ERR("Invalid notification");
786 if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) {
787 if (is_found_noti_exists == FALSE)
790 is_found_noti_exists = FALSE;
791 } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) {
792 if (is_found_noti_exists == TRUE)
795 is_found_noti_exists = TRUE;
796 } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) {
797 if (is_portal_noti_exists == TRUE)
800 is_portal_noti_exists = TRUE;
801 } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) {
802 if (is_portal_noti_exists == FALSE)
805 is_portal_noti_exists = FALSE;
809 bundle_add(b, "_SYSPOPUP_TYPE_", noti);
812 DBG("ssid (%s)", ssid);
813 bundle_add(b, "_AP_NAME_", ssid);
816 ret = syspopup_launch("net.netpopup", b);
821 ERR("Unable to launch noti-popup. Err = %d", ret);
825 DBG("Successfully sent notification (%s)", noti);
829 int netconfig_send_message_to_net_popup(const char *title,
830 const char *content, const char *type, const char *ssid)
833 bundle *b = bundle_create();
835 bundle_add(b, "_SYSPOPUP_TITLE_", title);
836 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
837 bundle_add(b, "_SYSPOPUP_TYPE_", type);
838 bundle_add(b, "_AP_NAME_", ssid);
840 ret = syspopup_launch("net.netpopup", b);
847 void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val)
851 DBG("System event set [%s : %s : %s]", sys_evt, evt_key, evt_val);
854 bundle_add_str(b, evt_key, evt_val);
855 eventsystem_send_system_event(sys_evt, b);
859 #if defined TIZEN_WEARABLE
860 int wc_launch_syspopup(netconfig_wcpopup_type_e type)
868 ERR("Failed to create bundle");
873 case WC_POPUP_TYPE_SESSION_OVERLAPPED:
874 bundle_add(b, "event-type", "wps-session-overlapped");
876 case WC_POPUP_TYPE_WIFI_CONNECTED:
877 ssid = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
879 ERR("Failed to get connected ap ssid");
880 ssid = g_strdup(" ");
882 bundle_add(b, "event-type", "wifi-connected");
883 bundle_add(b, "ssid", ssid);
887 case WC_POPUP_TYPE_WIFI_RESTRICT:
888 bundle_add(b, "event-type", "wifi-restrict");
891 ERR("Popup is not supported[%d]", type);
896 ret = syspopup_launch("wc-syspopup", b);
898 ERR("Failed to launch syspopup");
905 int wc_launch_popup(netconfig_wcpopup_type_e type)
908 app_control_h app_control = NULL;
910 ret = app_control_create(&app_control);
911 if (ret != APP_CONTROL_ERROR_NONE) {
912 ERR("Failed to create appcontrol[%d]", ret);
917 case WC_POPUP_TYPE_CAPTIVE_PORTAL:
918 app_control_add_extra_data(app_control, WC_POPUP_EXTRA_DATA_KEY, "captive-portal");
921 ERR("Popup is not supported[%d]", type);
922 app_control_destroy(app_control);
926 app_control_set_app_id(app_control, "com.samsung.weconn-popup");
927 ret = app_control_send_launch_request(app_control, NULL, NULL);
928 if (ret != APP_CONTROL_ERROR_NONE) {
929 DBG("failed appcontrol launch request [%d]", ret);
930 app_control_destroy(app_control);
934 app_control_destroy(app_control);
940 void netconfig_set_vconf_int(const char * key, int value)
944 DBG("[%s: %d]", key, value);
946 ret = vconf_set_int(key, value);
948 ERR("Failed to set");
951 void netconfig_set_vconf_str(const char * key, const char * value)
955 DBG("[%s: %s]", key, value);
957 ret = vconf_set_str(key, value);
959 ERR("Failed to set");
962 char* netconfig_get_env(const char *key)
965 char buf[256], *entry = NULL, *value = NULL, *last;
971 fp = fopen(NETCONFIG_TIZENMOBILEENV, "r");
975 while (fgets(buf, sizeof(buf), fp)) {
977 entry = strtok_r(entry, "=", &last);
979 if (strstr(entry, key)) {
980 entry = strtok_r(NULL, "\n", &last);
983 value = (char*)malloc(len+1);
984 g_strlcpy(value, entry, len+1);
987 value = (char*)malloc(sizeof(char));
988 g_strlcpy(value, "\n", sizeof(char));
999 void netconfig_set_mac_address_from_file(void)
1002 char mac_str[MAC_ADDRESS_MAX_LEN];
1003 gchar *mac_lower_str = NULL;
1006 file = fopen(MAC_INFO_FILEPATH, "r");
1008 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1011 if (fgets(mac_str, sizeof(mac_str), file) == NULL ) {
1012 ERR("Fail to read mac address");
1017 mac_len = strlen(mac_str);
1019 ERR("mac.info is empty");
1024 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1025 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1027 g_free(mac_lower_str);