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>
34 #include <vconf-keys.h>
35 #include <tzplatform_config.h>
36 #include <system_info.h>
41 #include "wifi-state.h"
44 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
45 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
46 #define MAC_INFO_FILEPATH tzplatform_mkpath(TZ_SYS_ETC, "/.mac.info")
47 #define MAC_ADDRESS_FILEPATH "/sys/class/net/wlan0/address"
48 #define MAC_ADDRESS_MAX_LEN 18
49 #define HEADED_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-headed.so"
50 #define TELEPHONY_PLUGIN_FILEPATH "/usr/lib/net-config-plugin-telephony.so"
52 static gboolean netconfig_device_picker_test = FALSE;
53 static int mdnsd_ref_count = 0;
57 } dnssd_conn_destroy_data;
59 static gboolean netconfig_plugin_headed_enabled = FALSE;
60 static gboolean netconfig_plugin_telephony_enabled = FALSE;
61 static void *handle_headed;
62 static void *handle_telephony;
63 static struct netconfig_headed_plugin_t *headed_plugin;
64 static struct netconfig_telephony_plugin_t *telephony_plugin;
66 gboolean netconfig_check_passphrase(const gchar *service, const char *passphrase)
73 length = strlen(passphrase);
75 if (g_str_has_suffix(service, "psk") == TRUE) {
77 for (int i = 0; i < 64; i++)
78 if (!isxdigit((unsigned char)passphrase[i]))
80 } else if (length < 8 || length > 63)
82 } else if (g_str_has_suffix(service, "wep") == TRUE) {
83 if (length == 10 || length == 26) {
84 for (int i = 0; i < length; i++)
85 if (!isxdigit((unsigned char)passphrase[i]))
87 } else if (length != 5 && length != 13)
94 GKeyFile *netconfig_keyfile_load(const char *pathname)
96 GKeyFile *keyfile = NULL;
99 keyfile = g_key_file_new();
100 if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
101 DBG("Unable to open %s, error %s", pathname, error->message);
104 g_key_file_free(keyfile);
108 DBG("loaded keyfile %s", pathname);
112 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
115 GError *error = NULL;
116 gchar *keydata = NULL;
117 gchar *needle = NULL, *directory = NULL;
119 directory = g_strdup(pathname);
120 needle = g_strrstr(directory, "/");
125 if (directory == NULL || (*directory) == '\0') {
127 ERR("directory is NULL");
131 if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) {
132 if (g_mkdir_with_parents(directory,
133 S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
135 ERR("failed to make directory");
141 keydata = g_key_file_to_data(keyfile, &size, &error);
142 if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
143 ERR("Unable to save %s, error %s", pathname, error->message);
147 chmod(pathname, S_IRUSR | S_IWUSR);
148 DBG("Successfully saved keyfile %s", pathname);
153 void netconfig_start_timer_seconds(guint secs,
154 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
158 if (callback == NULL) {
159 ERR("callback function is NULL");
163 if ((timer_id != NULL && *timer_id != 0)) {
164 ERR("timer already is registered");
168 t_id = g_timeout_add_seconds(secs, callback, user_data);
171 ERR("Can't add timer");
175 if (timer_id != NULL)
179 void netconfig_start_timer(guint msecs,
180 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
184 INFO("Register timer with callback pointer (%p)", callback);
186 if (callback == NULL) {
187 ERR("callback function is NULL");
191 if ((timer_id != NULL && *timer_id != 0)) {
192 ERR("timer already is registered");
196 t_id = g_timeout_add(msecs, callback, user_data);
199 ERR("Can't add timer");
203 if (timer_id != NULL)
207 void netconfig_stop_timer(guint *timer_id)
209 if (timer_id == NULL) {
210 ERR("timer is NULL");
214 if (*timer_id != 0) {
215 g_source_remove(*timer_id);
220 static gboolean __netconfig_test_device_picker()
222 char *favorite_wifi_service = NULL;
224 favorite_wifi_service = wifi_get_favorite_service();
225 if (favorite_wifi_service != NULL) {
226 ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service);
227 g_free(favorite_wifi_service);
234 static void __netconfig_pop_device_picker(void)
236 if (!netconfig_plugin_headed_enabled)
242 headed_plugin->pop_device_picker();
245 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
247 if (__netconfig_test_device_picker() == TRUE)
248 __netconfig_pop_device_picker();
253 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id)
255 static guint netconfig_wifi_device_picker_service_timer = 0;
257 if (is_set_method != TRUE)
258 return netconfig_wifi_device_picker_service_timer;
260 if (netconfig_wifi_device_picker_service_timer != timer_id)
261 netconfig_wifi_device_picker_service_timer = timer_id;
263 return netconfig_wifi_device_picker_service_timer;
266 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
268 __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
271 static guint __netconfig_wifi_device_picker_get_timer_id(void)
273 return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
276 void netconfig_wifi_enable_device_picker_test(void)
278 netconfig_device_picker_test = TRUE;
281 void netconfig_wifi_device_picker_service_start(void)
283 const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
286 if (netconfig_device_picker_test == TRUE)
287 netconfig_device_picker_test = FALSE;
293 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
294 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
297 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
298 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
300 __netconfig_wifi_device_picker_set_timer_id(timer_id);
303 void netconfig_wifi_device_picker_service_stop(void)
307 timer_id = __netconfig_wifi_device_picker_get_timer_id();
311 DBG("Clear device picker timer with timer_id %d", timer_id);
313 netconfig_stop_timer(&timer_id);
315 __netconfig_wifi_device_picker_set_timer_id(timer_id);
318 gboolean netconfig_is_wifi_direct_on(void)
320 #if defined TIZEN_P2P_ENABLE
321 int wifi_direct_state = 0;
323 netconfig_vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
325 DBG("Wi-Fi direct mode %d", wifi_direct_state);
326 return (wifi_direct_state != 0) ? TRUE : FALSE;
332 gboolean netconfig_is_wifi_tethering_on(void)
334 #if defined TIZEN_TETHERING_ENABLE
335 int wifi_tethering_state = 0;
337 netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
338 DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
339 if ((wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
340 || (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP)) {
341 DBG("Mobile AP is on");
345 DBG("Mobile AP is off");
349 gboolean netconfig_interface_up(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 |= (IFF_UP | IFF_DYNAMIC);
367 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
374 DBG("Successfully activated wireless interface %s", ifname);
378 gboolean netconfig_interface_down(const char *ifname)
383 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
387 memset(&ifr, 0, sizeof(ifr));
388 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
390 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
395 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
396 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
403 DBG("Successfully de-activated wireless interface %s", ifname);
407 int netconfig_execute_file(const char *file_path,
408 char *const args[], char *const envs[])
414 register unsigned int index = 0;
415 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
417 while (args[index] != NULL) {
418 DBG("%s", args[index]);
422 if (!(pid = fork())) {
423 DBG("pid(%d), ppid (%d)", getpid(), getppid());
424 DBG("Inside child, exec (%s) command", file_path);
427 if (execve(file_path, args, envs) == -1) {
428 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
429 DBG("Fail to execute command (%s)", error_buf);
432 } else if (pid > 0) {
433 if (waitpid(pid, &status, 0) == -1)
434 DBG("wait pid (%u) status (%d)", pid, status);
436 if (WIFEXITED(status)) {
437 rv = WEXITSTATUS(status);
438 DBG("exited, status=%d", rv);
439 } else if (WIFSIGNALED(status)) {
440 DBG("killed by signal %d", WTERMSIG(status));
441 } else if (WIFSTOPPED(status)) {
442 DBG("stopped by signal %d", WSTOPSIG(status));
443 } else if (WIFCONTINUED(status)) {
450 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
451 DBG("failed to fork(%s)", error_buf);
455 int netconfig_execute_cmd(const char *cmd)
464 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
467 DBG("command: %s", cmd);
469 args = g_strsplit_set(cmd, " ", -1);
471 if (!(pid = fork())) {
472 DBG("pid(%d), ppid (%d)", getpid(), getppid());
475 if (execv(args[0], args) == -1) {
476 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
477 DBG("Fail to execute command (%s)", error_buf);
481 } else if (pid > 0) {
482 if (waitpid(pid, &status, 0) == -1)
483 DBG("wait pid (%u) status (%d)", pid, status);
485 if (WIFEXITED(status)) {
486 rv = WEXITSTATUS(status);
487 DBG("exited, status=%d", rv);
488 } else if (WIFSIGNALED(status)) {
489 DBG("killed by signal %d", WTERMSIG(status));
490 } else if (WIFSTOPPED(status)) {
491 DBG("stopped by signal %d", WSTOPSIG(status));
492 } else if (WIFCONTINUED(status)) {
500 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
501 DBG("failed to fork(%s)", error_buf);
507 static void on_clat_handler()
512 clat_pid = waitpid(-1, &state, WNOHANG);
514 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
517 int netconfig_execute_clatd(const char *file_path, char *const args[])
522 register unsigned int index = 0;
523 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
525 struct sigaction act;
528 act.sa_handler = on_clat_handler;
529 sigemptyset(&act.sa_mask);
532 state = sigaction(SIGCHLD, &act, 0);
534 DBG("sigaction() : %d");
538 while (args[index] != NULL) {
539 DBG("%s", args[index]);
543 if (!(pid = fork())) {
544 DBG("pid(%d), ppid (%d)", getpid(), getppid());
545 DBG("Inside child, exec (%s) command", file_path);
548 if (execvp(file_path, args) == -1) {
549 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
550 ERR("Fail to execute command (%s)", error_buf);
553 } else if (pid > 0) {
554 ERR("Success to launch clatd");
558 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
559 DBG("failed to fork(%s)", error_buf);
563 static void no_wait_signal_handler()
568 child_pid = waitpid(-1, &state, WNOHANG);
570 DBG("child_id(%d) state(%d)", child_pid, WEXITSTATUS(state));
573 int netconfig_execute_file_no_wait(const char *file_path, char *const args[])
578 register unsigned int index = 0;
580 struct sigaction act;
583 act.sa_handler = no_wait_signal_handler;
584 sigemptyset(&act.sa_mask);
587 state = sigaction(SIGCHLD, &act, 0);
589 DBG("sigaction() : %d");
593 while (args[index] != NULL) {
594 DBG("%s", args[index]);
598 if (!(pid = fork())) {
599 DBG("pid(%d), ppid (%d)", getpid(), getppid());
600 DBG("Inside child, exec (%s) command", file_path);
603 if (execvp(file_path, args) == -1) {
604 ERR("Fail to execute command (%s)", strerror(errno));
607 } else if (pid > 0) {
608 ERR("Successfully launched child process");
612 DBG("failed to fork(%s)", strerror(errno));
616 int __netconfig_get_interface_index(const char *interface_name)
621 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
623 if (interface_name == NULL) {
624 DBG("Inteface name is NULL");
629 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
631 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
632 DBG("Failed to create socket : %s", error_buf);
636 memset(&ifr, 0, sizeof(ifr));
637 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
638 result = ioctl(sock, SIOCGIFINDEX, &ifr);
642 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
643 DBG("Failed to get ifr index: %s", error_buf);
647 return ifr.ifr_ifindex;
650 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
654 struct sockaddr_in addr_in;
656 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
658 memset(&ifr, 0, sizeof(ifr));
660 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
662 if (ifr.ifr_ifindex < 0)
665 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
667 memset(&rt, 0, sizeof(rt));
669 rt.rt_flags = RTF_UP | RTF_HOST;
670 memset(&addr_in, 0, sizeof(struct sockaddr_in));
671 addr_in.sin_family = address_family;
672 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
673 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
675 memset(&addr_in, 0, sizeof(struct sockaddr_in));
676 addr_in.sin_family = address_family;
677 addr_in.sin_addr.s_addr = INADDR_ANY;
678 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
680 memset(&addr_in, 0, sizeof(struct sockaddr_in));
681 addr_in.sin_family = AF_INET;
682 addr_in.sin_addr.s_addr = inet_addr(subnet);
683 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
685 rt.rt_dev = ifr.ifr_name;
688 sock = socket(PF_INET, SOCK_DGRAM, 0);
691 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
692 DBG("Failed to create socket : %s", error_buf);
696 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
697 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
698 DBG("Failed to set route address : %s", error_buf);
708 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
712 struct sockaddr_in addr_in;
714 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
716 memset(&ifr, 0, sizeof(ifr));
717 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
719 if (ifr.ifr_ifindex < 0)
722 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
724 memset(&rt, 0, sizeof(rt));
726 rt.rt_flags = RTF_UP;
727 memset(&addr_in, 0, sizeof(struct sockaddr_in));
728 addr_in.sin_family = address_family;
729 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
730 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
732 memset(&addr_in, 0, sizeof(struct sockaddr_in));
733 addr_in.sin_family = address_family;
734 addr_in.sin_addr.s_addr = inet_addr(subnet);
735 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
736 rt.rt_dev = ifr.ifr_name;
739 sock = socket(PF_INET, SOCK_DGRAM, 0);
742 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
743 DBG("Failed to create socket : %s", error_buf);
747 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
748 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
749 DBG("Failed to set route address : %s", error_buf);
759 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
764 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
766 memset(&rt, 0, sizeof(rt));
768 rt.rtmsg_dst_len = prefix_len;
770 rt.rtmsg_flags = RTF_UP | RTF_HOST;
773 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
774 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
775 DBG("inet_pton failed : %s", error_buf);
779 if (gateway != NULL) {
780 rt.rtmsg_flags |= RTF_GATEWAY;
781 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
782 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
783 DBG("inet_pton failed : %s", error_buf);
790 fd = socket(AF_INET6, SOCK_DGRAM, 0);
792 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
793 DBG("Failed to create socket : %s", error_buf);
797 rt.rtmsg_ifindex = 0;
801 memset(&ifr, 0, sizeof(ifr));
802 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
803 ioctl(fd, SIOCGIFINDEX, &ifr);
804 rt.rtmsg_ifindex = ifr.ifr_ifindex;
807 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
808 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
809 DBG("Failed to add route: %s", error_buf);
819 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
825 memset(&rt, 0, sizeof(rt));
827 rt.rtmsg_dst_len = prefix_len;
829 rt.rtmsg_flags = RTF_UP | RTF_HOST;
831 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
836 if (gateway != NULL) {
837 rt.rtmsg_flags |= RTF_GATEWAY;
838 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
846 fd = socket(AF_INET6, SOCK_DGRAM, 0);
850 rt.rtmsg_ifindex = 0;
854 memset(&ifr, 0, sizeof(ifr));
855 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
856 ioctl(fd, SIOCGIFINDEX, &ifr);
857 rt.rtmsg_ifindex = ifr.ifr_ifindex;
860 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
861 DBG("Failed to del route: %d\n", err);
871 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
873 #if defined TIZEN_P2P_ENABLE
875 DBG("Launch Wi-Fi direct daemon");
877 const char *path = "/usr/bin/wifi-direct-server.sh";
878 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
879 char *const envs[] = { NULL };
881 ret = netconfig_execute_file(path, args, envs);
883 ERR("Failed to launch Wi-Fi direct daemon");
884 netconfig_error_wifi_direct_failed(context);
888 wifi_complete_launch_direct(wifi, context);
891 wifi_complete_launch_direct(wifi, context);
896 int execute_mdnsd_script(char* op)
898 const char *path = "/usr/bin/mdnsresponder-server.sh";
899 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
900 char *const envs[] = { NULL };
902 return netconfig_execute_file(path, args, envs);
905 static void __dnssd_conn_destroyed_cb(GDBusConnection *conn,
906 const gchar *Name, const gchar *path, const gchar *interface,
907 const gchar *sig, GVariant *param, gpointer user_data)
912 dnssd_conn_destroy_data *data = user_data;
913 GDBusConnection *connection = NULL;
914 connection = netdbus_get_connection();
919 g_variant_get(param, "(sss)", &name, &old, &new);
921 if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
922 DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name,
925 g_dbus_connection_signal_unsubscribe(connection, data->conn_id);
926 if (mdnsd_ref_count == 0) {
927 if (execute_mdnsd_script("stop") < 0)
928 ERR("Failed to stop mdnsresponder daemon");
934 g_free(data->conn_name);
939 static void register_dnssd_conn_destroy_signal(gchar *name)
941 dnssd_conn_destroy_data *data;
942 GDBusConnection *connection = NULL;
943 connection = netdbus_get_connection();
945 if (connection == NULL) {
946 ERR("Failed to get GDbus Connection");
950 data = g_try_malloc0(sizeof(dnssd_conn_destroy_data));
953 ERR("Out of Memory!");
957 data->conn_name = g_strdup(name);
959 data->conn_id = g_dbus_connection_signal_subscribe(connection,
960 DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
961 "NameOwnerChanged", NULL, name,
962 G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb,
967 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context,
970 DBG("Launch mdnsresponder daemon");
972 if (execute_mdnsd_script("start") < 0) {
973 ERR("Failed to launch mdnsresponder daemon");
974 netconfig_error_invalid_parameter(context);
979 register_dnssd_conn_destroy_signal(name);
980 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
982 network_complete_launch_mdns(object, context);
986 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
988 if (!netconfig_plugin_headed_enabled)
994 return headed_plugin->send_notification_to_net_popup(noti, ssid);
997 int netconfig_send_message_to_net_popup(const char *title,
998 const char *content, const char *type, const char *ssid)
1000 if (!netconfig_plugin_headed_enabled)
1006 return headed_plugin->send_message_to_net_popup(title, content, type, ssid);
1009 int netconfig_send_restriction_to_net_popup(const char *title,
1010 const char *type, const char *restriction)
1012 if (!netconfig_plugin_headed_enabled)
1018 return headed_plugin->send_restriction_to_net_popup(title, type, restriction);
1021 void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val)
1023 if (!netconfig_plugin_headed_enabled)
1029 headed_plugin->set_system_event(sys_evt, evt_key, evt_val);
1032 void __netconfig_pop_wifi_connected_poppup(const char *ssid)
1034 if (!netconfig_plugin_headed_enabled)
1040 headed_plugin->pop_wifi_connected_poppup(ssid);
1043 void netconfig_get_telephony_network_type(int *svctype, int *pstype)
1045 if (!netconfig_plugin_telephony_enabled)
1048 if (!telephony_plugin)
1051 telephony_plugin->get_telephony_network_type(svctype, pstype);
1054 gboolean __netconfig_wifi_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context)
1056 if (!netconfig_plugin_telephony_enabled)
1059 if (!telephony_plugin)
1062 return telephony_plugin->wifi_get_sim_imsi(wifi, context);
1065 netconfig_error_e __netconfig_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data,
1066 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1068 if (!netconfig_plugin_telephony_enabled)
1069 return NETCONFIG_ERROR_INTERNAL;
1071 if (!telephony_plugin)
1072 return NETCONFIG_ERROR_INTERNAL;
1074 return telephony_plugin->wifi_req_aka_auth(rand_data, autn_data, context, data);
1077 gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data,
1078 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1080 if (!netconfig_plugin_telephony_enabled)
1083 if (!telephony_plugin)
1086 return telephony_plugin->wifi_req_sim_auth(rand_data, context, data);
1089 gboolean netconfig_tapi_check_sim_state(void)
1091 if (!netconfig_plugin_telephony_enabled)
1094 if (!telephony_plugin)
1097 return telephony_plugin->tapi_check_sim_state();
1100 gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi,
1101 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1103 if (!netconfig_plugin_telephony_enabled)
1106 if (!telephony_plugin)
1109 return telephony_plugin->wifi_get_aka_authdata(wifi, context, data);
1112 gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi,
1113 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1115 if (!netconfig_plugin_telephony_enabled)
1118 if (!telephony_plugin)
1121 return telephony_plugin->wifi_get_sim_authdata(wifi, context, data);
1124 void netconfig_set_vconf_int(const char * key, int value)
1128 DBG("[%s: %d]", key, value);
1130 ret = vconf_set_int(key, value);
1131 if (ret != VCONF_OK)
1132 ERR("Failed to set");
1135 void netconfig_set_vconf_str(const char * key, const char * value)
1139 DBG("[%s: %s]", key, value);
1141 ret = vconf_set_str(key, value);
1142 if (ret != VCONF_OK)
1143 ERR("Failed to set");
1146 int netconfig_vconf_get_int(const char * key, int *value)
1150 ret = vconf_get_int(key, value);
1151 if (ret != VCONF_OK) {
1152 ERR("Failed to get vconfkey [%s] value", key);
1159 int netconfig_vconf_get_bool(const char * key, int *value)
1163 ret = vconf_get_bool(key, value);
1164 if (ret != VCONF_OK) {
1165 ERR("Failed to get vconfkey [%s] value", key);
1172 char* netconfig_get_env(const char *key)
1175 char buf[256], *entry = NULL, *value = NULL, *last;
1181 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
1185 while (fgets(buf, sizeof(buf), fp)) {
1187 entry = strtok_r(entry, "=", &last);
1189 if (strstr(entry, key)) {
1190 entry = strtok_r(NULL, "\n", &last);
1192 len = strlen(entry);
1193 value = (char*)malloc(len+1);
1194 g_strlcpy(value, entry, len+1);
1196 value = (char*)malloc(sizeof(char));
1197 g_strlcpy(value, "\n", sizeof(char));
1208 void netconfig_set_mac_address_from_file(void)
1211 char mac_str[MAC_ADDRESS_MAX_LEN];
1212 gchar *mac_lower_str = NULL;
1215 file = fopen(MAC_INFO_FILEPATH, "r");
1217 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1218 file = fopen(MAC_ADDRESS_FILEPATH, "r");
1220 ERR("Fail to open %s", MAC_ADDRESS_FILEPATH);
1224 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
1225 ERR("Fail to read mac address");
1230 mac_len = strlen(mac_str);
1232 ERR("mac.info is empty");
1237 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1238 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1240 g_free(mac_lower_str);
1244 tizen_profile_t _get_tizen_profile()
1246 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
1247 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
1251 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
1252 switch (*profileName) {
1255 profile = TIZEN_PROFILE_MOBILE;
1259 profile = TIZEN_PROFILE_WEARABLE;
1263 profile = TIZEN_PROFILE_TV;
1267 profile = TIZEN_PROFILE_IVI;
1269 default: // common or unknown ==> ALL ARE COMMON.
1270 profile = TIZEN_PROFILE_COMMON;
1277 void netconfig_plugin_init()
1279 handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
1280 if (!handle_headed) {
1281 ERR("Can't load %s: %s", HEADED_PLUGIN_FILEPATH, dlerror());
1283 headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin");
1284 if (!headed_plugin) {
1285 ERR("Can't load symbol: %s", dlerror());
1286 dlclose(handle_headed);
1288 netconfig_plugin_headed_enabled = TRUE;
1292 handle_telephony = dlopen(TELEPHONY_PLUGIN_FILEPATH, RTLD_NOW);
1293 if (!handle_telephony) {
1294 ERR("Can't load %s: %s", TELEPHONY_PLUGIN_FILEPATH, dlerror());
1296 telephony_plugin = dlsym(handle_telephony, "netconfig_telephony_plugin");
1297 if (!telephony_plugin) {
1298 ERR("Can't load symbol: %s", dlerror());
1299 dlclose(handle_telephony);
1301 netconfig_plugin_telephony_enabled = TRUE;
1306 void netconfig_plugin_deinit()
1308 if (netconfig_plugin_headed_enabled) {
1309 netconfig_plugin_headed_enabled = FALSE;
1310 dlclose(handle_headed);
1313 if (netconfig_plugin_telephony_enabled) {
1314 netconfig_plugin_telephony_enabled = FALSE;
1315 dlclose(handle_telephony);
1319 gboolean netconfig_get_headed_plugin_flag()
1321 return netconfig_plugin_headed_enabled;
1324 gboolean netconfig_get_telephony_plugin_flag()
1326 return netconfig_plugin_telephony_enabled;