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 static bool is_feature_checked[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, };
67 static bool feature_supported[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, };
69 gboolean netconfig_check_passphrase(const gchar *service, const char *passphrase)
76 length = strlen(passphrase);
78 if (g_str_has_suffix(service, "psk") == TRUE) {
80 for (int i = 0; i < 64; i++)
81 if (!isxdigit((unsigned char)passphrase[i]))
83 } else if (length < 8 || length > 63)
85 } else if (g_str_has_suffix(service, "wep") == TRUE) {
86 if (length == 10 || length == 26) {
87 for (int i = 0; i < length; i++)
88 if (!isxdigit((unsigned char)passphrase[i]))
90 } else if (length != 5 && length != 13)
97 GKeyFile *netconfig_keyfile_load(const char *pathname)
99 GKeyFile *keyfile = NULL;
100 GError *error = NULL;
102 keyfile = g_key_file_new();
103 if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
104 DBG("Unable to open %s, error %s", pathname, error->message);
107 g_key_file_free(keyfile);
111 DBG("loaded keyfile %s", pathname);
115 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
118 GError *error = NULL;
119 gchar *keydata = NULL;
120 gchar *needle = NULL, *directory = NULL;
122 directory = g_strdup(pathname);
123 needle = g_strrstr(directory, "/");
128 if (directory == NULL || (*directory) == '\0') {
130 ERR("directory is NULL");
134 if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) {
135 if (g_mkdir_with_parents(directory,
136 S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
138 ERR("failed to make directory");
144 keydata = g_key_file_to_data(keyfile, &size, &error);
145 if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
146 ERR("Unable to save %s, error %s", pathname, error->message);
150 if (chmod(pathname, S_IRUSR | S_IWUSR) < 0)
151 DBG("Failed to change mode");
153 DBG("Successfully saved keyfile %s", pathname);
158 void netconfig_start_timer_seconds(guint secs,
159 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
163 if (callback == NULL) {
164 ERR("callback function is NULL");
168 if ((timer_id != NULL && *timer_id != 0)) {
169 ERR("timer already is registered");
173 t_id = g_timeout_add_seconds(secs, callback, user_data);
176 ERR("Can't add timer");
180 if (timer_id != NULL)
184 void netconfig_start_timer(guint msecs,
185 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
189 INFO("Register timer with callback pointer (%p)", callback);
191 if (callback == NULL) {
192 ERR("callback function is NULL");
196 if ((timer_id != NULL && *timer_id != 0)) {
197 ERR("timer already is registered");
201 t_id = g_timeout_add(msecs, callback, user_data);
204 ERR("Can't add timer");
208 if (timer_id != NULL)
212 void netconfig_stop_timer(guint *timer_id)
214 if (timer_id == NULL) {
215 ERR("timer is NULL");
219 if (*timer_id != 0) {
220 g_source_remove(*timer_id);
225 static gboolean __netconfig_test_device_picker()
227 char *favorite_wifi_service = NULL;
229 favorite_wifi_service = wifi_get_favorite_service();
230 if (favorite_wifi_service != NULL) {
231 ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service);
232 g_free(favorite_wifi_service);
239 static void __netconfig_pop_device_picker(void)
241 if (!netconfig_plugin_headed_enabled)
247 headed_plugin->pop_device_picker();
250 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
252 if (__netconfig_test_device_picker() == TRUE)
253 __netconfig_pop_device_picker();
258 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id)
260 static guint netconfig_wifi_device_picker_service_timer = 0;
262 if (is_set_method != TRUE)
263 return netconfig_wifi_device_picker_service_timer;
265 if (netconfig_wifi_device_picker_service_timer != timer_id)
266 netconfig_wifi_device_picker_service_timer = timer_id;
268 return netconfig_wifi_device_picker_service_timer;
271 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
273 __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
276 static guint __netconfig_wifi_device_picker_get_timer_id(void)
278 return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
281 void netconfig_wifi_enable_device_picker_test(void)
283 netconfig_device_picker_test = TRUE;
286 void netconfig_wifi_device_picker_service_start(void)
288 const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
291 if (netconfig_device_picker_test == TRUE)
292 netconfig_device_picker_test = FALSE;
298 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
299 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
302 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
303 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
305 __netconfig_wifi_device_picker_set_timer_id(timer_id);
308 void netconfig_wifi_device_picker_service_stop(void)
312 timer_id = __netconfig_wifi_device_picker_get_timer_id();
316 DBG("Clear device picker timer with timer_id %d", timer_id);
318 netconfig_stop_timer(&timer_id);
320 __netconfig_wifi_device_picker_set_timer_id(timer_id);
323 gboolean netconfig_is_wifi_direct_on(void)
325 if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
328 int wifi_direct_state = 0;
330 netconfig_vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
332 DBG("Wi-Fi direct mode %d", wifi_direct_state);
333 return (wifi_direct_state != 0) ? TRUE : FALSE;
336 gboolean netconfig_is_wifi_tethering_on(void)
338 if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING)) {
339 int wifi_tethering_state = 0;
341 netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
342 DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
343 if ((wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
344 || (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP)) {
345 DBG("Mobile AP is on");
350 DBG("Mobile AP is off");
354 gboolean netconfig_interface_up(const char *ifname)
359 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
363 memset(&ifr, 0, sizeof(ifr));
364 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
366 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
371 ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
372 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
379 DBG("Successfully activated wireless interface %s", ifname);
383 gboolean netconfig_interface_down(const char *ifname)
388 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
392 memset(&ifr, 0, sizeof(ifr));
393 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
395 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
400 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
401 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
408 DBG("Successfully de-activated wireless interface %s", ifname);
412 int netconfig_execute_file(const char *file_path,
413 char *const args[], char *const envs[])
419 register unsigned int index = 0;
420 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
422 while (args[index] != NULL) {
423 DBG("%s", args[index]);
427 if (!(pid = fork())) {
428 DBG("pid(%d), ppid (%d)", getpid(), getppid());
429 DBG("Inside child, exec (%s) command", file_path);
432 if (execve(file_path, args, envs) == -1) {
433 DBG("Fail to execute command (%s)",
434 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
437 } else if (pid > 0) {
438 if (waitpid(pid, &status, 0) == -1)
439 DBG("wait pid (%u) status (%d)", pid, status);
441 if (WIFEXITED(status)) {
442 rv = WEXITSTATUS(status);
443 DBG("exited, status=%d", rv);
444 } else if (WIFSIGNALED(status)) {
445 DBG("killed by signal %d", WTERMSIG(status));
446 } else if (WIFSTOPPED(status)) {
447 DBG("stopped by signal %d", WSTOPSIG(status));
448 } else if (WIFCONTINUED(status)) {
455 DBG("failed to fork(%s)",
456 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
460 int netconfig_execute_cmd(const char *cmd)
469 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
472 DBG("command: %s", cmd);
474 args = g_strsplit_set(cmd, " ", -1);
476 if (!(pid = fork())) {
477 DBG("pid(%d), ppid (%d)", getpid(), getppid());
480 if (execv(args[0], args) == -1) {
481 DBG("Fail to execute command (%s)",
482 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
486 } else if (pid > 0) {
487 if (waitpid(pid, &status, 0) == -1)
488 DBG("wait pid (%u) status (%d)", pid, status);
490 if (WIFEXITED(status)) {
491 rv = WEXITSTATUS(status);
492 DBG("exited, status=%d", rv);
493 } else if (WIFSIGNALED(status)) {
494 DBG("killed by signal %d", WTERMSIG(status));
495 } else if (WIFSTOPPED(status)) {
496 DBG("stopped by signal %d", WSTOPSIG(status));
497 } else if (WIFCONTINUED(status)) {
505 DBG("failed to fork(%s)",
506 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
512 static void on_clat_handler()
517 clat_pid = waitpid(-1, &state, WNOHANG);
519 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
522 int netconfig_execute_clatd(const char *file_path, char *const args[])
527 register unsigned int index = 0;
528 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
530 struct sigaction act;
533 act.sa_handler = on_clat_handler;
534 sigemptyset(&act.sa_mask);
537 state = sigaction(SIGCHLD, &act, 0);
539 DBG("sigaction() : %d", state);
543 while (args[index] != NULL) {
544 DBG("%s", args[index]);
548 if (!(pid = fork())) {
549 DBG("pid(%d), ppid (%d)", getpid(), getppid());
550 DBG("Inside child, exec (%s) command", file_path);
553 if (execvp(file_path, args) == -1) {
554 ERR("Fail to execute command (%s)",
555 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
558 } else if (pid > 0) {
559 ERR("Success to launch clatd");
563 DBG("failed to fork(%s)",
564 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
568 static void no_wait_signal_handler()
573 child_pid = waitpid(-1, &state, WNOHANG);
575 DBG("child_id(%d) state(%d)", child_pid, WEXITSTATUS(state));
578 int netconfig_execute_file_no_wait(const char *file_path, char *const args[])
583 register unsigned int index = 0;
585 struct sigaction act;
587 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
589 act.sa_handler = no_wait_signal_handler;
590 sigemptyset(&act.sa_mask);
593 state = sigaction(SIGCHLD, &act, 0);
595 DBG("sigaction() : %d", state);
599 while (args[index] != NULL) {
600 DBG("%s", args[index]);
604 if (!(pid = fork())) {
605 DBG("pid(%d), ppid (%d)", getpid(), getppid());
606 DBG("Inside child, exec (%s) command", file_path);
609 if (execvp(file_path, args) == -1) {
610 ERR("Fail to execute command (%s)",
611 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
614 } else if (pid > 0) {
615 ERR("Successfully launched child process");
619 DBG("failed to fork(%s)",
620 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
624 int __netconfig_get_interface_index(const char *interface_name)
629 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
631 if (interface_name == NULL) {
632 DBG("Inteface name is NULL");
637 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
639 DBG("Failed to create socket : %s",
640 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
644 memset(&ifr, 0, sizeof(ifr));
645 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
646 result = ioctl(sock, SIOCGIFINDEX, &ifr);
650 DBG("Failed to get ifr index: %s",
651 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
655 return ifr.ifr_ifindex;
658 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
662 struct sockaddr_in addr_in;
664 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
666 memset(&ifr, 0, sizeof(ifr));
668 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
670 if (ifr.ifr_ifindex < 0)
673 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
675 memset(&rt, 0, sizeof(rt));
677 rt.rt_flags = RTF_UP | RTF_HOST;
678 memset(&addr_in, 0, sizeof(struct sockaddr_in));
679 addr_in.sin_family = address_family;
680 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
681 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
683 memset(&addr_in, 0, sizeof(struct sockaddr_in));
684 addr_in.sin_family = address_family;
685 addr_in.sin_addr.s_addr = INADDR_ANY;
686 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
688 memset(&addr_in, 0, sizeof(struct sockaddr_in));
689 addr_in.sin_family = AF_INET;
690 addr_in.sin_addr.s_addr = inet_addr(subnet);
691 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
693 rt.rt_dev = ifr.ifr_name;
696 sock = socket(PF_INET, SOCK_DGRAM, 0);
699 DBG("Failed to create socket : %s",
700 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
704 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
705 DBG("Failed to set route address : %s",
706 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
716 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
720 struct sockaddr_in addr_in;
722 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
724 memset(&ifr, 0, sizeof(ifr));
725 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
727 if (ifr.ifr_ifindex < 0)
730 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
732 memset(&rt, 0, sizeof(rt));
734 rt.rt_flags = RTF_UP;
735 memset(&addr_in, 0, sizeof(struct sockaddr_in));
736 addr_in.sin_family = address_family;
737 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
738 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
740 memset(&addr_in, 0, sizeof(struct sockaddr_in));
741 addr_in.sin_family = address_family;
742 addr_in.sin_addr.s_addr = inet_addr(subnet);
743 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
744 rt.rt_dev = ifr.ifr_name;
747 sock = socket(PF_INET, SOCK_DGRAM, 0);
750 DBG("Failed to create socket : %s",
751 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
755 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
756 DBG("Failed to set route address : %s",
757 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
767 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
772 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
774 memset(&rt, 0, sizeof(rt));
776 rt.rtmsg_dst_len = prefix_len;
778 rt.rtmsg_flags = RTF_UP | RTF_HOST;
781 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
782 DBG("inet_pton failed : %s",
783 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
787 if (gateway != NULL) {
788 rt.rtmsg_flags |= RTF_GATEWAY;
789 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
790 DBG("inet_pton failed : %s",
791 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
798 fd = socket(AF_INET6, SOCK_DGRAM, 0);
800 DBG("Failed to create socket : %s",
801 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
805 rt.rtmsg_ifindex = 0;
809 memset(&ifr, 0, sizeof(ifr));
810 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
811 ioctl(fd, SIOCGIFINDEX, &ifr);
812 rt.rtmsg_ifindex = ifr.ifr_ifindex;
815 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
816 DBG("Failed to add route: %s",
817 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
827 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
833 memset(&rt, 0, sizeof(rt));
835 rt.rtmsg_dst_len = prefix_len;
837 rt.rtmsg_flags = RTF_UP | RTF_HOST;
839 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
844 if (gateway != NULL) {
845 rt.rtmsg_flags |= RTF_GATEWAY;
846 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
854 fd = socket(AF_INET6, SOCK_DGRAM, 0);
858 rt.rtmsg_ifindex = 0;
862 memset(&ifr, 0, sizeof(ifr));
863 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
864 ioctl(fd, SIOCGIFINDEX, &ifr);
865 rt.rtmsg_ifindex = ifr.ifr_ifindex;
868 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
869 DBG("Failed to del route: %d\n", err);
879 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
881 if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT)) {
882 wifi_complete_launch_direct(wifi, context);
887 DBG("Launch Wi-Fi direct daemon");
889 const char *path = "/usr/bin/wifi-direct-server.sh";
890 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
891 char *const envs[] = { NULL };
893 ret = netconfig_execute_file(path, args, envs);
895 ERR("Failed to launch Wi-Fi direct daemon");
896 netconfig_error_wifi_direct_failed(context);
900 wifi_complete_launch_direct(wifi, context);
904 int execute_mdnsd_script(char* op)
906 const char *path = "/usr/bin/mdnsresponder-server.sh";
907 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
908 char *const envs[] = { NULL };
910 return netconfig_execute_file(path, args, envs);
913 static void __dnssd_conn_destroyed_cb(GDBusConnection *conn,
914 const gchar *Name, const gchar *path, const gchar *interface,
915 const gchar *sig, GVariant *param, gpointer user_data)
920 dnssd_conn_destroy_data *data = user_data;
921 GDBusConnection *connection = NULL;
922 connection = netdbus_get_connection();
927 g_variant_get(param, "(sss)", &name, &old, &new);
929 if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
930 DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name,
933 g_dbus_connection_signal_unsubscribe(connection, data->conn_id);
934 if (mdnsd_ref_count == 0) {
935 if (execute_mdnsd_script("stop") < 0)
936 ERR("Failed to stop mdnsresponder daemon");
942 g_free(data->conn_name);
947 static void register_dnssd_conn_destroy_signal(gchar *name)
949 dnssd_conn_destroy_data *data;
950 GDBusConnection *connection = NULL;
951 connection = netdbus_get_connection();
953 if (connection == NULL) {
954 ERR("Failed to get GDbus Connection");
958 data = g_try_malloc0(sizeof(dnssd_conn_destroy_data));
961 ERR("Out of Memory!");
965 data->conn_name = g_strdup(name);
967 data->conn_id = g_dbus_connection_signal_subscribe(connection,
968 DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
969 "NameOwnerChanged", NULL, name,
970 G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb,
975 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context,
978 DBG("Launch mdnsresponder daemon");
980 if (execute_mdnsd_script("start") < 0) {
981 ERR("Failed to launch mdnsresponder daemon");
982 netconfig_error_invalid_parameter(context);
987 register_dnssd_conn_destroy_signal(name);
988 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
990 network_complete_launch_mdns(object, context);
994 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
996 if (!netconfig_plugin_headed_enabled)
1002 return headed_plugin->send_notification_to_net_popup(noti, ssid);
1005 int netconfig_send_message_to_net_popup(const char *title,
1006 const char *content, const char *type, const char *ssid)
1008 if (!netconfig_plugin_headed_enabled)
1014 return headed_plugin->send_message_to_net_popup(title, content, type, ssid);
1017 int netconfig_send_restriction_to_net_popup(const char *title,
1018 const char *type, const char *restriction)
1020 if (!netconfig_plugin_headed_enabled)
1026 return headed_plugin->send_restriction_to_net_popup(title, type, restriction);
1029 void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val)
1031 if (!netconfig_plugin_headed_enabled)
1037 headed_plugin->set_system_event(sys_evt, evt_key, evt_val);
1040 void __netconfig_pop_wifi_connected_poppup(const char *ssid)
1042 if (!netconfig_plugin_headed_enabled)
1048 headed_plugin->pop_wifi_connected_poppup(ssid);
1051 void netconfig_get_telephony_network_type(int *svctype, int *pstype)
1053 if (!netconfig_plugin_telephony_enabled)
1056 if (!telephony_plugin)
1059 telephony_plugin->get_telephony_network_type(svctype, pstype);
1062 gboolean __netconfig_wifi_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context)
1064 if (!netconfig_plugin_telephony_enabled)
1067 if (!telephony_plugin)
1070 return telephony_plugin->wifi_get_sim_imsi(wifi, context);
1073 netconfig_error_e __netconfig_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data,
1074 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1076 if (!netconfig_plugin_telephony_enabled)
1077 return NETCONFIG_ERROR_INTERNAL;
1079 if (!telephony_plugin)
1080 return NETCONFIG_ERROR_INTERNAL;
1082 return telephony_plugin->wifi_req_aka_auth(rand_data, autn_data, context, data);
1085 gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data,
1086 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1088 if (!netconfig_plugin_telephony_enabled)
1091 if (!telephony_plugin)
1094 return telephony_plugin->wifi_req_sim_auth(rand_data, context, data);
1097 gboolean netconfig_tapi_check_sim_state(void)
1099 if (!netconfig_plugin_telephony_enabled)
1102 if (!telephony_plugin)
1105 return telephony_plugin->tapi_check_sim_state();
1108 gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi,
1109 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1111 if (!netconfig_plugin_telephony_enabled)
1114 if (!telephony_plugin)
1117 return telephony_plugin->wifi_get_aka_authdata(wifi, context, data);
1120 gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi,
1121 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1123 if (!netconfig_plugin_telephony_enabled)
1126 if (!telephony_plugin)
1129 return telephony_plugin->wifi_get_sim_authdata(wifi, context, data);
1132 void netconfig_set_vconf_int(const char * key, int value)
1136 DBG("[%s: %d]", key, value);
1138 ret = vconf_set_int(key, value);
1139 if (ret != VCONF_OK)
1140 ERR("Failed to set");
1143 void netconfig_set_vconf_str(const char * key, const char * value)
1147 DBG("[%s: %s]", key, value);
1149 ret = vconf_set_str(key, value);
1150 if (ret != VCONF_OK)
1151 ERR("Failed to set");
1154 int netconfig_vconf_get_int(const char * key, int *value)
1158 ret = vconf_get_int(key, value);
1159 if (ret != VCONF_OK) {
1160 ERR("Failed to get vconfkey [%s] value", key);
1167 int netconfig_vconf_get_bool(const char * key, int *value)
1171 ret = vconf_get_bool(key, value);
1172 if (ret != VCONF_OK) {
1173 ERR("Failed to get vconfkey [%s] value", key);
1180 char* netconfig_get_env(const char *key)
1183 char buf[256], *entry = NULL, *value = NULL, *last;
1189 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
1193 while (fgets(buf, sizeof(buf), fp)) {
1195 entry = strtok_r(entry, "=", &last);
1197 if (strstr(entry, key)) {
1198 entry = strtok_r(NULL, "\n", &last);
1200 len = strlen(entry);
1201 value = (char*)malloc(len+1);
1202 g_strlcpy(value, entry, len+1);
1204 value = (char*)malloc(sizeof(char));
1205 g_strlcpy(value, "\n", sizeof(char));
1216 void netconfig_set_mac_address_from_file(void)
1219 char mac_str[MAC_ADDRESS_MAX_LEN];
1220 gchar *mac_lower_str = NULL;
1223 file = fopen(MAC_INFO_FILEPATH, "r");
1225 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1226 file = fopen(MAC_ADDRESS_FILEPATH, "r");
1228 ERR("Fail to open %s", MAC_ADDRESS_FILEPATH);
1232 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
1233 ERR("Fail to read mac address");
1238 mac_len = strlen(mac_str);
1240 ERR("mac.info is empty");
1245 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1246 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1248 g_free(mac_lower_str);
1252 tizen_profile_t _get_tizen_profile()
1254 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
1255 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
1259 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
1260 switch (*profileName) {
1263 profile = TIZEN_PROFILE_MOBILE;
1267 profile = TIZEN_PROFILE_WEARABLE;
1271 profile = TIZEN_PROFILE_TV;
1275 profile = TIZEN_PROFILE_IVI;
1277 default: // common or unknown ==> ALL ARE COMMON.
1278 profile = TIZEN_PROFILE_COMMON;
1285 void netconfig_plugin_init()
1287 handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
1288 if (!handle_headed) {
1289 ERR("Can't load %s: %s", HEADED_PLUGIN_FILEPATH, dlerror());
1291 headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin");
1292 if (!headed_plugin) {
1293 ERR("Can't load symbol: %s", dlerror());
1294 dlclose(handle_headed);
1296 netconfig_plugin_headed_enabled = TRUE;
1300 handle_telephony = dlopen(TELEPHONY_PLUGIN_FILEPATH, RTLD_NOW);
1301 if (!handle_telephony) {
1302 ERR("Can't load %s: %s", TELEPHONY_PLUGIN_FILEPATH, dlerror());
1304 telephony_plugin = dlsym(handle_telephony, "netconfig_telephony_plugin");
1305 if (!telephony_plugin) {
1306 ERR("Can't load symbol: %s", dlerror());
1307 dlclose(handle_telephony);
1309 netconfig_plugin_telephony_enabled = TRUE;
1314 void netconfig_plugin_deinit()
1316 if (netconfig_plugin_headed_enabled) {
1317 netconfig_plugin_headed_enabled = FALSE;
1318 dlclose(handle_headed);
1321 if (netconfig_plugin_telephony_enabled) {
1322 netconfig_plugin_telephony_enabled = FALSE;
1323 dlclose(handle_telephony);
1327 gboolean netconfig_get_headed_plugin_flag()
1329 return netconfig_plugin_headed_enabled;
1332 gboolean netconfig_get_telephony_plugin_flag()
1334 return netconfig_plugin_telephony_enabled;
1337 bool netconfig_check_feature_supported(netconfig_supported_feature_e feature)
1339 const char *key = NULL;
1341 if (!is_feature_checked[feature]) {
1343 case NETCONFIG_SUPPORTED_FEATURE_ETHERNET:
1344 key = ETHERNET_FEATURE;
1346 case NETCONFIG_SUPPORTED_FEATURE_TETHERING:
1347 key = TETHERING_FEATURE;
1349 case NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT:
1350 key = WIFI_DIRECT_FEATURE;
1352 case NETCONFIG_SUPPORTED_FEATURE_WIFI_SOFTAP:
1353 key = WIFI_SOFTAP_FEATURE;
1356 ERR("Uknown feature");
1360 if (system_info_get_platform_bool(key, &feature_supported[feature]) < 0) {
1361 ERR("Get feature is failed");
1364 is_feature_checked[feature] = true;
1366 return feature_supported[feature];