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>
41 #include <tzplatform_config.h>
46 #include "wifi-state.h"
48 #define WC_POPUP_EXTRA_DATA_KEY "http://tizen.org/appcontrol/data/connection_type"
49 #define MAC_INFO_FILEPATH tzplatform_mkpath(TZ_SYS_SHARE, "/.mac.info")
50 #define MAC_ADDRESS_MAX_LEN 18
52 static gboolean netconfig_device_picker_test = FALSE;
54 GKeyFile *netconfig_keyfile_load(const char *pathname)
56 GKeyFile *keyfile = NULL;
59 keyfile = g_key_file_new();
60 if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
61 DBG("Unable to open %s, error %s", pathname, error->message);
64 g_key_file_free(keyfile);
71 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
75 gchar *keydata = NULL;
76 gchar *needle = NULL, *directory = NULL;
78 directory = g_strdup(pathname);
79 needle = g_strrstr(directory, "/");
84 if (directory == NULL || (*directory) == '\0') {
89 if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) {
90 if (g_mkdir_with_parents(directory,
91 S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
98 keydata = g_key_file_to_data(keyfile, &size, &error);
99 if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
100 DBG("Unable to save %s, error %s", pathname, error->message);
104 chmod(pathname, S_IRUSR | S_IWUSR);
109 void netconfig_start_timer_seconds(guint secs,
110 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
114 if (callback == NULL) {
115 ERR("callback function is NULL");
119 if ((timer_id != NULL && *timer_id != 0)) {
120 ERR("timer already is registered");
124 t_id = g_timeout_add_seconds(secs, callback, user_data);
127 ERR("Can't add timer");
131 if (timer_id != NULL)
135 void netconfig_start_timer(guint msecs,
136 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
140 INFO("Register timer with callback pointer (%p)", callback);
142 if (callback == NULL) {
143 ERR("callback function is NULL");
147 if ((timer_id != NULL && *timer_id != 0)) {
148 ERR("timer already is registered");
152 t_id = g_timeout_add(msecs, callback, user_data);
155 ERR("Can't add timer");
159 if (timer_id != NULL)
163 void netconfig_stop_timer(guint *timer_id)
165 if (timer_id == NULL) {
166 ERR("timer is NULL");
170 if (*timer_id != 0) {
171 g_source_remove(*timer_id);
176 static gboolean __netconfig_test_device_picker()
178 char *favorite_wifi_service = NULL;
180 favorite_wifi_service = wifi_get_favorite_service();
181 if (favorite_wifi_service != NULL) {
182 ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service);
183 g_free(favorite_wifi_service);
190 static void __netconfig_pop_device_picker(void)
192 #if defined TIZEN_WEARABLE
194 app_control_h control = NULL;
196 ret = app_control_create(&control);
197 if (APP_CONTROL_ERROR_NONE != ret) {
198 DBG("failed to create app control");
202 app_control_add_extra_data(control, "viewtype", "scanlist");
204 app_control_set_app_id(control, "org.tizen.wifi");
205 ret = app_control_send_launch_request(control, NULL, NULL);
206 if (APP_CONTROL_ERROR_NONE == ret)
207 DBG("Launch request sent successfully");
209 app_control_destroy(control);
212 int wifi_ug_state = 0;
214 vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
215 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
220 DBG("Launch Wi-Fi device picker");
221 syspopup_launch("wifi-qs", b);
227 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
229 if (__netconfig_test_device_picker() == TRUE)
230 __netconfig_pop_device_picker();
235 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id)
237 static guint netconfig_wifi_device_picker_service_timer = 0;
239 if (is_set_method != TRUE)
240 return netconfig_wifi_device_picker_service_timer;
242 if (netconfig_wifi_device_picker_service_timer != timer_id)
243 netconfig_wifi_device_picker_service_timer = timer_id;
245 return netconfig_wifi_device_picker_service_timer;
248 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
250 __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
253 static guint __netconfig_wifi_device_picker_get_timer_id(void)
255 return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
258 void netconfig_wifi_enable_device_picker_test(void)
260 netconfig_device_picker_test = TRUE;
263 void netconfig_wifi_device_picker_service_start(void)
265 const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
268 if (netconfig_device_picker_test == TRUE)
269 netconfig_device_picker_test = FALSE;
273 #if defined TIZEN_WEARABLE
274 if (aul_app_is_running("org.tizen.wifi") > 0) {
275 DBG("wifi app is running");
281 vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
282 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
286 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
287 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
289 __netconfig_wifi_device_picker_set_timer_id(timer_id);
292 void netconfig_wifi_device_picker_service_stop(void)
296 timer_id = __netconfig_wifi_device_picker_get_timer_id();
300 DBG("Clear device picker timer with timer_id %d", timer_id);
302 netconfig_stop_timer(&timer_id);
304 __netconfig_wifi_device_picker_set_timer_id(timer_id);
307 gboolean netconfig_is_wifi_direct_on(void)
309 #if defined TIZEN_P2P_ENABLE
310 int wifi_direct_state = 0;
312 vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
314 DBG("Wi-Fi direct mode %d", wifi_direct_state);
315 return (wifi_direct_state != 0) ? TRUE : FALSE;
321 gboolean netconfig_is_wifi_tethering_on(void)
323 #if defined TIZEN_TETHERING_ENABLE
324 int wifi_tethering_state = 0;
326 vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
328 DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
329 if (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
335 gboolean netconfig_interface_up(const char *ifname)
340 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
344 memset(&ifr, 0, sizeof(ifr));
345 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
347 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
352 ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
353 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
360 DBG("Successfully activated wireless interface");
364 gboolean netconfig_interface_down(const char *ifname)
369 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
373 memset(&ifr, 0, sizeof(ifr));
374 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
376 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
381 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
382 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
389 DBG("Successfully de-activated wireless interface");
393 int netconfig_execute_file(const char *file_path,
394 char *const args[], char *const envs[])
400 register unsigned int index = 0;
401 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
403 while (args[index] != NULL) {
404 DBG("%s", args[index]);
408 if (!(pid = fork())) {
409 DBG("pid(%d), ppid (%d)", getpid(), getppid());
410 DBG("Inside child, exec (%s) command", file_path);
413 if (execve(file_path, args, envs) == -1) {
414 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
415 DBG("Fail to execute command (%s)", error_buf);
418 } else if (pid > 0) {
419 if (waitpid(pid, &status, 0) == -1)
420 DBG("wait pid (%u) status (%d)", pid, status);
422 if (WIFEXITED(status)) {
423 rv = WEXITSTATUS(status);
424 DBG("exited, status=%d", rv);
425 } else if (WIFSIGNALED(status)) {
426 DBG("killed by signal %d", WTERMSIG(status));
427 } else if (WIFSTOPPED(status)) {
428 DBG("stopped by signal %d", WSTOPSIG(status));
429 } else if (WIFCONTINUED(status)) {
436 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
437 DBG("failed to fork(%s)", error_buf);
441 static void on_clat_handler()
446 clat_pid = waitpid(-1, &state, WNOHANG);
448 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
451 int netconfig_execute_clatd(const char *file_path, char *const args[])
456 register unsigned int index = 0;
457 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
459 struct sigaction act;
462 act.sa_handler = on_clat_handler;
463 sigemptyset(&act.sa_mask);
466 state = sigaction(SIGCHLD, &act, 0);
468 DBG("sigaction() : %d");
472 while (args[index] != NULL) {
473 DBG("%s", args[index]);
477 if (!(pid = fork())) {
478 DBG("pid(%d), ppid (%d)", getpid(), getppid());
479 DBG("Inside child, exec (%s) command", file_path);
482 if (execvp(file_path, args) == -1) {
483 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
484 ERR("Fail to execute command (%s)", error_buf);
487 } else if (pid > 0) {
488 ERR("Success to launch clatd");
492 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
493 DBG("failed to fork(%s)", error_buf);
497 int __netconfig_get_interface_index(const char *interface_name)
502 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
504 if (interface_name == NULL) {
505 DBG("Inteface name is NULL");
510 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
512 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
513 DBG("Failed to create socket : %s", error_buf);
517 memset(&ifr, 0, sizeof(ifr));
518 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
519 result = ioctl(sock, SIOCGIFINDEX, &ifr);
523 DBG("Failed to get ifr index: %s", error_buf);
527 return ifr.ifr_ifindex;
530 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
534 struct sockaddr_in addr_in;
536 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
538 memset(&ifr, 0, sizeof(ifr));
540 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
542 if (ifr.ifr_ifindex < 0)
545 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
547 memset(&rt, 0, sizeof(rt));
549 rt.rt_flags = RTF_UP | RTF_HOST;
550 memset(&addr_in, 0, sizeof(struct sockaddr_in));
551 addr_in.sin_family = address_family;
552 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
553 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
555 memset(&addr_in, 0, sizeof(struct sockaddr_in));
556 addr_in.sin_family = address_family;
557 addr_in.sin_addr.s_addr = INADDR_ANY;
558 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
560 memset(&addr_in, 0, sizeof(struct sockaddr_in));
561 addr_in.sin_family = AF_INET;
562 addr_in.sin_addr.s_addr = inet_addr(subnet);
563 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
565 rt.rt_dev = ifr.ifr_name;
568 sock = socket(PF_INET, SOCK_DGRAM, 0);
571 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
572 DBG("Failed to create socket : %s", error_buf);
576 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
577 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
578 DBG("Failed to set route address : %s", error_buf);
588 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
592 struct sockaddr_in addr_in;
594 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
596 memset(&ifr, 0, sizeof(ifr));
597 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
599 if (ifr.ifr_ifindex < 0)
602 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
604 memset(&rt, 0, sizeof(rt));
606 rt.rt_flags = RTF_UP;
607 memset(&addr_in, 0, sizeof(struct sockaddr_in));
608 addr_in.sin_family = address_family;
609 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
610 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
612 memset(&addr_in, 0, sizeof(struct sockaddr_in));
613 addr_in.sin_family = address_family;
614 addr_in.sin_addr.s_addr = inet_addr(subnet);
615 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
616 rt.rt_dev = ifr.ifr_name;
619 sock = socket(PF_INET, SOCK_DGRAM, 0);
622 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
623 DBG("Failed to create socket : %s", error_buf);
627 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
628 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
629 DBG("Failed to set route address : %s", error_buf);
639 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
644 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
646 memset(&rt, 0, sizeof(rt));
648 rt.rtmsg_dst_len = prefix_len;
650 rt.rtmsg_flags = RTF_UP | RTF_HOST;
653 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
654 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
655 DBG("inet_pton failed : %s", error_buf);
659 if (gateway != NULL) {
660 rt.rtmsg_flags |= RTF_GATEWAY;
661 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
662 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
663 DBG("inet_pton failed : %s", error_buf);
670 fd = socket(AF_INET6, SOCK_DGRAM, 0);
672 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
673 DBG("Failed to create socket : %s", error_buf);
677 rt.rtmsg_ifindex = 0;
681 memset(&ifr, 0, sizeof(ifr));
682 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
683 ioctl(fd, SIOCGIFINDEX, &ifr);
684 rt.rtmsg_ifindex = ifr.ifr_ifindex;
687 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
688 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
689 DBG("Failed to add route: %s", error_buf);
699 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
705 memset(&rt, 0, sizeof(rt));
707 rt.rtmsg_dst_len = prefix_len;
709 rt.rtmsg_flags = RTF_UP | RTF_HOST;
711 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
716 if (gateway != NULL) {
717 rt.rtmsg_flags |= RTF_GATEWAY;
718 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
726 fd = socket(AF_INET6, SOCK_DGRAM, 0);
730 rt.rtmsg_ifindex = 0;
734 memset(&ifr, 0, sizeof(ifr));
735 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
736 ioctl(fd, SIOCGIFINDEX, &ifr);
737 rt.rtmsg_ifindex = ifr.ifr_ifindex;
740 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
741 DBG("Failed to del route: %d\n", err);
751 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
753 #if defined TIZEN_P2P_ENABLE
755 DBG("Launch Wi-Fi direct daemon");
757 const char *path = "/usr/bin/wifi-direct-server.sh";
758 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
759 char *const envs[] = { NULL };
761 ret = netconfig_execute_file(path, args, envs);
763 ERR("Failed to launch Wi-Fi direct daemon");
764 netconfig_error_wifi_direct_failed(context);
767 wifi_complete_launch_direct(wifi, context);
770 wifi_complete_launch_direct(wifi, context);
775 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
779 static gboolean is_found_noti_exists = FALSE;
780 static gboolean is_portal_noti_exists = FALSE;
783 ERR("Invalid notification");
787 if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) {
788 if (is_found_noti_exists == FALSE)
791 is_found_noti_exists = FALSE;
792 } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) {
793 if (is_found_noti_exists == TRUE)
796 is_found_noti_exists = TRUE;
797 } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) {
798 if (is_portal_noti_exists == TRUE)
801 is_portal_noti_exists = TRUE;
802 } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) {
803 if (is_portal_noti_exists == FALSE)
806 is_portal_noti_exists = FALSE;
810 bundle_add(b, "_SYSPOPUP_TYPE_", noti);
813 DBG("ssid (%s)", ssid);
814 bundle_add(b, "_AP_NAME_", ssid);
817 ret = syspopup_launch("net.netpopup", b);
822 ERR("Unable to launch noti-popup. Err = %d", ret);
826 DBG("Successfully sent notification (%s)", noti);
830 int netconfig_send_message_to_net_popup(const char *title,
831 const char *content, const char *type, const char *ssid)
834 bundle *b = bundle_create();
836 bundle_add(b, "_SYSPOPUP_TITLE_", title);
837 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
838 bundle_add(b, "_SYSPOPUP_TYPE_", type);
839 bundle_add(b, "_AP_NAME_", ssid);
841 ret = syspopup_launch("net.netpopup", b);
848 void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val)
852 DBG("System event set [%s : %s : %s]", sys_evt, evt_key, evt_val);
855 bundle_add_str(b, evt_key, evt_val);
856 eventsystem_send_system_event(sys_evt, b);
860 #if defined TIZEN_WEARABLE
861 int wc_launch_syspopup(netconfig_wcpopup_type_e type)
869 ERR("Failed to create bundle");
874 case WC_POPUP_TYPE_SESSION_OVERLAPPED:
875 bundle_add(b, "event-type", "wps-session-overlapped");
877 case WC_POPUP_TYPE_WIFI_CONNECTED:
878 ssid = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
880 ERR("Failed to get connected ap ssid");
881 ssid = g_strdup(" ");
883 bundle_add(b, "event-type", "wifi-connected");
884 bundle_add(b, "ssid", ssid);
888 case WC_POPUP_TYPE_WIFI_RESTRICT:
889 bundle_add(b, "event-type", "wifi-restrict");
892 ERR("Popup is not supported[%d]", type);
897 ret = syspopup_launch("wc-syspopup", b);
899 ERR("Failed to launch syspopup");
906 int wc_launch_popup(netconfig_wcpopup_type_e type)
909 app_control_h app_control = NULL;
911 ret = app_control_create(&app_control);
912 if (ret != APP_CONTROL_ERROR_NONE) {
913 ERR("Failed to create appcontrol[%d]", ret);
918 case WC_POPUP_TYPE_CAPTIVE_PORTAL:
919 app_control_add_extra_data(app_control, WC_POPUP_EXTRA_DATA_KEY, "captive-portal");
922 ERR("Popup is not supported[%d]", type);
923 app_control_destroy(app_control);
927 app_control_set_app_id(app_control, "com.samsung.weconn-popup");
928 ret = app_control_send_launch_request(app_control, NULL, NULL);
929 if (ret != APP_CONTROL_ERROR_NONE) {
930 DBG("failed appcontrol launch request [%d]", ret);
931 app_control_destroy(app_control);
935 app_control_destroy(app_control);
941 void netconfig_set_vconf_int(const char * key, int value)
945 DBG("[%s: %d]", key, value);
947 ret = vconf_set_int(key, value);
949 ERR("Failed to set");
952 void netconfig_set_vconf_str(const char * key, const char * value)
956 DBG("[%s: %s]", key, value);
958 ret = vconf_set_str(key, value);
960 ERR("Failed to set");
963 char* netconfig_get_env(const char *key)
966 char buf[256], *entry = NULL, *value = NULL, *last;
972 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
976 while (fgets(buf, sizeof(buf), fp)) {
978 entry = strtok_r(entry, "=", &last);
980 if (strstr(entry, key)) {
981 entry = strtok_r(NULL, "\n", &last);
984 value = (char*)malloc(len+1);
985 g_strlcpy(value, entry, len+1);
988 value = (char*)malloc(sizeof(char));
989 g_strlcpy(value, "\n", sizeof(char));
1000 void netconfig_set_mac_address_from_file(void)
1003 char mac_str[MAC_ADDRESS_MAX_LEN];
1004 gchar *mac_lower_str = NULL;
1007 file = fopen(MAC_INFO_FILEPATH, "r");
1009 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1012 if (fgets(mac_str, sizeof(mac_str), file) == NULL ) {
1013 ERR("Fail to read mac address");
1018 mac_len = strlen(mac_str);
1020 ERR("mac.info is empty");
1025 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1026 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1028 g_free(mac_lower_str);