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_ETC, "/.mac.info")
50 #define MAC_ADDRESS_MAX_LEN 18
52 static gboolean netconfig_device_picker_test = FALSE;
53 static int mdnsd_ref_count = 0;
55 GKeyFile *netconfig_keyfile_load(const char *pathname)
57 GKeyFile *keyfile = NULL;
60 keyfile = g_key_file_new();
61 if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
62 DBG("Unable to open %s, error %s", pathname, error->message);
65 g_key_file_free(keyfile);
72 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
76 gchar *keydata = NULL;
77 gchar *needle = NULL, *directory = NULL;
79 directory = g_strdup(pathname);
80 needle = g_strrstr(directory, "/");
85 if (directory == NULL || (*directory) == '\0') {
90 if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) {
91 if (g_mkdir_with_parents(directory,
92 S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
99 keydata = g_key_file_to_data(keyfile, &size, &error);
100 if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
101 DBG("Unable to save %s, error %s", pathname, error->message);
105 chmod(pathname, S_IRUSR | S_IWUSR);
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;
274 #if defined TIZEN_WEARABLE
275 if (aul_app_is_running("org.tizen.wifi") > 0) {
276 DBG("wifi app is running");
282 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
283 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
287 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
288 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
290 __netconfig_wifi_device_picker_set_timer_id(timer_id);
293 void netconfig_wifi_device_picker_service_stop(void)
297 timer_id = __netconfig_wifi_device_picker_get_timer_id();
301 DBG("Clear device picker timer with timer_id %d", timer_id);
303 netconfig_stop_timer(&timer_id);
305 __netconfig_wifi_device_picker_set_timer_id(timer_id);
308 gboolean netconfig_is_wifi_direct_on(void)
310 #if defined TIZEN_P2P_ENABLE
311 int wifi_direct_state = 0;
313 netconfig_vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
315 DBG("Wi-Fi direct mode %d", wifi_direct_state);
316 return (wifi_direct_state != 0) ? TRUE : FALSE;
322 gboolean netconfig_is_wifi_tethering_on(void)
324 #if defined TIZEN_TETHERING_ENABLE
325 int wifi_tethering_state = 0;
327 netconfig_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);
768 wifi_complete_launch_direct(wifi, context);
771 wifi_complete_launch_direct(wifi, context);
776 int execute_mdnsd_script(char* op) {
777 const char *path = "/usr/bin/mdnsresponder-server.sh";
778 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
779 char *const envs[] = { NULL };
781 return netconfig_execute_file(path, args, envs);
784 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context)
786 DBG("Launch mdnsresponder daemon");
788 if (mdnsd_ref_count != 0) {
789 ERR("Invalid access");
790 netconfig_error_invalid_parameter(context);
794 if (execute_mdnsd_script("start") < 0) {
795 ERR("Failed to launch mdnsresponder daemon");
796 netconfig_error_invalid_parameter(context);
800 network_complete_launch_mdns(object, context);
804 gboolean handle_ref_mdns(Network *object, GDBusMethodInvocation *context)
808 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
809 network_complete_ref_mdns(object, context);
813 gboolean handle_unref_mdns(Network *object, GDBusMethodInvocation *context)
815 DBG("Unef mdnsresponder daemon");
817 if (mdnsd_ref_count <= 0) {
818 ERR("Invalid access");
819 netconfig_error_invalid_parameter(context);
825 DBG("Unref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
826 if (mdnsd_ref_count == 0) {
827 if (execute_mdnsd_script("stop") < 0) {
828 ERR("Failed to stop mdnsresponder daemon");
829 netconfig_error_invalid_parameter(context);
834 network_complete_unref_mdns(object, context);
838 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
842 static gboolean is_found_noti_exists = FALSE;
843 static gboolean is_portal_noti_exists = FALSE;
846 ERR("Invalid notification");
850 if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) {
851 if (is_found_noti_exists == FALSE)
854 is_found_noti_exists = FALSE;
855 } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) {
856 if (is_found_noti_exists == TRUE)
859 is_found_noti_exists = TRUE;
860 } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) {
861 if (is_portal_noti_exists == TRUE)
864 is_portal_noti_exists = TRUE;
865 } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) {
866 if (is_portal_noti_exists == FALSE)
869 is_portal_noti_exists = FALSE;
873 bundle_add(b, "_SYSPOPUP_TYPE_", noti);
876 DBG("ssid (%s)", ssid);
877 bundle_add(b, "_AP_NAME_", ssid);
880 ret = syspopup_launch("net-popup", b);
885 ERR("Unable to launch noti-popup. Err = %d", ret);
889 DBG("Successfully sent notification (%s)", noti);
893 int netconfig_send_message_to_net_popup(const char *title,
894 const char *content, const char *type, const char *ssid)
897 bundle *b = bundle_create();
899 bundle_add(b, "_SYSPOPUP_TITLE_", title);
900 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
901 bundle_add(b, "_SYSPOPUP_TYPE_", type);
902 bundle_add(b, "_AP_NAME_", ssid);
904 ret = syspopup_launch("net-popup", b);
911 int netconfig_send_restriction_to_net_popup(const char *title,
912 const char *type, const char *restriction)
915 bundle *b = bundle_create();
917 bundle_add(b, "_SYSPOPUP_TITLE_", title);
918 bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
919 bundle_add(b, "_SYSPOPUP_TYPE_", type);
920 bundle_add(b, "_RESTRICTED_TYPE_", restriction);
922 ret = syspopup_launch("net-popup", b);
929 void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val)
933 DBG("System event set [%s : %s : %s]", sys_evt, evt_key, evt_val);
936 bundle_add_str(b, evt_key, evt_val);
937 eventsystem_send_system_event(sys_evt, b);
941 #if defined TIZEN_WEARABLE
942 int wc_launch_syspopup(netconfig_wcpopup_type_e type)
950 ERR("Failed to create bundle");
955 case WC_POPUP_TYPE_SESSION_OVERLAPPED:
956 bundle_add(b, "event-type", "wps-session-overlapped");
958 case WC_POPUP_TYPE_WIFI_CONNECTED:
959 ssid = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
961 ERR("Failed to get connected ap ssid");
962 ssid = g_strdup(" ");
964 bundle_add(b, "event-type", "wifi-connected");
965 bundle_add(b, "ssid", ssid);
969 case WC_POPUP_TYPE_WIFI_RESTRICT:
970 bundle_add(b, "event-type", "wifi-restrict");
973 ERR("Popup is not supported[%d]", type);
978 ret = syspopup_launch("wc-syspopup", b);
980 ERR("Failed to launch syspopup");
986 int wc_launch_popup(netconfig_wcpopup_type_e type)
989 app_control_h app_control = NULL;
991 ret = app_control_create(&app_control);
992 if (ret != APP_CONTROL_ERROR_NONE) {
993 ERR("Failed to create appcontrol[%d]", ret);
998 case WC_POPUP_TYPE_CAPTIVE_PORTAL:
999 app_control_add_extra_data(app_control, WC_POPUP_EXTRA_DATA_KEY, "captive-portal");
1002 ERR("Popup is not supported[%d]", type);
1003 app_control_destroy(app_control);
1007 app_control_set_app_id(app_control, "com.samsung.weconn-popup");
1008 ret = app_control_send_launch_request(app_control, NULL, NULL);
1009 if (ret != APP_CONTROL_ERROR_NONE) {
1010 DBG("failed appcontrol launch request [%d]", ret);
1011 app_control_destroy(app_control);
1015 app_control_destroy(app_control);
1021 void netconfig_set_vconf_int(const char * key, int value)
1025 DBG("[%s: %d]", key, value);
1027 ret = vconf_set_int(key, value);
1028 if (ret != VCONF_OK)
1029 ERR("Failed to set");
1032 void netconfig_set_vconf_str(const char * key, const char * value)
1036 DBG("[%s: %s]", key, value);
1038 ret = vconf_set_str(key, value);
1039 if (ret != VCONF_OK)
1040 ERR("Failed to set");
1043 int netconfig_vconf_get_int(const char * key, int *value)
1047 ret = vconf_get_int(key, value);
1048 if (ret != VCONF_OK) {
1049 ERR("Failed to get vconfkey [%s] value", key);
1056 int netconfig_vconf_get_bool(const char * key, int *value)
1060 ret = vconf_get_bool(key, value);
1061 if (ret != VCONF_OK) {
1062 ERR("Failed to get vconfkey [%s] value", key);
1069 char* netconfig_get_env(const char *key)
1072 char buf[256], *entry = NULL, *value = NULL, *last;
1078 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
1082 while (fgets(buf, sizeof(buf), fp)) {
1084 entry = strtok_r(entry, "=", &last);
1086 if (strstr(entry, key)) {
1087 entry = strtok_r(NULL, "\n", &last);
1089 len = strlen(entry);
1090 value = (char*)malloc(len+1);
1091 g_strlcpy(value, entry, len+1);
1093 value = (char*)malloc(sizeof(char));
1094 g_strlcpy(value, "\n", sizeof(char));
1105 void netconfig_set_mac_address_from_file(void)
1108 char mac_str[MAC_ADDRESS_MAX_LEN];
1109 gchar *mac_lower_str = NULL;
1112 file = fopen(MAC_INFO_FILEPATH, "r");
1114 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1117 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
1118 ERR("Fail to read mac address");
1123 mac_len = strlen(mac_str);
1125 ERR("mac.info is empty");
1130 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1131 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1133 g_free(mac_lower_str);