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"
46 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
47 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
48 #define MAC_INFO_FILEPATH tzplatform_mkpath(TZ_SYS_ETC, "/.mac.info")
49 #define MAC_ADDRESS_FILEPATH "/sys/class/net/wlan0/address"
50 #define MAC_ADDRESS_MAX_LEN 18
52 static gboolean netconfig_device_picker_test = FALSE;
53 static int mdnsd_ref_count = 0;
57 } dnssd_conn_destroy_data;
59 GKeyFile *netconfig_keyfile_load(const char *pathname)
61 GKeyFile *keyfile = NULL;
64 keyfile = g_key_file_new();
65 if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
66 DBG("Unable to open %s, error %s", pathname, error->message);
69 g_key_file_free(keyfile);
73 DBG("loaded keyfile %s", pathname);
77 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
81 gchar *keydata = NULL;
82 gchar *needle = NULL, *directory = NULL;
84 directory = g_strdup(pathname);
85 needle = g_strrstr(directory, "/");
90 if (directory == NULL || (*directory) == '\0') {
92 ERR("directory is NULL");
96 if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) {
97 if (g_mkdir_with_parents(directory,
98 S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
100 ERR("failed to make directory");
106 keydata = g_key_file_to_data(keyfile, &size, &error);
107 if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
108 ERR("Unable to save %s, error %s", pathname, error->message);
112 chmod(pathname, S_IRUSR | S_IWUSR);
113 DBG("Successfully saved keyfile %s", pathname);
118 void netconfig_start_timer_seconds(guint secs,
119 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
123 if (callback == NULL) {
124 ERR("callback function is NULL");
128 if ((timer_id != NULL && *timer_id != 0)) {
129 ERR("timer already is registered");
133 t_id = g_timeout_add_seconds(secs, callback, user_data);
136 ERR("Can't add timer");
140 if (timer_id != NULL)
144 void netconfig_start_timer(guint msecs,
145 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
149 INFO("Register timer with callback pointer (%p)", callback);
151 if (callback == NULL) {
152 ERR("callback function is NULL");
156 if ((timer_id != NULL && *timer_id != 0)) {
157 ERR("timer already is registered");
161 t_id = g_timeout_add(msecs, callback, user_data);
164 ERR("Can't add timer");
168 if (timer_id != NULL)
172 void netconfig_stop_timer(guint *timer_id)
174 if (timer_id == NULL) {
175 ERR("timer is NULL");
179 if (*timer_id != 0) {
180 g_source_remove(*timer_id);
185 static gboolean __netconfig_test_device_picker()
187 char *favorite_wifi_service = NULL;
189 favorite_wifi_service = wifi_get_favorite_service();
190 if (favorite_wifi_service != NULL) {
191 ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service);
192 g_free(favorite_wifi_service);
199 static void __netconfig_pop_device_picker(void)
201 #if defined TIZEN_WEARABLE
203 app_control_h control = NULL;
205 ret = app_control_create(&control);
206 if (APP_CONTROL_ERROR_NONE != ret) {
207 DBG("failed to create app control");
211 app_control_add_extra_data(control, "viewtype", "scanlist");
213 app_control_set_app_id(control, "org.tizen.wifi");
214 ret = app_control_send_launch_request(control, NULL, NULL);
215 if (APP_CONTROL_ERROR_NONE == ret)
216 DBG("Launch request sent successfully");
218 app_control_destroy(control);
221 int wifi_ug_state = 0;
223 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
224 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
229 DBG("Launch Wi-Fi device picker");
230 syspopup_launch("wifi-qs", b);
236 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
238 if (__netconfig_test_device_picker() == TRUE)
239 __netconfig_pop_device_picker();
244 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id)
246 static guint netconfig_wifi_device_picker_service_timer = 0;
248 if (is_set_method != TRUE)
249 return netconfig_wifi_device_picker_service_timer;
251 if (netconfig_wifi_device_picker_service_timer != timer_id)
252 netconfig_wifi_device_picker_service_timer = timer_id;
254 return netconfig_wifi_device_picker_service_timer;
257 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
259 __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
262 static guint __netconfig_wifi_device_picker_get_timer_id(void)
264 return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
267 void netconfig_wifi_enable_device_picker_test(void)
269 netconfig_device_picker_test = TRUE;
272 void netconfig_wifi_device_picker_service_start(void)
274 const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
277 if (netconfig_device_picker_test == TRUE)
278 netconfig_device_picker_test = FALSE;
284 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
285 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
288 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
289 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
291 __netconfig_wifi_device_picker_set_timer_id(timer_id);
294 void netconfig_wifi_device_picker_service_stop(void)
298 timer_id = __netconfig_wifi_device_picker_get_timer_id();
302 DBG("Clear device picker timer with timer_id %d", timer_id);
304 netconfig_stop_timer(&timer_id);
306 __netconfig_wifi_device_picker_set_timer_id(timer_id);
309 gboolean netconfig_is_wifi_direct_on(void)
311 #if defined TIZEN_P2P_ENABLE
312 int wifi_direct_state = 0;
314 netconfig_vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
316 DBG("Wi-Fi direct mode %d", wifi_direct_state);
317 return (wifi_direct_state != 0) ? TRUE : FALSE;
323 gboolean netconfig_is_wifi_tethering_on(void)
325 #if defined TIZEN_TETHERING_ENABLE
326 int wifi_tethering_state = 0;
328 netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
329 DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
330 if ((wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
331 || (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP)) {
332 DBG("Mobile AP is on");
336 DBG("Mobile AP is off");
340 gboolean netconfig_interface_up(const char *ifname)
345 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
349 memset(&ifr, 0, sizeof(ifr));
350 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
352 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
357 ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
358 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
365 DBG("Successfully activated wireless interface");
369 gboolean netconfig_interface_down(const char *ifname)
374 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
378 memset(&ifr, 0, sizeof(ifr));
379 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
381 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
386 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
387 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
394 DBG("Successfully de-activated wireless interface");
398 int netconfig_execute_file(const char *file_path,
399 char *const args[], char *const envs[])
405 register unsigned int index = 0;
406 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
408 while (args[index] != NULL) {
409 DBG("%s", args[index]);
413 if (!(pid = fork())) {
414 DBG("pid(%d), ppid (%d)", getpid(), getppid());
415 DBG("Inside child, exec (%s) command", file_path);
418 if (execve(file_path, args, envs) == -1) {
419 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
420 DBG("Fail to execute command (%s)", error_buf);
423 } else if (pid > 0) {
424 if (waitpid(pid, &status, 0) == -1)
425 DBG("wait pid (%u) status (%d)", pid, status);
427 if (WIFEXITED(status)) {
428 rv = WEXITSTATUS(status);
429 DBG("exited, status=%d", rv);
430 } else if (WIFSIGNALED(status)) {
431 DBG("killed by signal %d", WTERMSIG(status));
432 } else if (WIFSTOPPED(status)) {
433 DBG("stopped by signal %d", WSTOPSIG(status));
434 } else if (WIFCONTINUED(status)) {
441 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
442 DBG("failed to fork(%s)", error_buf);
446 static void on_clat_handler()
451 clat_pid = waitpid(-1, &state, WNOHANG);
453 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
456 int netconfig_execute_clatd(const char *file_path, char *const args[])
461 register unsigned int index = 0;
462 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
464 struct sigaction act;
467 act.sa_handler = on_clat_handler;
468 sigemptyset(&act.sa_mask);
471 state = sigaction(SIGCHLD, &act, 0);
473 DBG("sigaction() : %d");
477 while (args[index] != NULL) {
478 DBG("%s", args[index]);
482 if (!(pid = fork())) {
483 DBG("pid(%d), ppid (%d)", getpid(), getppid());
484 DBG("Inside child, exec (%s) command", file_path);
487 if (execvp(file_path, args) == -1) {
488 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
489 ERR("Fail to execute command (%s)", error_buf);
492 } else if (pid > 0) {
493 ERR("Success to launch clatd");
497 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
498 DBG("failed to fork(%s)", error_buf);
502 int __netconfig_get_interface_index(const char *interface_name)
507 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
509 if (interface_name == NULL) {
510 DBG("Inteface name is NULL");
515 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
517 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
518 DBG("Failed to create socket : %s", error_buf);
522 memset(&ifr, 0, sizeof(ifr));
523 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
524 result = ioctl(sock, SIOCGIFINDEX, &ifr);
528 DBG("Failed to get ifr index: %s", error_buf);
532 return ifr.ifr_ifindex;
535 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
539 struct sockaddr_in addr_in;
541 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
543 memset(&ifr, 0, sizeof(ifr));
545 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
547 if (ifr.ifr_ifindex < 0)
550 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
552 memset(&rt, 0, sizeof(rt));
554 rt.rt_flags = RTF_UP | RTF_HOST;
555 memset(&addr_in, 0, sizeof(struct sockaddr_in));
556 addr_in.sin_family = address_family;
557 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
558 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
560 memset(&addr_in, 0, sizeof(struct sockaddr_in));
561 addr_in.sin_family = address_family;
562 addr_in.sin_addr.s_addr = INADDR_ANY;
563 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
565 memset(&addr_in, 0, sizeof(struct sockaddr_in));
566 addr_in.sin_family = AF_INET;
567 addr_in.sin_addr.s_addr = inet_addr(subnet);
568 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
570 rt.rt_dev = ifr.ifr_name;
573 sock = socket(PF_INET, SOCK_DGRAM, 0);
576 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
577 DBG("Failed to create socket : %s", error_buf);
581 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
582 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
583 DBG("Failed to set route address : %s", error_buf);
593 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
597 struct sockaddr_in addr_in;
599 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
601 memset(&ifr, 0, sizeof(ifr));
602 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
604 if (ifr.ifr_ifindex < 0)
607 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
609 memset(&rt, 0, sizeof(rt));
611 rt.rt_flags = RTF_UP;
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(ip_addr);
615 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
617 memset(&addr_in, 0, sizeof(struct sockaddr_in));
618 addr_in.sin_family = address_family;
619 addr_in.sin_addr.s_addr = inet_addr(subnet);
620 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
621 rt.rt_dev = ifr.ifr_name;
624 sock = socket(PF_INET, SOCK_DGRAM, 0);
627 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
628 DBG("Failed to create socket : %s", error_buf);
632 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
633 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
634 DBG("Failed to set route address : %s", error_buf);
644 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
649 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
651 memset(&rt, 0, sizeof(rt));
653 rt.rtmsg_dst_len = prefix_len;
655 rt.rtmsg_flags = RTF_UP | RTF_HOST;
658 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
659 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
660 DBG("inet_pton failed : %s", error_buf);
664 if (gateway != NULL) {
665 rt.rtmsg_flags |= RTF_GATEWAY;
666 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
667 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
668 DBG("inet_pton failed : %s", error_buf);
675 fd = socket(AF_INET6, SOCK_DGRAM, 0);
677 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
678 DBG("Failed to create socket : %s", error_buf);
682 rt.rtmsg_ifindex = 0;
686 memset(&ifr, 0, sizeof(ifr));
687 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
688 ioctl(fd, SIOCGIFINDEX, &ifr);
689 rt.rtmsg_ifindex = ifr.ifr_ifindex;
692 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
693 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
694 DBG("Failed to add route: %s", error_buf);
704 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
710 memset(&rt, 0, sizeof(rt));
712 rt.rtmsg_dst_len = prefix_len;
714 rt.rtmsg_flags = RTF_UP | RTF_HOST;
716 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
721 if (gateway != NULL) {
722 rt.rtmsg_flags |= RTF_GATEWAY;
723 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
731 fd = socket(AF_INET6, SOCK_DGRAM, 0);
735 rt.rtmsg_ifindex = 0;
739 memset(&ifr, 0, sizeof(ifr));
740 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
741 ioctl(fd, SIOCGIFINDEX, &ifr);
742 rt.rtmsg_ifindex = ifr.ifr_ifindex;
745 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
746 DBG("Failed to del route: %d\n", err);
756 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
758 #if defined TIZEN_P2P_ENABLE
760 DBG("Launch Wi-Fi direct daemon");
762 const char *path = "/usr/bin/wifi-direct-server.sh";
763 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
764 char *const envs[] = { NULL };
766 ret = netconfig_execute_file(path, args, envs);
768 ERR("Failed to launch Wi-Fi direct daemon");
769 netconfig_error_wifi_direct_failed(context);
773 wifi_complete_launch_direct(wifi, context);
776 wifi_complete_launch_direct(wifi, context);
781 int execute_mdnsd_script(char* op)
783 const char *path = "/usr/bin/mdnsresponder-server.sh";
784 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
785 char *const envs[] = { NULL };
787 return netconfig_execute_file(path, args, envs);
790 static void __dnssd_conn_destroyed_cb(GDBusConnection *conn,
791 const gchar *Name, const gchar *path, const gchar *interface,
792 const gchar *sig, GVariant *param, gpointer user_data)
797 dnssd_conn_destroy_data *data = user_data;
798 GDBusConnection *connection = NULL;
799 connection = netdbus_get_connection();
804 g_variant_get(param, "(sss)", &name, &old, &new);
806 if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
807 DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name,
810 g_dbus_connection_signal_unsubscribe(connection, data->conn_id);
811 if (mdnsd_ref_count == 0) {
812 if (execute_mdnsd_script("stop") < 0)
813 ERR("Failed to stop mdnsresponder daemon");
819 g_free(data->conn_name);
824 static void register_dnssd_conn_destroy_signal(gchar *name)
826 dnssd_conn_destroy_data *data;
827 GDBusConnection *connection = NULL;
828 connection = netdbus_get_connection();
830 if (connection == NULL) {
831 ERR("Failed to get GDbus Connection");
835 data = g_try_malloc0(sizeof(dnssd_conn_destroy_data));
836 data->conn_name = g_strdup(name);
838 data->conn_id = g_dbus_connection_signal_subscribe(connection,
839 DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
840 "NameOwnerChanged", NULL, name,
841 G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb,
846 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context,
849 DBG("Launch mdnsresponder daemon");
851 if (execute_mdnsd_script("start") < 0) {
852 ERR("Failed to launch mdnsresponder daemon");
853 netconfig_error_invalid_parameter(context);
858 register_dnssd_conn_destroy_signal(name);
859 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
861 network_complete_launch_mdns(object, context);
865 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
869 static gboolean is_found_noti_exists = FALSE;
870 static gboolean is_portal_noti_exists = FALSE;
873 ERR("Invalid notification");
877 if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) {
878 if (is_found_noti_exists == FALSE)
881 is_found_noti_exists = FALSE;
882 } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) {
883 if (is_found_noti_exists == TRUE)
886 is_found_noti_exists = TRUE;
887 } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) {
888 if (is_portal_noti_exists == TRUE)
891 is_portal_noti_exists = TRUE;
892 } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) {
893 if (is_portal_noti_exists == FALSE)
896 is_portal_noti_exists = FALSE;
900 bundle_add(b, "_SYSPOPUP_TYPE_", noti);
903 DBG("ssid (%s)", ssid);
904 bundle_add(b, "_AP_NAME_", ssid);
907 ret = syspopup_launch("net-popup", b);
912 ERR("Unable to launch noti-popup. Err = %d", ret);
916 DBG("Successfully sent notification (%s)", noti);
920 int netconfig_send_message_to_net_popup(const char *title,
921 const char *content, const char *type, const char *ssid)
924 bundle *b = bundle_create();
926 bundle_add(b, "_SYSPOPUP_TITLE_", title);
927 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
928 bundle_add(b, "_SYSPOPUP_TYPE_", type);
929 bundle_add(b, "_AP_NAME_", ssid);
931 ret = syspopup_launch("net-popup", b);
938 int netconfig_send_restriction_to_net_popup(const char *title,
939 const char *type, const char *restriction)
942 bundle *b = bundle_create();
944 bundle_add(b, "_SYSPOPUP_TITLE_", title);
945 bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
946 bundle_add(b, "_SYSPOPUP_TYPE_", type);
947 bundle_add(b, "_RESTRICTED_TYPE_", restriction);
949 ret = syspopup_launch("net-popup", b);
956 void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val)
960 DBG("System event set [%s : %s : %s]", sys_evt, evt_key, evt_val);
963 bundle_add_str(b, evt_key, evt_val);
964 eventsystem_send_system_event(sys_evt, b);
968 void netconfig_set_vconf_int(const char * key, int value)
972 DBG("[%s: %d]", key, value);
974 ret = vconf_set_int(key, value);
976 ERR("Failed to set");
979 void netconfig_set_vconf_str(const char * key, const char * value)
983 DBG("[%s: %s]", key, value);
985 ret = vconf_set_str(key, value);
987 ERR("Failed to set");
990 int netconfig_vconf_get_int(const char * key, int *value)
994 ret = vconf_get_int(key, value);
995 if (ret != VCONF_OK) {
996 ERR("Failed to get vconfkey [%s] value", key);
1003 int netconfig_vconf_get_bool(const char * key, int *value)
1007 ret = vconf_get_bool(key, value);
1008 if (ret != VCONF_OK) {
1009 ERR("Failed to get vconfkey [%s] value", key);
1016 char* netconfig_get_env(const char *key)
1019 char buf[256], *entry = NULL, *value = NULL, *last;
1025 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
1029 while (fgets(buf, sizeof(buf), fp)) {
1031 entry = strtok_r(entry, "=", &last);
1033 if (strstr(entry, key)) {
1034 entry = strtok_r(NULL, "\n", &last);
1036 len = strlen(entry);
1037 value = (char*)malloc(len+1);
1038 g_strlcpy(value, entry, len+1);
1040 value = (char*)malloc(sizeof(char));
1041 g_strlcpy(value, "\n", sizeof(char));
1052 void netconfig_set_mac_address_from_file(void)
1055 char mac_str[MAC_ADDRESS_MAX_LEN];
1056 gchar *mac_lower_str = NULL;
1059 file = fopen(MAC_INFO_FILEPATH, "r");
1061 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1062 file = fopen(MAC_ADDRESS_FILEPATH, "r");
1064 ERR("Fail to open %s", MAC_ADDRESS_FILEPATH);
1068 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
1069 ERR("Fail to read mac address");
1074 mac_len = strlen(mac_str);
1076 ERR("mac.info is empty");
1081 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1082 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1084 g_free(mac_lower_str);