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 <tzplatform_config.h>
35 #include <system_info.h>
40 #include "wifi-state.h"
43 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
44 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
45 #define MAC_INFO_FILEPATH tzplatform_mkpath(TZ_SYS_ETC, "/.mac.info")
46 #define MAC_ADDRESS_FILEPATH "/sys/class/net/wlan0/address"
47 #define MAC_ADDRESS_MAX_LEN 18
48 #define HEADED_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-headed.so"
49 #define TELEPHONY_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-telephony.so"
51 static gboolean netconfig_device_picker_test = FALSE;
52 static int mdnsd_ref_count = 0;
56 } dnssd_conn_destroy_data;
58 static gboolean netconfig_plugin_headed_enabled = FALSE;
59 static gboolean netconfig_plugin_telephony_enabled = FALSE;
60 static void *handle_headed;
61 static void *handle_telephony;
62 static struct netconfig_headed_plugin_t *headed_plugin;
63 static struct netconfig_telephony_plugin_t *telephony_plugin;
65 GKeyFile *netconfig_keyfile_load(const char *pathname)
67 GKeyFile *keyfile = NULL;
70 keyfile = g_key_file_new();
71 if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
72 DBG("Unable to open %s, error %s", pathname, error->message);
75 g_key_file_free(keyfile);
79 DBG("loaded keyfile %s", pathname);
83 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
87 gchar *keydata = NULL;
88 gchar *needle = NULL, *directory = NULL;
90 directory = g_strdup(pathname);
91 needle = g_strrstr(directory, "/");
96 if (directory == NULL || (*directory) == '\0') {
98 ERR("directory is NULL");
102 if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) {
103 if (g_mkdir_with_parents(directory,
104 S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
106 ERR("failed to make directory");
112 keydata = g_key_file_to_data(keyfile, &size, &error);
113 if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
114 ERR("Unable to save %s, error %s", pathname, error->message);
118 chmod(pathname, S_IRUSR | S_IWUSR);
119 DBG("Successfully saved keyfile %s", pathname);
124 void netconfig_start_timer_seconds(guint secs,
125 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
129 if (callback == NULL) {
130 ERR("callback function is NULL");
134 if ((timer_id != NULL && *timer_id != 0)) {
135 ERR("timer already is registered");
139 t_id = g_timeout_add_seconds(secs, callback, user_data);
142 ERR("Can't add timer");
146 if (timer_id != NULL)
150 void netconfig_start_timer(guint msecs,
151 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
155 INFO("Register timer with callback pointer (%p)", callback);
157 if (callback == NULL) {
158 ERR("callback function is NULL");
162 if ((timer_id != NULL && *timer_id != 0)) {
163 DBG("timer already is registered");
167 t_id = g_timeout_add(msecs, callback, user_data);
170 ERR("Can't add timer");
174 if (timer_id != NULL)
178 void netconfig_stop_timer(guint *timer_id)
180 if (timer_id == NULL) {
181 ERR("timer is NULL");
185 if (*timer_id != 0) {
186 g_source_remove(*timer_id);
191 static gboolean __netconfig_test_device_picker()
193 char *favorite_wifi_service = NULL;
195 favorite_wifi_service = wifi_get_favorite_service();
196 if (favorite_wifi_service != NULL) {
197 ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service);
198 g_free(favorite_wifi_service);
205 static void __netconfig_pop_device_picker(void)
207 if (!netconfig_plugin_headed_enabled)
213 headed_plugin->pop_device_picker();
216 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
218 if (__netconfig_test_device_picker() == TRUE)
219 __netconfig_pop_device_picker();
224 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id)
226 static guint netconfig_wifi_device_picker_service_timer = 0;
228 if (is_set_method != TRUE)
229 return netconfig_wifi_device_picker_service_timer;
231 if (netconfig_wifi_device_picker_service_timer != timer_id)
232 netconfig_wifi_device_picker_service_timer = timer_id;
234 return netconfig_wifi_device_picker_service_timer;
237 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
239 __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
242 static guint __netconfig_wifi_device_picker_get_timer_id(void)
244 return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
247 void netconfig_wifi_enable_device_picker_test(void)
249 netconfig_device_picker_test = TRUE;
252 void netconfig_wifi_device_picker_service_start(void)
254 const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
257 if (netconfig_device_picker_test == TRUE)
258 netconfig_device_picker_test = FALSE;
264 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
265 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
268 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
269 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
271 __netconfig_wifi_device_picker_set_timer_id(timer_id);
274 void netconfig_wifi_device_picker_service_stop(void)
278 timer_id = __netconfig_wifi_device_picker_get_timer_id();
282 DBG("Clear device picker timer with timer_id %d", timer_id);
284 netconfig_stop_timer(&timer_id);
286 __netconfig_wifi_device_picker_set_timer_id(timer_id);
289 gboolean netconfig_is_wifi_direct_on(void)
291 #if defined TIZEN_P2P_ENABLE
292 int wifi_direct_state = 0;
294 netconfig_vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
296 DBG("Wi-Fi direct mode %d", wifi_direct_state);
297 return (wifi_direct_state != 0) ? TRUE : FALSE;
303 gboolean netconfig_is_wifi_tethering_on(void)
305 #if defined TIZEN_TETHERING_ENABLE
306 int wifi_tethering_state = 0;
308 netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
309 DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
310 if ((wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
311 || (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP)) {
312 DBG("Mobile AP is on");
316 DBG("Mobile AP is off");
320 gboolean netconfig_interface_up(const char *ifname)
325 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
329 memset(&ifr, 0, sizeof(ifr));
330 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
332 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
337 ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
338 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
345 DBG("Successfully activated wireless interface %s", ifname);
349 gboolean netconfig_interface_down(const char *ifname)
354 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
358 memset(&ifr, 0, sizeof(ifr));
359 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
361 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
366 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
367 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
374 DBG("Successfully de-activated wireless interface %s", ifname);
378 int netconfig_execute_file(const char *file_path,
379 char *const args[], char *const envs[])
385 register unsigned int index = 0;
386 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
388 while (args[index] != NULL) {
389 DBG("%s", args[index]);
393 if (!(pid = fork())) {
394 DBG("pid(%d), ppid (%d)", getpid(), getppid());
395 DBG("Inside child, exec (%s) command", file_path);
398 if (execve(file_path, args, envs) == -1) {
399 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
400 DBG("Fail to execute command (%s)", error_buf);
403 } else if (pid > 0) {
404 if (waitpid(pid, &status, 0) == -1)
405 DBG("wait pid (%u) status (%d)", pid, status);
407 if (WIFEXITED(status)) {
408 rv = WEXITSTATUS(status);
409 DBG("exited, status=%d", rv);
410 } else if (WIFSIGNALED(status)) {
411 DBG("killed by signal %d", WTERMSIG(status));
412 } else if (WIFSTOPPED(status)) {
413 DBG("stopped by signal %d", WSTOPSIG(status));
414 } else if (WIFCONTINUED(status)) {
421 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
422 DBG("failed to fork(%s)", error_buf);
426 int netconfig_execute_cmd(const char *cmd)
435 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
438 DBG("command: %s", cmd);
440 args = g_strsplit_set(cmd, " ", -1);
442 if (!(pid = fork())) {
443 DBG("pid(%d), ppid (%d)", getpid(), getppid());
446 if (execv(args[0], args) == -1) {
447 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
448 DBG("Fail to execute command (%s)", error_buf);
452 } else if (pid > 0) {
453 if (waitpid(pid, &status, 0) == -1)
454 DBG("wait pid (%u) status (%d)", pid, status);
456 if (WIFEXITED(status)) {
457 rv = WEXITSTATUS(status);
458 DBG("exited, status=%d", rv);
459 } else if (WIFSIGNALED(status)) {
460 DBG("killed by signal %d", WTERMSIG(status));
461 } else if (WIFSTOPPED(status)) {
462 DBG("stopped by signal %d", WSTOPSIG(status));
463 } else if (WIFCONTINUED(status)) {
471 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
472 DBG("failed to fork(%s)", error_buf);
478 static void on_clat_handler()
483 clat_pid = waitpid(-1, &state, WNOHANG);
485 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
488 int netconfig_execute_clatd(const char *file_path, char *const args[])
493 register unsigned int index = 0;
494 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
496 struct sigaction act;
499 act.sa_handler = on_clat_handler;
500 sigemptyset(&act.sa_mask);
503 state = sigaction(SIGCHLD, &act, 0);
505 DBG("sigaction() : %d");
509 while (args[index] != NULL) {
510 DBG("%s", args[index]);
514 if (!(pid = fork())) {
515 DBG("pid(%d), ppid (%d)", getpid(), getppid());
516 DBG("Inside child, exec (%s) command", file_path);
519 if (execvp(file_path, args) == -1) {
520 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
521 ERR("Fail to execute command (%s)", error_buf);
524 } else if (pid > 0) {
525 ERR("Success to launch clatd");
529 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
530 DBG("failed to fork(%s)", error_buf);
534 int __netconfig_get_interface_index(const char *interface_name)
539 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
541 if (interface_name == NULL) {
542 DBG("Inteface name is NULL");
547 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
549 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
550 DBG("Failed to create socket : %s", error_buf);
554 memset(&ifr, 0, sizeof(ifr));
555 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
556 result = ioctl(sock, SIOCGIFINDEX, &ifr);
560 DBG("Failed to get ifr index: %s", error_buf);
564 return ifr.ifr_ifindex;
567 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
571 struct sockaddr_in addr_in;
573 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
575 memset(&ifr, 0, sizeof(ifr));
577 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
579 if (ifr.ifr_ifindex < 0)
582 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
584 memset(&rt, 0, sizeof(rt));
586 rt.rt_flags = RTF_UP | RTF_HOST;
587 memset(&addr_in, 0, sizeof(struct sockaddr_in));
588 addr_in.sin_family = address_family;
589 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
590 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
592 memset(&addr_in, 0, sizeof(struct sockaddr_in));
593 addr_in.sin_family = address_family;
594 addr_in.sin_addr.s_addr = INADDR_ANY;
595 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
597 memset(&addr_in, 0, sizeof(struct sockaddr_in));
598 addr_in.sin_family = AF_INET;
599 addr_in.sin_addr.s_addr = inet_addr(subnet);
600 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
602 rt.rt_dev = ifr.ifr_name;
605 sock = socket(PF_INET, SOCK_DGRAM, 0);
608 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
609 DBG("Failed to create socket : %s", error_buf);
613 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
614 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
615 DBG("Failed to set route address : %s", error_buf);
625 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
629 struct sockaddr_in addr_in;
631 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
633 memset(&ifr, 0, sizeof(ifr));
634 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
636 if (ifr.ifr_ifindex < 0)
639 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
641 memset(&rt, 0, sizeof(rt));
643 rt.rt_flags = RTF_UP;
644 memset(&addr_in, 0, sizeof(struct sockaddr_in));
645 addr_in.sin_family = address_family;
646 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
647 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
649 memset(&addr_in, 0, sizeof(struct sockaddr_in));
650 addr_in.sin_family = address_family;
651 addr_in.sin_addr.s_addr = inet_addr(subnet);
652 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
653 rt.rt_dev = ifr.ifr_name;
656 sock = socket(PF_INET, SOCK_DGRAM, 0);
659 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
660 DBG("Failed to create socket : %s", error_buf);
664 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
665 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
666 DBG("Failed to set route address : %s", error_buf);
676 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
681 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
683 memset(&rt, 0, sizeof(rt));
685 rt.rtmsg_dst_len = prefix_len;
687 rt.rtmsg_flags = RTF_UP | RTF_HOST;
690 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
691 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
692 DBG("inet_pton failed : %s", error_buf);
696 if (gateway != NULL) {
697 rt.rtmsg_flags |= RTF_GATEWAY;
698 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
699 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
700 DBG("inet_pton failed : %s", error_buf);
707 fd = socket(AF_INET6, SOCK_DGRAM, 0);
709 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
710 DBG("Failed to create socket : %s", error_buf);
714 rt.rtmsg_ifindex = 0;
718 memset(&ifr, 0, sizeof(ifr));
719 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
720 ioctl(fd, SIOCGIFINDEX, &ifr);
721 rt.rtmsg_ifindex = ifr.ifr_ifindex;
724 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
725 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
726 DBG("Failed to add route: %s", error_buf);
736 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
742 memset(&rt, 0, sizeof(rt));
744 rt.rtmsg_dst_len = prefix_len;
746 rt.rtmsg_flags = RTF_UP | RTF_HOST;
748 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
753 if (gateway != NULL) {
754 rt.rtmsg_flags |= RTF_GATEWAY;
755 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
763 fd = socket(AF_INET6, SOCK_DGRAM, 0);
767 rt.rtmsg_ifindex = 0;
771 memset(&ifr, 0, sizeof(ifr));
772 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
773 ioctl(fd, SIOCGIFINDEX, &ifr);
774 rt.rtmsg_ifindex = ifr.ifr_ifindex;
777 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
778 DBG("Failed to del route: %d\n", err);
788 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
790 #if defined TIZEN_P2P_ENABLE
792 DBG("Launch Wi-Fi direct daemon");
794 const char *path = "/usr/bin/wifi-direct-server.sh";
795 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
796 char *const envs[] = { NULL };
798 ret = netconfig_execute_file(path, args, envs);
800 ERR("Failed to launch Wi-Fi direct daemon");
801 netconfig_error_wifi_direct_failed(context);
805 wifi_complete_launch_direct(wifi, context);
808 wifi_complete_launch_direct(wifi, context);
813 int execute_mdnsd_script(char* op)
815 const char *path = "/usr/bin/mdnsresponder-server.sh";
816 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
817 char *const envs[] = { NULL };
819 return netconfig_execute_file(path, args, envs);
822 static void __dnssd_conn_destroyed_cb(GDBusConnection *conn,
823 const gchar *Name, const gchar *path, const gchar *interface,
824 const gchar *sig, GVariant *param, gpointer user_data)
829 dnssd_conn_destroy_data *data = user_data;
830 GDBusConnection *connection = NULL;
831 connection = netdbus_get_connection();
836 g_variant_get(param, "(sss)", &name, &old, &new);
838 if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
839 DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name,
842 g_dbus_connection_signal_unsubscribe(connection, data->conn_id);
843 if (mdnsd_ref_count == 0) {
844 if (execute_mdnsd_script("stop") < 0)
845 ERR("Failed to stop mdnsresponder daemon");
851 g_free(data->conn_name);
856 static void register_dnssd_conn_destroy_signal(gchar *name)
858 dnssd_conn_destroy_data *data;
859 GDBusConnection *connection = NULL;
860 connection = netdbus_get_connection();
862 if (connection == NULL) {
863 ERR("Failed to get GDbus Connection");
867 data = g_try_malloc0(sizeof(dnssd_conn_destroy_data));
870 ERR("Out of Memory!");
874 data->conn_name = g_strdup(name);
876 data->conn_id = g_dbus_connection_signal_subscribe(connection,
877 DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
878 "NameOwnerChanged", NULL, name,
879 G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb,
884 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context,
887 DBG("Launch mdnsresponder daemon");
889 if (execute_mdnsd_script("start") < 0) {
890 ERR("Failed to launch mdnsresponder daemon");
891 netconfig_error_invalid_parameter(context);
896 register_dnssd_conn_destroy_signal(name);
897 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
899 network_complete_launch_mdns(object, context);
903 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
905 if (!netconfig_plugin_headed_enabled)
911 return headed_plugin->send_notification_to_net_popup(noti, ssid);
914 int netconfig_send_message_to_net_popup(const char *title,
915 const char *content, const char *type, const char *ssid)
917 if (!netconfig_plugin_headed_enabled)
923 return headed_plugin->send_message_to_net_popup(title, content, type, ssid);
926 int netconfig_send_restriction_to_net_popup(const char *title,
927 const char *type, const char *restriction)
929 if (!netconfig_plugin_headed_enabled)
935 return headed_plugin->send_restriction_to_net_popup(title, type, restriction);
938 void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val)
940 if (!netconfig_plugin_headed_enabled)
946 headed_plugin->set_system_event(sys_evt, evt_key, evt_val);
949 void __netconfig_pop_wifi_connected_poppup(const char *ssid)
951 if (!netconfig_plugin_headed_enabled)
957 headed_plugin->pop_wifi_connected_poppup(ssid);
960 void netconfig_get_telephony_network_type(int *svctype, int *pstype)
962 if (!netconfig_plugin_telephony_enabled)
965 if (!telephony_plugin)
968 telephony_plugin->get_telephony_network_type(svctype, pstype);
971 gboolean __netconfig_wifi_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context)
973 if (!netconfig_plugin_telephony_enabled)
976 if (!telephony_plugin)
979 return telephony_plugin->wifi_get_sim_imsi(wifi, context);
982 netconfig_error_e __netconfig_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data,
983 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
985 if (!netconfig_plugin_telephony_enabled)
986 return NETCONFIG_ERROR_INTERNAL;
988 if (!telephony_plugin)
989 return NETCONFIG_ERROR_INTERNAL;
991 return telephony_plugin->wifi_req_aka_auth(rand_data, autn_data, context, data);
994 gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data,
995 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
997 if (!netconfig_plugin_telephony_enabled)
1000 if (!telephony_plugin)
1003 return telephony_plugin->wifi_req_sim_auth(rand_data, context, data);
1006 gboolean netconfig_tapi_check_sim_state(void)
1008 if (!netconfig_plugin_telephony_enabled)
1011 if (!telephony_plugin)
1014 return telephony_plugin->tapi_check_sim_state();
1017 gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi,
1018 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1020 if (!netconfig_plugin_telephony_enabled)
1023 if (!telephony_plugin)
1026 return telephony_plugin->wifi_get_aka_authdata(wifi, context, data);
1029 gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi,
1030 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1032 if (!netconfig_plugin_telephony_enabled)
1035 if (!telephony_plugin)
1038 return telephony_plugin->wifi_get_sim_authdata(wifi, context, data);
1041 void netconfig_set_vconf_int(const char * key, int value)
1045 DBG("[%s: %d]", key, value);
1047 ret = vconf_set_int(key, value);
1048 if (ret != VCONF_OK)
1049 ERR("Failed to set");
1052 void netconfig_set_vconf_str(const char * key, const char * value)
1056 DBG("[%s: %s]", key, value);
1058 ret = vconf_set_str(key, value);
1059 if (ret != VCONF_OK)
1060 ERR("Failed to set");
1063 int netconfig_vconf_get_int(const char * key, int *value)
1067 ret = vconf_get_int(key, value);
1068 if (ret != VCONF_OK) {
1069 ERR("Failed to get vconfkey [%s] value", key);
1076 int netconfig_vconf_get_bool(const char * key, int *value)
1080 ret = vconf_get_bool(key, value);
1081 if (ret != VCONF_OK) {
1082 ERR("Failed to get vconfkey [%s] value", key);
1089 char* netconfig_get_env(const char *key)
1092 char buf[256], *entry = NULL, *value = NULL, *last;
1098 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
1102 while (fgets(buf, sizeof(buf), fp)) {
1104 entry = strtok_r(entry, "=", &last);
1106 if (strstr(entry, key)) {
1107 entry = strtok_r(NULL, "\n", &last);
1109 len = strlen(entry);
1110 value = (char*)malloc(len+1);
1111 g_strlcpy(value, entry, len+1);
1113 value = (char*)malloc(sizeof(char));
1114 g_strlcpy(value, "\n", sizeof(char));
1125 void netconfig_set_mac_address_from_file(void)
1128 char mac_str[MAC_ADDRESS_MAX_LEN];
1129 gchar *mac_lower_str = NULL;
1132 file = fopen(MAC_INFO_FILEPATH, "r");
1134 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1135 file = fopen(MAC_ADDRESS_FILEPATH, "r");
1137 ERR("Fail to open %s", MAC_ADDRESS_FILEPATH);
1141 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
1142 ERR("Fail to read mac address");
1147 mac_len = strlen(mac_str);
1149 ERR("mac.info is empty");
1154 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1155 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1157 g_free(mac_lower_str);
1161 tizen_profile_t _get_tizen_profile()
1163 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
1164 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
1168 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
1169 switch (*profileName) {
1172 profile = TIZEN_PROFILE_MOBILE;
1176 profile = TIZEN_PROFILE_WEARABLE;
1180 profile = TIZEN_PROFILE_TV;
1184 profile = TIZEN_PROFILE_IVI;
1186 default: // common or unknown ==> ALL ARE COMMON.
1187 profile = TIZEN_PROFILE_COMMON;
1194 void netconfig_plugin_init()
1196 handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
1197 if (!handle_headed) {
1198 ERR("Can't load %s: %s", HEADED_PLUGIN_FILEPATH, dlerror());
1200 headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin");
1201 if (!headed_plugin) {
1202 ERR("Can't load symbol: %s", dlerror());
1203 dlclose(handle_headed);
1205 netconfig_plugin_headed_enabled = TRUE;
1209 handle_telephony = dlopen(TELEPHONY_PLUGIN_FILEPATH, RTLD_NOW);
1210 if (!handle_telephony) {
1211 ERR("Can't load %s: %s", TELEPHONY_PLUGIN_FILEPATH, dlerror());
1213 telephony_plugin = dlsym(handle_telephony, "netconfig_telephony_plugin");
1214 if (!telephony_plugin) {
1215 ERR("Can't load symbol: %s", dlerror());
1216 dlclose(handle_telephony);
1218 netconfig_plugin_telephony_enabled = TRUE;
1223 void netconfig_plugin_deinit()
1225 if (netconfig_plugin_headed_enabled) {
1226 netconfig_plugin_headed_enabled = FALSE;
1227 dlclose(handle_headed);
1230 if (netconfig_plugin_telephony_enabled) {
1231 netconfig_plugin_telephony_enabled = FALSE;
1232 dlclose(handle_telephony);
1236 gboolean netconfig_get_headed_plugin_flag()
1238 return netconfig_plugin_headed_enabled;
1241 gboolean netconfig_get_telephony_plugin_flag()
1243 return netconfig_plugin_telephony_enabled;