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 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 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 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 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)
336 gboolean netconfig_interface_up(const char *ifname)
341 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
345 memset(&ifr, 0, sizeof(ifr));
346 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
348 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
353 ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
354 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
361 DBG("Successfully activated wireless interface");
365 gboolean netconfig_interface_down(const char *ifname)
370 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
374 memset(&ifr, 0, sizeof(ifr));
375 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
377 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
382 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
383 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
390 DBG("Successfully de-activated wireless interface");
394 int netconfig_execute_file(const char *file_path,
395 char *const args[], char *const envs[])
401 register unsigned int index = 0;
402 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
404 while (args[index] != NULL) {
405 DBG("%s", args[index]);
409 if (!(pid = fork())) {
410 DBG("pid(%d), ppid (%d)", getpid(), getppid());
411 DBG("Inside child, exec (%s) command", file_path);
414 if (execve(file_path, args, envs) == -1) {
415 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
416 DBG("Fail to execute command (%s)", error_buf);
419 } else if (pid > 0) {
420 if (waitpid(pid, &status, 0) == -1)
421 DBG("wait pid (%u) status (%d)", pid, status);
423 if (WIFEXITED(status)) {
424 rv = WEXITSTATUS(status);
425 DBG("exited, status=%d", rv);
426 } else if (WIFSIGNALED(status)) {
427 DBG("killed by signal %d", WTERMSIG(status));
428 } else if (WIFSTOPPED(status)) {
429 DBG("stopped by signal %d", WSTOPSIG(status));
430 } else if (WIFCONTINUED(status)) {
437 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
438 DBG("failed to fork(%s)", error_buf);
442 static void on_clat_handler()
447 clat_pid = waitpid(-1, &state, WNOHANG);
449 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
452 int netconfig_execute_clatd(const char *file_path, char *const args[])
457 register unsigned int index = 0;
458 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
460 struct sigaction act;
463 act.sa_handler = on_clat_handler;
464 sigemptyset(&act.sa_mask);
467 state = sigaction(SIGCHLD, &act, 0);
469 DBG("sigaction() : %d");
473 while (args[index] != NULL) {
474 DBG("%s", args[index]);
478 if (!(pid = fork())) {
479 DBG("pid(%d), ppid (%d)", getpid(), getppid());
480 DBG("Inside child, exec (%s) command", file_path);
483 if (execvp(file_path, args) == -1) {
484 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
485 ERR("Fail to execute command (%s)", error_buf);
488 } else if (pid > 0) {
489 ERR("Success to launch clatd");
493 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
494 DBG("failed to fork(%s)", error_buf);
498 int __netconfig_get_interface_index(const char *interface_name)
503 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
505 if (interface_name == NULL) {
506 DBG("Inteface name is NULL");
511 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
513 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
514 DBG("Failed to create socket : %s", error_buf);
518 memset(&ifr, 0, sizeof(ifr));
519 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
520 result = ioctl(sock, SIOCGIFINDEX, &ifr);
524 DBG("Failed to get ifr index: %s", error_buf);
528 return ifr.ifr_ifindex;
531 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
535 struct sockaddr_in addr_in;
537 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
539 memset(&ifr, 0, sizeof(ifr));
541 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
543 if (ifr.ifr_ifindex < 0)
546 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
548 memset(&rt, 0, sizeof(rt));
550 rt.rt_flags = RTF_UP | RTF_HOST;
551 memset(&addr_in, 0, sizeof(struct sockaddr_in));
552 addr_in.sin_family = address_family;
553 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
554 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
556 memset(&addr_in, 0, sizeof(struct sockaddr_in));
557 addr_in.sin_family = address_family;
558 addr_in.sin_addr.s_addr = INADDR_ANY;
559 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
561 memset(&addr_in, 0, sizeof(struct sockaddr_in));
562 addr_in.sin_family = AF_INET;
563 addr_in.sin_addr.s_addr = inet_addr(subnet);
564 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
566 rt.rt_dev = ifr.ifr_name;
569 sock = socket(PF_INET, SOCK_DGRAM, 0);
572 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
573 DBG("Failed to create socket : %s", error_buf);
577 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
578 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
579 DBG("Failed to set route address : %s", error_buf);
589 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
593 struct sockaddr_in addr_in;
595 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
597 memset(&ifr, 0, sizeof(ifr));
598 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
600 if (ifr.ifr_ifindex < 0)
603 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
605 memset(&rt, 0, sizeof(rt));
607 rt.rt_flags = RTF_UP;
608 memset(&addr_in, 0, sizeof(struct sockaddr_in));
609 addr_in.sin_family = address_family;
610 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
611 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
613 memset(&addr_in, 0, sizeof(struct sockaddr_in));
614 addr_in.sin_family = address_family;
615 addr_in.sin_addr.s_addr = inet_addr(subnet);
616 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
617 rt.rt_dev = ifr.ifr_name;
620 sock = socket(PF_INET, SOCK_DGRAM, 0);
623 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
624 DBG("Failed to create socket : %s", error_buf);
628 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
629 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
630 DBG("Failed to set route address : %s", error_buf);
640 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
645 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
647 memset(&rt, 0, sizeof(rt));
649 rt.rtmsg_dst_len = prefix_len;
651 rt.rtmsg_flags = RTF_UP | RTF_HOST;
654 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
655 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
656 DBG("inet_pton failed : %s", error_buf);
660 if (gateway != NULL) {
661 rt.rtmsg_flags |= RTF_GATEWAY;
662 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
663 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
664 DBG("inet_pton failed : %s", error_buf);
671 fd = socket(AF_INET6, SOCK_DGRAM, 0);
673 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
674 DBG("Failed to create socket : %s", error_buf);
678 rt.rtmsg_ifindex = 0;
682 memset(&ifr, 0, sizeof(ifr));
683 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
684 ioctl(fd, SIOCGIFINDEX, &ifr);
685 rt.rtmsg_ifindex = ifr.ifr_ifindex;
688 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
689 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
690 DBG("Failed to add route: %s", error_buf);
700 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
706 memset(&rt, 0, sizeof(rt));
708 rt.rtmsg_dst_len = prefix_len;
710 rt.rtmsg_flags = RTF_UP | RTF_HOST;
712 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
717 if (gateway != NULL) {
718 rt.rtmsg_flags |= RTF_GATEWAY;
719 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
727 fd = socket(AF_INET6, SOCK_DGRAM, 0);
731 rt.rtmsg_ifindex = 0;
735 memset(&ifr, 0, sizeof(ifr));
736 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
737 ioctl(fd, SIOCGIFINDEX, &ifr);
738 rt.rtmsg_ifindex = ifr.ifr_ifindex;
741 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
742 DBG("Failed to del route: %d\n", err);
752 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
754 #if defined TIZEN_P2P_ENABLE
756 DBG("Launch Wi-Fi direct daemon");
758 const char *path = "/usr/bin/wifi-direct-server.sh";
759 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
760 char *const envs[] = { NULL };
762 ret = netconfig_execute_file(path, args, envs);
764 ERR("Failed to launch Wi-Fi direct daemon");
765 netconfig_error_wifi_direct_failed(context);
769 wifi_complete_launch_direct(wifi, context);
772 wifi_complete_launch_direct(wifi, context);
777 int execute_mdnsd_script(char* op) {
778 const char *path = "/usr/bin/mdnsresponder-server.sh";
779 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
780 char *const envs[] = { NULL };
782 return netconfig_execute_file(path, args, envs);
785 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context)
787 DBG("Launch mdnsresponder daemon");
789 if (mdnsd_ref_count != 0) {
790 ERR("Invalid access");
791 netconfig_error_invalid_parameter(context);
795 if (execute_mdnsd_script("start") < 0) {
796 ERR("Failed to launch mdnsresponder daemon");
797 netconfig_error_invalid_parameter(context);
801 network_complete_launch_mdns(object, context);
805 gboolean handle_ref_mdns(Network *object, GDBusMethodInvocation *context)
809 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
810 network_complete_ref_mdns(object, context);
814 gboolean handle_unref_mdns(Network *object, GDBusMethodInvocation *context)
816 DBG("Unef mdnsresponder daemon");
818 if (mdnsd_ref_count <= 0) {
819 ERR("Invalid access");
820 netconfig_error_invalid_parameter(context);
826 DBG("Unref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
827 if (mdnsd_ref_count == 0) {
828 if (execute_mdnsd_script("stop") < 0) {
829 ERR("Failed to stop mdnsresponder daemon");
830 netconfig_error_invalid_parameter(context);
835 network_complete_unref_mdns(object, context);
839 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
843 static gboolean is_found_noti_exists = FALSE;
844 static gboolean is_portal_noti_exists = FALSE;
847 ERR("Invalid notification");
851 if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) {
852 if (is_found_noti_exists == FALSE)
855 is_found_noti_exists = FALSE;
856 } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) {
857 if (is_found_noti_exists == TRUE)
860 is_found_noti_exists = TRUE;
861 } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) {
862 if (is_portal_noti_exists == TRUE)
865 is_portal_noti_exists = TRUE;
866 } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) {
867 if (is_portal_noti_exists == FALSE)
870 is_portal_noti_exists = FALSE;
874 bundle_add(b, "_SYSPOPUP_TYPE_", noti);
877 DBG("ssid (%s)", ssid);
878 bundle_add(b, "_AP_NAME_", ssid);
881 ret = syspopup_launch("net-popup", b);
886 ERR("Unable to launch noti-popup. Err = %d", ret);
890 DBG("Successfully sent notification (%s)", noti);
894 int netconfig_send_message_to_net_popup(const char *title,
895 const char *content, const char *type, const char *ssid)
898 bundle *b = bundle_create();
900 bundle_add(b, "_SYSPOPUP_TITLE_", title);
901 bundle_add(b, "_SYSPOPUP_CONTENT_", content);
902 bundle_add(b, "_SYSPOPUP_TYPE_", type);
903 bundle_add(b, "_AP_NAME_", ssid);
905 ret = syspopup_launch("net-popup", b);
912 int netconfig_send_restriction_to_net_popup(const char *title,
913 const char *type, const char *restriction)
916 bundle *b = bundle_create();
918 bundle_add(b, "_SYSPOPUP_TITLE_", title);
919 bundle_add(b, "_SYSPOPUP_CONTENT_", "security restriction");
920 bundle_add(b, "_SYSPOPUP_TYPE_", type);
921 bundle_add(b, "_RESTRICTED_TYPE_", restriction);
923 ret = syspopup_launch("net-popup", b);
930 void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val)
934 DBG("System event set [%s : %s : %s]", sys_evt, evt_key, evt_val);
937 bundle_add_str(b, evt_key, evt_val);
938 eventsystem_send_system_event(sys_evt, b);
942 #if defined TIZEN_WEARABLE
943 int wc_launch_syspopup(netconfig_wcpopup_type_e type)
951 ERR("Failed to create bundle");
956 case WC_POPUP_TYPE_SESSION_OVERLAPPED:
957 bundle_add(b, "event-type", "wps-session-overlapped");
959 case WC_POPUP_TYPE_WIFI_CONNECTED:
960 ssid = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
962 ERR("Failed to get connected ap ssid");
963 ssid = g_strdup(" ");
965 bundle_add(b, "event-type", "wifi-connected");
966 bundle_add(b, "ssid", ssid);
970 case WC_POPUP_TYPE_WIFI_RESTRICT:
971 bundle_add(b, "event-type", "wifi-restrict");
974 ERR("Popup is not supported[%d]", type);
979 ret = syspopup_launch("wc-syspopup", b);
981 ERR("Failed to launch syspopup");
987 int wc_launch_popup(netconfig_wcpopup_type_e type)
990 app_control_h app_control = NULL;
992 ret = app_control_create(&app_control);
993 if (ret != APP_CONTROL_ERROR_NONE) {
994 ERR("Failed to create appcontrol[%d]", ret);
999 case WC_POPUP_TYPE_CAPTIVE_PORTAL:
1000 app_control_add_extra_data(app_control, WC_POPUP_EXTRA_DATA_KEY, "captive-portal");
1003 ERR("Popup is not supported[%d]", type);
1004 app_control_destroy(app_control);
1008 app_control_set_app_id(app_control, "com.samsung.weconn-popup");
1009 ret = app_control_send_launch_request(app_control, NULL, NULL);
1010 if (ret != APP_CONTROL_ERROR_NONE) {
1011 DBG("failed appcontrol launch request [%d]", ret);
1012 app_control_destroy(app_control);
1016 app_control_destroy(app_control);
1022 void netconfig_set_vconf_int(const char * key, int value)
1026 DBG("[%s: %d]", key, value);
1028 ret = vconf_set_int(key, value);
1029 if (ret != VCONF_OK)
1030 ERR("Failed to set");
1033 void netconfig_set_vconf_str(const char * key, const char * value)
1037 DBG("[%s: %s]", key, value);
1039 ret = vconf_set_str(key, value);
1040 if (ret != VCONF_OK)
1041 ERR("Failed to set");
1044 char* netconfig_get_env(const char *key)
1047 char buf[256], *entry = NULL, *value = NULL, *last;
1053 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
1057 while (fgets(buf, sizeof(buf), fp)) {
1059 entry = strtok_r(entry, "=", &last);
1061 if (strstr(entry, key)) {
1062 entry = strtok_r(NULL, "\n", &last);
1064 len = strlen(entry);
1065 value = (char*)malloc(len+1);
1066 g_strlcpy(value, entry, len+1);
1068 value = (char*)malloc(sizeof(char));
1069 g_strlcpy(value, "\n", sizeof(char));
1080 void netconfig_set_mac_address_from_file(void)
1083 char mac_str[MAC_ADDRESS_MAX_LEN];
1084 gchar *mac_lower_str = NULL;
1087 file = fopen(MAC_INFO_FILEPATH, "r");
1089 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1092 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
1093 ERR("Fail to read mac address");
1098 mac_len = strlen(mac_str);
1100 ERR("mac.info is empty");
1105 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1106 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1108 g_free(mac_lower_str);