11178022a108e8062ae729c79fc4ab9934600e21
[platform/core/connectivity/net-config.git] / src / utils / util.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <aul.h>
21 #include <app.h>
22 #include <errno.h>
23 #include <vconf.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <unistd.h>
28 #include <net/if.h>
29 #include <net/route.h>
30 #include <arpa/inet.h>
31 #include <sys/wait.h>
32 #include <sys/stat.h>
33 #include <sys/ioctl.h>
34 #include <vconf-keys.h>
35 #include <syspopup_caller.h>
36 #include <bundle.h>
37 #include <bundle_internal.h>
38 #include <eventsystem.h>
39
40 #include "log.h"
41 #include "util.h"
42 #include "neterror.h"
43 #include "wifi-state.h"
44
45 #define WC_POPUP_EXTRA_DATA_KEY "http://samsung.com/appcontrol/data/connection_type"
46
47 static gboolean netconfig_device_picker_test = FALSE;
48
49 GKeyFile *netconfig_keyfile_load(const char *pathname)
50 {
51         GKeyFile *keyfile = NULL;
52         GError *error = NULL;
53
54         keyfile = g_key_file_new();
55         if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
56                 DBG("Unable to open %s, error %s", pathname, error->message);
57                 g_error_free(error);
58
59                 g_key_file_free(keyfile);
60                 keyfile = NULL;
61         }
62
63         return keyfile;
64 }
65
66 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
67 {
68         gsize size = 0;
69         GError *error = NULL;
70         gchar *keydata = NULL;
71         gchar *needle = NULL, *directory = NULL;
72
73         directory = g_strdup(pathname);
74         needle = g_strrstr(directory, "/");
75
76         if (needle != NULL)
77                 *needle = '\0';
78
79         if (directory == NULL || (*directory) == '\0') {
80                 g_free(directory);
81                 return;
82         }
83
84         if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) {
85                 if (g_mkdir_with_parents(directory,
86                                 S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
87                         g_free(directory);
88                         return;
89                 }
90         }
91         g_free(directory);
92
93         keydata = g_key_file_to_data(keyfile, &size, &error);
94         if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
95                 DBG("Unable to save %s, error %s", pathname, error->message);
96                 g_error_free(error);
97         }
98
99         chmod(pathname, S_IRUSR | S_IWUSR);
100
101         g_free(keydata);
102
103         g_key_file_free(keyfile);
104 }
105
106 void netconfig_start_timer_seconds(guint secs,
107                 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
108 {
109         guint t_id = 0;
110
111         if (callback == NULL) {
112                 ERR("callback function is NULL");
113                 return;
114         }
115
116         if ((timer_id != NULL && *timer_id != 0)) {
117                 ERR("timer already is registered");
118                 return;
119         }
120
121         t_id = g_timeout_add_seconds(secs, callback, user_data);
122
123         if (t_id == 0) {
124                 ERR("Can't add timer");
125                 return;
126         }
127
128         if (timer_id != NULL)
129                 *timer_id = t_id;
130 }
131
132 void netconfig_start_timer(guint msecs,
133                 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
134 {
135         guint t_id = 0;
136
137         INFO("Register timer with callback pointer (%p)", callback);
138
139         if (callback == NULL) {
140                 ERR("callback function is NULL");
141                 return;
142         }
143
144         if ((timer_id != NULL && *timer_id != 0)) {
145                 ERR("timer already is registered");
146                 return;
147         }
148
149         t_id = g_timeout_add(msecs, callback, user_data);
150
151         if (t_id == 0) {
152                 ERR("Can't add timer");
153                 return;
154         }
155
156         if (timer_id != NULL)
157                 *timer_id = t_id;
158 }
159
160 void netconfig_stop_timer(guint *timer_id)
161 {
162         if (timer_id == NULL) {
163                 ERR("timer is NULL");
164                 return;
165         }
166
167         if (*timer_id != 0) {
168                 g_source_remove(*timer_id);
169                 *timer_id = 0;
170         }
171 }
172
173 static gboolean __netconfig_test_device_picker()
174 {
175         char *favorite_wifi_service = NULL;
176
177         favorite_wifi_service = netconfig_wifi_get_favorite_service();
178         if (favorite_wifi_service != NULL) {
179                 g_free(favorite_wifi_service);
180                 return FALSE;
181         }
182
183         return TRUE;
184 }
185
186 static void __netconfig_pop_device_picker(void)
187 {
188 #if defined TIZEN_WEARABLE
189         int ret = 0;
190         app_control_h   control = NULL;
191
192         ret = app_control_create(&control);
193         if (APP_CONTROL_ERROR_NONE != ret) {
194                 DBG("failed to create app control");
195                 return ;
196         }
197
198         app_control_add_extra_data(control, "viewtype", "scanlist");
199
200         app_control_set_app_id(control, "org.tizen.wifi");
201         ret = app_control_send_launch_request(control, NULL, NULL);
202         if (APP_CONTROL_ERROR_NONE == ret)
203                 DBG("Launch request sent successfully");
204
205         app_control_destroy(control);
206 #else
207         bundle *b = NULL;
208         int wifi_ug_state = 0;
209
210         vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
211         if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
212                 return;
213
214         b = bundle_create();
215
216         DBG("Launch Wi-Fi device picker");
217         syspopup_launch("wifi-qs", b);
218
219         bundle_free(b);
220 #endif
221 }
222
223 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
224 {
225         if (__netconfig_test_device_picker() == TRUE)
226                 __netconfig_pop_device_picker();
227
228         return FALSE;
229 }
230
231 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method,
232                 guint timer_id)
233 {
234         static guint netconfig_wifi_device_picker_service_timer = 0;
235
236         if (is_set_method != TRUE)
237                 return netconfig_wifi_device_picker_service_timer;
238
239         if (netconfig_wifi_device_picker_service_timer != timer_id)
240                 netconfig_wifi_device_picker_service_timer = timer_id;
241
242         return netconfig_wifi_device_picker_service_timer;
243 }
244
245 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
246 {
247         __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
248 }
249
250 static guint __netconfig_wifi_device_picker_get_timer_id(void)
251 {
252         return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
253 }
254
255 void netconfig_wifi_enable_device_picker_test(void)
256 {
257         netconfig_device_picker_test = TRUE;
258 }
259
260 void netconfig_wifi_device_picker_service_start(void)
261 {
262         const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
263         guint timer_id = 0;
264
265         if (netconfig_device_picker_test == TRUE)
266                 netconfig_device_picker_test = FALSE;
267         else
268                 return;
269
270 #if defined TIZEN_WEARABLE
271         if (aul_app_is_running("org.tizen.wifi") > 0) {
272                 DBG("wifi app is running");
273                 return;
274         }
275 #else
276         int wifi_ug_state;
277
278         if (netconfig_device_picker_test == TRUE)
279                 netconfig_device_picker_test = FALSE;
280         else
281                 return;
282
283         vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
284         if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
285                 return;
286 #endif
287
288         DBG("Register device picker timer with %d milliseconds",
289                         NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
290
291         netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL,
292                         __netconfig_wifi_try_device_picker, NULL, &timer_id);
293
294         __netconfig_wifi_device_picker_set_timer_id(timer_id);
295 }
296
297 void netconfig_wifi_device_picker_service_stop(void)
298 {
299         guint timer_id = 0;
300
301         timer_id = __netconfig_wifi_device_picker_get_timer_id();
302         if (timer_id == 0)
303                 return;
304
305         DBG("Clear device picker timer with timer_id %d", timer_id);
306
307         netconfig_stop_timer(&timer_id);
308
309         __netconfig_wifi_device_picker_set_timer_id(timer_id);
310 }
311
312 gboolean netconfig_is_wifi_direct_on(void)
313 {
314 #if defined TIZEN_P2P_ENABLE
315         int wifi_direct_state = 0;
316
317         vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
318
319         DBG("Wi-Fi direct mode %d", wifi_direct_state);
320         return (wifi_direct_state != 0) ? TRUE : FALSE;
321 #else
322         return FALSE;
323 #endif
324 }
325
326 gboolean netconfig_is_wifi_tethering_on(void)
327 {
328 #if defined TIZEN_TETHERING_ENABLE
329         int wifi_tethering_state = 0;
330
331         vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
332
333         DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
334         if (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
335                 return TRUE;
336 #endif
337         return FALSE;
338 }
339
340 gboolean netconfig_interface_up(const char *ifname)
341 {
342         int fd;
343         struct ifreq ifr;
344
345         fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
346         if (fd < 0)
347                 return FALSE;
348
349         memset(&ifr, 0, sizeof(ifr));
350         g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
351
352         if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
353                 close(fd);
354                 return FALSE;
355         }
356
357         ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
358         if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
359                 close(fd);
360                 return FALSE;
361         }
362
363         close(fd);
364
365         DBG("Successfully activated wireless interface");
366         return TRUE;
367 }
368
369 gboolean netconfig_interface_down(const char *ifname)
370 {
371         int fd;
372         struct ifreq ifr;
373
374         fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
375         if (fd < 0)
376                 return FALSE;
377
378         memset(&ifr, 0, sizeof(ifr));
379         g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
380
381         if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
382                 close(fd);
383                 return FALSE;
384         }
385
386         ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
387         if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
388                 close(fd);
389                 return FALSE;
390         }
391
392         close(fd);
393
394         DBG("Successfully de-activated wireless interface");
395         return TRUE;
396 }
397
398 int netconfig_execute_file(const char *file_path,
399                 char *const args[], char *const envs[])
400 {
401         pid_t pid = 0;
402         int status = 0;
403         int rv = 0;
404         errno = 0;
405         register unsigned int index = 0;
406
407         while (args[index] != NULL) {
408                 DBG("%s", args[index]);
409                 index++;
410         }
411
412         if (!(pid = fork())) {
413                 DBG("pid(%d), ppid (%d)", getpid(), getppid());
414                 DBG("Inside child, exec (%s) command", file_path);
415
416                 errno = 0;
417                 if (execve(file_path, args, envs) == -1) {
418                         DBG("Fail to execute command (%s)", strerror(errno));
419                         exit(1);
420                 }
421         } else if (pid > 0) {
422                 if (waitpid(pid, &status, 0) == -1)
423                         DBG("wait pid (%u) status (%d)", pid, status);
424
425                 if (WIFEXITED(status)) {
426                         rv = WEXITSTATUS(status);
427                         DBG("exited, status=%d", rv);
428                 } else if (WIFSIGNALED(status)) {
429                         DBG("killed by signal %d", WTERMSIG(status));
430                 } else if (WIFSTOPPED(status)) {
431                         DBG("stopped by signal %d", WSTOPSIG(status));
432                 } else if (WIFCONTINUED(status)) {
433                         DBG("continued");
434                 }
435
436                 return rv;
437         }
438
439         DBG("failed to fork(%s)", strerror(errno));
440         return -EIO;
441 }
442
443 static void on_clat_handler()
444 {
445         pid_t clat_pid = 0;
446         int state = 0;
447
448         clat_pid = waitpid(-1, &state, WNOHANG);
449
450         DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
451 }
452
453 int netconfig_execute_clatd(const char *file_path, char *const args[])
454 {
455         pid_t pid = 0;
456         int rv = 0;
457         errno = 0;
458         register unsigned int index = 0;
459
460         struct sigaction act;
461         int state = 0;
462
463         act.sa_handler = on_clat_handler;
464         sigemptyset(&act.sa_mask);
465         act.sa_flags = 0;
466
467         state = sigaction(SIGCHLD, &act, 0);
468         if (state != 0) {
469                 DBG("sigaction() : %d");
470                 return -1;
471         }
472
473         while (args[index] != NULL) {
474                 DBG("%s", args[index]);
475                 index++;
476         }
477
478         if (!(pid = fork())) {
479                 DBG("pid(%d), ppid (%d)", getpid(), getppid());
480                 DBG("Inside child, exec (%s) command", file_path);
481
482                 errno = 0;
483                 if (execvp(file_path, args) == -1) {
484                         ERR("Fail to execute command (%s)", strerror(errno));
485                         return -1;
486                 }
487         } else if (pid > 0) {
488                 ERR("Success to launch clatd");
489                 return rv;
490         }
491
492         DBG("failed to fork(%s)", strerror(errno));
493         return -EIO;
494 }
495
496 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
497 {
498         struct in6_rtmsg rt;
499         int fd = 0;
500         int err = 0;
501
502         memset(&rt, 0, sizeof(rt));
503
504         rt.rtmsg_dst_len = prefix_len;
505
506         rt.rtmsg_flags = RTF_UP | RTF_HOST;
507
508         if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
509                 err = -errno;
510                 return err;
511         }
512
513         if (gateway != NULL) {
514                 rt.rtmsg_flags |= RTF_GATEWAY;
515                 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
516                         err = -errno;
517                         return err;
518                 }
519         }
520
521         rt.rtmsg_metric = 1;
522
523         fd = socket(AF_INET6, SOCK_DGRAM, 0);
524         if (fd < 0)
525                 return -1;
526
527         rt.rtmsg_ifindex = 0;
528
529         if (interface) {
530                 struct ifreq ifr;
531                 memset(&ifr, 0, sizeof(ifr));
532                 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
533                 ioctl(fd, SIOCGIFINDEX, &ifr);
534                 rt.rtmsg_ifindex = ifr.ifr_ifindex;
535         }
536
537         if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
538                 DBG("Failed to add route: %d\n", err);
539                 close(fd);
540                 return -1;
541         }
542
543         close(fd);
544
545         return 1;
546 }
547
548 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
549 {
550         struct in6_rtmsg rt;
551         int fd = 0;
552         int err = 0;
553
554         memset(&rt, 0, sizeof(rt));
555
556         rt.rtmsg_dst_len = prefix_len;
557
558         rt.rtmsg_flags = RTF_UP | RTF_HOST;
559
560         if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
561                 err = -errno;
562                 return err;
563         }
564
565         if (gateway != NULL) {
566                 rt.rtmsg_flags |= RTF_GATEWAY;
567                 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
568                         err = -errno;
569                         return err;
570                 }
571         }
572
573         rt.rtmsg_metric = 1;
574
575         fd = socket(AF_INET6, SOCK_DGRAM, 0);
576         if (fd < 0)
577                 return -1;
578
579         rt.rtmsg_ifindex = 0;
580
581         if (interface) {
582                 struct ifreq ifr;
583                 memset(&ifr, 0, sizeof(ifr));
584                 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
585                 ioctl(fd, SIOCGIFINDEX, &ifr);
586                 rt.rtmsg_ifindex = ifr.ifr_ifindex;
587         }
588
589         if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
590                 DBG("Failed to add route: %d\n", err);
591                 close(fd);
592                 return -1;
593         }
594
595         close(fd);
596
597         return 1;
598 }
599
600 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
601 {
602 #if defined TIZEN_P2P_ENABLE
603         int ret = 0;
604         DBG("Launch Wi-Fi direct daemon");
605
606         const char *path = "/usr/bin/wifi-direct-server.sh";
607         char *const args[] = { "wifi-direct-server.sh", "start", NULL };
608         char *const envs[] = { NULL };
609
610         ret = netconfig_execute_file(path, args, envs);
611         if (ret < 0) {
612                 ERR("Failed to launch Wi-Fi direct daemon");
613                 netconfig_error_wifi_direct_failed(context);
614                 return FALSE;
615         }
616         wifi_complete_launch_direct(wifi, context);
617         return TRUE;
618 #else
619         wifi_complete_launch_direct(wifi, context);
620         return FALSE;
621 #endif
622 }
623
624 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
625 {
626         int ret = 0;
627         bundle *b;
628         static gboolean is_found_noti_exists = FALSE;
629         static gboolean is_portal_noti_exists = FALSE;
630
631         if (noti == NULL) {
632                 ERR("Invalid notification");
633                 return FALSE;
634         }
635
636         if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) {
637                 if (is_found_noti_exists == FALSE)
638                         return TRUE;
639
640                 is_found_noti_exists = FALSE;
641         } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) {
642                 if (is_found_noti_exists == TRUE)
643                         return TRUE;
644
645                 is_found_noti_exists = TRUE;
646         } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) {
647                 if (is_portal_noti_exists == TRUE)
648                         return TRUE;
649
650                 is_portal_noti_exists = TRUE;
651         } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) {
652                 if (is_portal_noti_exists == FALSE)
653                         return TRUE;
654
655                 is_portal_noti_exists = FALSE;
656         }
657
658         b = bundle_create();
659         bundle_add(b, "_SYSPOPUP_TYPE_", noti);
660
661         if (ssid != NULL) {
662                 DBG("ssid (%s)", ssid);
663                 bundle_add(b, "_AP_NAME_", ssid);
664         }
665
666         ret = aul_launch_app("net.netpopup", b);
667
668         bundle_free(b);
669
670         if (ret < 0) {
671                 ERR("Unable to launch noti-popup. Err = %d", ret);
672                 return FALSE;
673         }
674
675         DBG("Successfully sent notification (%s)", noti);
676         return TRUE;
677 }
678
679 int netconfig_send_message_to_net_popup(const char *title,
680                 const char *content, const char *type, const char *ssid)
681 {
682         int ret = 0;
683         bundle *b = bundle_create();
684
685         bundle_add(b, "_SYSPOPUP_TITLE_", title);
686         bundle_add(b, "_SYSPOPUP_CONTENT_", content);
687         bundle_add(b, "_SYSPOPUP_TYPE_", type);
688         bundle_add(b, "_AP_NAME_", ssid);
689
690         ret = aul_launch_app("net.netpopup", b);
691
692         bundle_free(b);
693
694         return ret;
695 }
696
697 void netconfig_set_system_event(const char * sys_evt, const char * evt_key, const char * evt_val)
698 {
699         bundle *b = NULL;
700
701         DBG("System event set [%s : %s : %s]", sys_evt, evt_key, evt_val);
702
703         b = bundle_create();
704         bundle_add_str(b, evt_key, evt_val);
705         eventsystem_send_system_event(sys_evt, b);
706         bundle_free(b);
707 }
708
709 #if defined TIZEN_WEARABLE
710 int wc_launch_syspopup(netconfig_wcpopup_type_e type)
711 {
712         int ret;
713         bundle* b;
714         char *ssid = NULL;
715
716         b = bundle_create();
717         if (!b) {
718                 ERR("Failed to create bundle");
719                 return -1;
720         }
721
722         switch (type) {
723         case WC_POPUP_TYPE_SESSION_OVERLAPPED:
724                 bundle_add(b, "event-type", "wps-session-overlapped");
725                 break;
726         case WC_POPUP_TYPE_WIFI_CONNECTED:
727                 ssid = vconf_get_str(VCONFKEY_WIFI_CONNECTED_AP_NAME);
728                 if (ssid == NULL) {
729                         ERR("Failed to get connected ap ssid");
730                         ssid = g_strdup(" ");
731                 }
732                 bundle_add(b, "event-type", "wifi-connected");
733                 bundle_add(b, "ssid", ssid);
734                 if (ssid)
735                         g_free(ssid);
736                 break;
737         case WC_POPUP_TYPE_WIFI_RESTRICT:
738                                 bundle_add(b, "event-type", "wifi-restrict");
739                                 break;
740         default:
741                 ERR("Popup is not supported[%d]", type);
742                 bundle_free(b);
743                 return -1;
744         }
745
746         ret = syspopup_launch("wc-syspopup", b);
747         if (ret < 0)
748                 ERR("Failed to launch syspopup");
749
750         bundle_free(b);
751
752         return ret;
753 }
754
755 int wc_launch_popup(netconfig_wcpopup_type_e type)
756 {
757         int ret;
758         app_control_h app_control = NULL;
759
760         ret = app_control_create(&app_control);
761         if (ret != APP_CONTROL_ERROR_NONE) {
762                 ERR("Failed to create appcontrol[%d]", ret);
763                 return -1;
764         }
765
766         switch (type) {
767         case WC_POPUP_TYPE_CAPTIVE_PORTAL:
768                 app_control_add_extra_data(app_control, WC_POPUP_EXTRA_DATA_KEY, "captive-portal");
769                 break;
770         default:
771                 ERR("Popup is not supported[%d]", type);
772                 app_control_destroy(app_control);
773                 return -1;
774         }
775
776         app_control_set_app_id(app_control, "com.samsung.weconn-popup");
777         ret = app_control_send_launch_request(app_control, NULL, NULL);
778         if (ret != APP_CONTROL_ERROR_NONE) {
779                 DBG("failed appcontrol launch request [%d]", ret);
780                 app_control_destroy(app_control);
781                 return -1;
782         }
783
784         app_control_destroy(app_control);
785
786         return 0;
787 }
788 #endif
789
790 void netconfig_set_vconf_int(const char * key, int value)
791 {
792         int ret = 0;
793
794         DBG("[%s: %d]", key, value);
795
796         ret = vconf_set_int(key, value);
797         if (ret != VCONF_OK)
798                 ERR("Failed to set");
799 }
800
801 void netconfig_set_vconf_str(const char * key, const char * value)
802 {
803         int ret = 0;
804
805         DBG("[%s: %s]", key, value);
806
807         ret = vconf_set_str(key, value);
808         if (ret != VCONF_OK)
809                 ERR("Failed to set");
810 }
811
812 char* netconfig_get_env(const char *key)
813 {
814         FILE *fp;
815         char buf[256], *entry = NULL, *value = NULL, *last;
816         int len=0;
817
818         if (!key)
819                 return NULL;
820
821         fp = fopen(NETCONFIG_TIZENMOBILEENV, "r");
822         if (!fp)
823                 return NULL;
824
825         while (fgets(buf, sizeof(buf), fp)) {
826                 entry = buf;
827                 entry = strtok_r(entry, "=", &last);
828                 if (entry) {
829                         if (strstr(entry, key)) {
830                                 entry = strtok_r(NULL, "\n", &last);
831                                 if(entry){
832                                         len = strlen(entry);
833                                         value = (char*)malloc(len+1);
834                                         g_strlcpy(value, entry, len+1);
835                                 }
836                                 else{
837                                         value = (char*)malloc(sizeof(char));
838                                         g_strlcpy(value, "\n", sizeof(char));
839                                 }
840                                 break;
841                         }
842                 }
843         }
844
845         fclose(fp);
846         return value;
847 }