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 chmod(pathname, S_IRUSR | S_IWUSR);
151 DBG("Successfully saved keyfile %s", pathname);
156 void netconfig_start_timer_seconds(guint secs,
157 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
161 if (callback == NULL) {
162 ERR("callback function is NULL");
166 if ((timer_id != NULL && *timer_id != 0)) {
167 ERR("timer already is registered");
171 t_id = g_timeout_add_seconds(secs, callback, user_data);
174 ERR("Can't add timer");
178 if (timer_id != NULL)
182 void netconfig_start_timer(guint msecs,
183 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
187 INFO("Register timer with callback pointer (%p)", callback);
189 if (callback == NULL) {
190 ERR("callback function is NULL");
194 if ((timer_id != NULL && *timer_id != 0)) {
195 ERR("timer already is registered");
199 t_id = g_timeout_add(msecs, callback, user_data);
202 ERR("Can't add timer");
206 if (timer_id != NULL)
210 void netconfig_stop_timer(guint *timer_id)
212 if (timer_id == NULL) {
213 ERR("timer is NULL");
217 if (*timer_id != 0) {
218 g_source_remove(*timer_id);
223 static gboolean __netconfig_test_device_picker()
225 char *favorite_wifi_service = NULL;
227 favorite_wifi_service = wifi_get_favorite_service();
228 if (favorite_wifi_service != NULL) {
229 ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service);
230 g_free(favorite_wifi_service);
237 static void __netconfig_pop_device_picker(void)
239 if (!netconfig_plugin_headed_enabled)
245 headed_plugin->pop_device_picker();
248 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
250 if (__netconfig_test_device_picker() == TRUE)
251 __netconfig_pop_device_picker();
256 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id)
258 static guint netconfig_wifi_device_picker_service_timer = 0;
260 if (is_set_method != TRUE)
261 return netconfig_wifi_device_picker_service_timer;
263 if (netconfig_wifi_device_picker_service_timer != timer_id)
264 netconfig_wifi_device_picker_service_timer = timer_id;
266 return netconfig_wifi_device_picker_service_timer;
269 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
271 __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
274 static guint __netconfig_wifi_device_picker_get_timer_id(void)
276 return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
279 void netconfig_wifi_enable_device_picker_test(void)
281 netconfig_device_picker_test = TRUE;
284 void netconfig_wifi_device_picker_service_start(void)
286 const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
289 if (netconfig_device_picker_test == TRUE)
290 netconfig_device_picker_test = FALSE;
296 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
297 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
300 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
301 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
303 __netconfig_wifi_device_picker_set_timer_id(timer_id);
306 void netconfig_wifi_device_picker_service_stop(void)
310 timer_id = __netconfig_wifi_device_picker_get_timer_id();
314 DBG("Clear device picker timer with timer_id %d", timer_id);
316 netconfig_stop_timer(&timer_id);
318 __netconfig_wifi_device_picker_set_timer_id(timer_id);
321 gboolean netconfig_is_wifi_direct_on(void)
323 if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
326 int wifi_direct_state = 0;
328 netconfig_vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
330 DBG("Wi-Fi direct mode %d", wifi_direct_state);
331 return (wifi_direct_state != 0) ? TRUE : FALSE;
334 gboolean netconfig_is_wifi_tethering_on(void)
336 if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING)) {
337 int wifi_tethering_state = 0;
339 netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
340 DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
341 if ((wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
342 || (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP)) {
343 DBG("Mobile AP is on");
348 DBG("Mobile AP is off");
352 gboolean netconfig_interface_up(const char *ifname)
357 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
361 memset(&ifr, 0, sizeof(ifr));
362 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
364 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
369 ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
370 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
377 DBG("Successfully activated wireless interface %s", ifname);
381 gboolean netconfig_interface_down(const char *ifname)
386 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
390 memset(&ifr, 0, sizeof(ifr));
391 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
393 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
398 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
399 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
406 DBG("Successfully de-activated wireless interface %s", ifname);
410 int netconfig_execute_file(const char *file_path,
411 char *const args[], char *const envs[])
417 register unsigned int index = 0;
418 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
420 while (args[index] != NULL) {
421 DBG("%s", args[index]);
425 if (!(pid = fork())) {
426 DBG("pid(%d), ppid (%d)", getpid(), getppid());
427 DBG("Inside child, exec (%s) command", file_path);
430 if (execve(file_path, args, envs) == -1) {
431 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
432 DBG("Fail to execute command (%s)", error_buf);
435 } else if (pid > 0) {
436 if (waitpid(pid, &status, 0) == -1)
437 DBG("wait pid (%u) status (%d)", pid, status);
439 if (WIFEXITED(status)) {
440 rv = WEXITSTATUS(status);
441 DBG("exited, status=%d", rv);
442 } else if (WIFSIGNALED(status)) {
443 DBG("killed by signal %d", WTERMSIG(status));
444 } else if (WIFSTOPPED(status)) {
445 DBG("stopped by signal %d", WSTOPSIG(status));
446 } else if (WIFCONTINUED(status)) {
453 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
454 DBG("failed to fork(%s)", error_buf);
458 int netconfig_execute_cmd(const char *cmd)
467 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
470 DBG("command: %s", cmd);
472 args = g_strsplit_set(cmd, " ", -1);
474 if (!(pid = fork())) {
475 DBG("pid(%d), ppid (%d)", getpid(), getppid());
478 if (execv(args[0], args) == -1) {
479 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
480 DBG("Fail to execute command (%s)", error_buf);
484 } else if (pid > 0) {
485 if (waitpid(pid, &status, 0) == -1)
486 DBG("wait pid (%u) status (%d)", pid, status);
488 if (WIFEXITED(status)) {
489 rv = WEXITSTATUS(status);
490 DBG("exited, status=%d", rv);
491 } else if (WIFSIGNALED(status)) {
492 DBG("killed by signal %d", WTERMSIG(status));
493 } else if (WIFSTOPPED(status)) {
494 DBG("stopped by signal %d", WSTOPSIG(status));
495 } else if (WIFCONTINUED(status)) {
503 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
504 DBG("failed to fork(%s)", error_buf);
510 static void on_clat_handler()
515 clat_pid = waitpid(-1, &state, WNOHANG);
517 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
520 int netconfig_execute_clatd(const char *file_path, char *const args[])
525 register unsigned int index = 0;
526 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
528 struct sigaction act;
531 act.sa_handler = on_clat_handler;
532 sigemptyset(&act.sa_mask);
535 state = sigaction(SIGCHLD, &act, 0);
537 DBG("sigaction() : %d");
541 while (args[index] != NULL) {
542 DBG("%s", args[index]);
546 if (!(pid = fork())) {
547 DBG("pid(%d), ppid (%d)", getpid(), getppid());
548 DBG("Inside child, exec (%s) command", file_path);
551 if (execvp(file_path, args) == -1) {
552 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
553 ERR("Fail to execute command (%s)", error_buf);
556 } else if (pid > 0) {
557 ERR("Success to launch clatd");
561 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
562 DBG("failed to fork(%s)", error_buf);
566 static void no_wait_signal_handler()
571 child_pid = waitpid(-1, &state, WNOHANG);
573 DBG("child_id(%d) state(%d)", child_pid, WEXITSTATUS(state));
576 int netconfig_execute_file_no_wait(const char *file_path, char *const args[])
581 register unsigned int index = 0;
583 struct sigaction act;
586 act.sa_handler = no_wait_signal_handler;
587 sigemptyset(&act.sa_mask);
590 state = sigaction(SIGCHLD, &act, 0);
592 DBG("sigaction() : %d");
596 while (args[index] != NULL) {
597 DBG("%s", args[index]);
601 if (!(pid = fork())) {
602 DBG("pid(%d), ppid (%d)", getpid(), getppid());
603 DBG("Inside child, exec (%s) command", file_path);
606 if (execvp(file_path, args) == -1) {
607 ERR("Fail to execute command (%s)", strerror(errno));
610 } else if (pid > 0) {
611 ERR("Successfully launched child process");
615 DBG("failed to fork(%s)", strerror(errno));
619 int __netconfig_get_interface_index(const char *interface_name)
624 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
626 if (interface_name == NULL) {
627 DBG("Inteface name is NULL");
632 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
634 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
635 DBG("Failed to create socket : %s", error_buf);
639 memset(&ifr, 0, sizeof(ifr));
640 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
641 result = ioctl(sock, SIOCGIFINDEX, &ifr);
645 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
646 DBG("Failed to get ifr index: %s", error_buf);
650 return ifr.ifr_ifindex;
653 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
657 struct sockaddr_in addr_in;
659 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
661 memset(&ifr, 0, sizeof(ifr));
663 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
665 if (ifr.ifr_ifindex < 0)
668 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
670 memset(&rt, 0, sizeof(rt));
672 rt.rt_flags = RTF_UP | RTF_HOST;
673 memset(&addr_in, 0, sizeof(struct sockaddr_in));
674 addr_in.sin_family = address_family;
675 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
676 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
678 memset(&addr_in, 0, sizeof(struct sockaddr_in));
679 addr_in.sin_family = address_family;
680 addr_in.sin_addr.s_addr = INADDR_ANY;
681 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
683 memset(&addr_in, 0, sizeof(struct sockaddr_in));
684 addr_in.sin_family = AF_INET;
685 addr_in.sin_addr.s_addr = inet_addr(subnet);
686 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
688 rt.rt_dev = ifr.ifr_name;
691 sock = socket(PF_INET, SOCK_DGRAM, 0);
694 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
695 DBG("Failed to create socket : %s", error_buf);
699 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
700 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
701 DBG("Failed to set route address : %s", error_buf);
711 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
715 struct sockaddr_in addr_in;
717 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
719 memset(&ifr, 0, sizeof(ifr));
720 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
722 if (ifr.ifr_ifindex < 0)
725 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
727 memset(&rt, 0, sizeof(rt));
729 rt.rt_flags = RTF_UP;
730 memset(&addr_in, 0, sizeof(struct sockaddr_in));
731 addr_in.sin_family = address_family;
732 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
733 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
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(subnet);
738 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
739 rt.rt_dev = ifr.ifr_name;
742 sock = socket(PF_INET, SOCK_DGRAM, 0);
745 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
746 DBG("Failed to create socket : %s", error_buf);
750 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
751 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
752 DBG("Failed to set route address : %s", error_buf);
762 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
767 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
769 memset(&rt, 0, sizeof(rt));
771 rt.rtmsg_dst_len = prefix_len;
773 rt.rtmsg_flags = RTF_UP | RTF_HOST;
776 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
777 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
778 DBG("inet_pton failed : %s", error_buf);
782 if (gateway != NULL) {
783 rt.rtmsg_flags |= RTF_GATEWAY;
784 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
785 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
786 DBG("inet_pton failed : %s", error_buf);
793 fd = socket(AF_INET6, SOCK_DGRAM, 0);
795 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
796 DBG("Failed to create socket : %s", error_buf);
800 rt.rtmsg_ifindex = 0;
804 memset(&ifr, 0, sizeof(ifr));
805 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
806 ioctl(fd, SIOCGIFINDEX, &ifr);
807 rt.rtmsg_ifindex = ifr.ifr_ifindex;
810 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
811 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
812 DBG("Failed to add route: %s", error_buf);
822 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
828 memset(&rt, 0, sizeof(rt));
830 rt.rtmsg_dst_len = prefix_len;
832 rt.rtmsg_flags = RTF_UP | RTF_HOST;
834 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
839 if (gateway != NULL) {
840 rt.rtmsg_flags |= RTF_GATEWAY;
841 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
849 fd = socket(AF_INET6, SOCK_DGRAM, 0);
853 rt.rtmsg_ifindex = 0;
857 memset(&ifr, 0, sizeof(ifr));
858 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
859 ioctl(fd, SIOCGIFINDEX, &ifr);
860 rt.rtmsg_ifindex = ifr.ifr_ifindex;
863 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
864 DBG("Failed to del route: %d\n", err);
874 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
876 if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT)) {
877 wifi_complete_launch_direct(wifi, context);
882 DBG("Launch Wi-Fi direct daemon");
884 const char *path = "/usr/bin/wifi-direct-server.sh";
885 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
886 char *const envs[] = { NULL };
888 ret = netconfig_execute_file(path, args, envs);
890 ERR("Failed to launch Wi-Fi direct daemon");
891 netconfig_error_wifi_direct_failed(context);
895 wifi_complete_launch_direct(wifi, context);
899 int execute_mdnsd_script(char* op)
901 const char *path = "/usr/bin/mdnsresponder-server.sh";
902 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
903 char *const envs[] = { NULL };
905 return netconfig_execute_file(path, args, envs);
908 static void __dnssd_conn_destroyed_cb(GDBusConnection *conn,
909 const gchar *Name, const gchar *path, const gchar *interface,
910 const gchar *sig, GVariant *param, gpointer user_data)
915 dnssd_conn_destroy_data *data = user_data;
916 GDBusConnection *connection = NULL;
917 connection = netdbus_get_connection();
922 g_variant_get(param, "(sss)", &name, &old, &new);
924 if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
925 DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name,
928 g_dbus_connection_signal_unsubscribe(connection, data->conn_id);
929 if (mdnsd_ref_count == 0) {
930 if (execute_mdnsd_script("stop") < 0)
931 ERR("Failed to stop mdnsresponder daemon");
937 g_free(data->conn_name);
942 static void register_dnssd_conn_destroy_signal(gchar *name)
944 dnssd_conn_destroy_data *data;
945 GDBusConnection *connection = NULL;
946 connection = netdbus_get_connection();
948 if (connection == NULL) {
949 ERR("Failed to get GDbus Connection");
953 data = g_try_malloc0(sizeof(dnssd_conn_destroy_data));
956 ERR("Out of Memory!");
960 data->conn_name = g_strdup(name);
962 data->conn_id = g_dbus_connection_signal_subscribe(connection,
963 DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
964 "NameOwnerChanged", NULL, name,
965 G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb,
970 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context,
973 DBG("Launch mdnsresponder daemon");
975 if (execute_mdnsd_script("start") < 0) {
976 ERR("Failed to launch mdnsresponder daemon");
977 netconfig_error_invalid_parameter(context);
982 register_dnssd_conn_destroy_signal(name);
983 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
985 network_complete_launch_mdns(object, context);
989 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
991 if (!netconfig_plugin_headed_enabled)
997 return headed_plugin->send_notification_to_net_popup(noti, ssid);
1000 int netconfig_send_message_to_net_popup(const char *title,
1001 const char *content, const char *type, const char *ssid)
1003 if (!netconfig_plugin_headed_enabled)
1009 return headed_plugin->send_message_to_net_popup(title, content, type, ssid);
1012 int netconfig_send_restriction_to_net_popup(const char *title,
1013 const char *type, const char *restriction)
1015 if (!netconfig_plugin_headed_enabled)
1021 return headed_plugin->send_restriction_to_net_popup(title, type, restriction);
1024 void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val)
1026 if (!netconfig_plugin_headed_enabled)
1032 headed_plugin->set_system_event(sys_evt, evt_key, evt_val);
1035 void __netconfig_pop_wifi_connected_poppup(const char *ssid)
1037 if (!netconfig_plugin_headed_enabled)
1043 headed_plugin->pop_wifi_connected_poppup(ssid);
1046 void netconfig_get_telephony_network_type(int *svctype, int *pstype)
1048 if (!netconfig_plugin_telephony_enabled)
1051 if (!telephony_plugin)
1054 telephony_plugin->get_telephony_network_type(svctype, pstype);
1057 gboolean __netconfig_wifi_get_sim_imsi(Wifi *wifi, GDBusMethodInvocation *context)
1059 if (!netconfig_plugin_telephony_enabled)
1062 if (!telephony_plugin)
1065 return telephony_plugin->wifi_get_sim_imsi(wifi, context);
1068 netconfig_error_e __netconfig_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data,
1069 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1071 if (!netconfig_plugin_telephony_enabled)
1072 return NETCONFIG_ERROR_INTERNAL;
1074 if (!telephony_plugin)
1075 return NETCONFIG_ERROR_INTERNAL;
1077 return telephony_plugin->wifi_req_aka_auth(rand_data, autn_data, context, data);
1080 gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data,
1081 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1083 if (!netconfig_plugin_telephony_enabled)
1086 if (!telephony_plugin)
1089 return telephony_plugin->wifi_req_sim_auth(rand_data, context, data);
1092 gboolean netconfig_tapi_check_sim_state(void)
1094 if (!netconfig_plugin_telephony_enabled)
1097 if (!telephony_plugin)
1100 return telephony_plugin->tapi_check_sim_state();
1103 gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi,
1104 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1106 if (!netconfig_plugin_telephony_enabled)
1109 if (!telephony_plugin)
1112 return telephony_plugin->wifi_get_aka_authdata(wifi, context, data);
1115 gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi,
1116 GDBusMethodInvocation *context, struct wifi_authentication_data **data)
1118 if (!netconfig_plugin_telephony_enabled)
1121 if (!telephony_plugin)
1124 return telephony_plugin->wifi_get_sim_authdata(wifi, context, data);
1127 void netconfig_set_vconf_int(const char * key, int value)
1131 DBG("[%s: %d]", key, value);
1133 ret = vconf_set_int(key, value);
1134 if (ret != VCONF_OK)
1135 ERR("Failed to set");
1138 void netconfig_set_vconf_str(const char * key, const char * value)
1142 DBG("[%s: %s]", key, value);
1144 ret = vconf_set_str(key, value);
1145 if (ret != VCONF_OK)
1146 ERR("Failed to set");
1149 int netconfig_vconf_get_int(const char * key, int *value)
1153 ret = vconf_get_int(key, value);
1154 if (ret != VCONF_OK) {
1155 ERR("Failed to get vconfkey [%s] value", key);
1162 int netconfig_vconf_get_bool(const char * key, int *value)
1166 ret = vconf_get_bool(key, value);
1167 if (ret != VCONF_OK) {
1168 ERR("Failed to get vconfkey [%s] value", key);
1175 char* netconfig_get_env(const char *key)
1178 char buf[256], *entry = NULL, *value = NULL, *last;
1184 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
1188 while (fgets(buf, sizeof(buf), fp)) {
1190 entry = strtok_r(entry, "=", &last);
1192 if (strstr(entry, key)) {
1193 entry = strtok_r(NULL, "\n", &last);
1195 len = strlen(entry);
1196 value = (char*)malloc(len+1);
1197 g_strlcpy(value, entry, len+1);
1199 value = (char*)malloc(sizeof(char));
1200 g_strlcpy(value, "\n", sizeof(char));
1211 void netconfig_set_mac_address_from_file(void)
1214 char mac_str[MAC_ADDRESS_MAX_LEN];
1215 gchar *mac_lower_str = NULL;
1218 file = fopen(MAC_INFO_FILEPATH, "r");
1220 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1221 file = fopen(MAC_ADDRESS_FILEPATH, "r");
1223 ERR("Fail to open %s", MAC_ADDRESS_FILEPATH);
1227 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
1228 ERR("Fail to read mac address");
1233 mac_len = strlen(mac_str);
1235 ERR("mac.info is empty");
1240 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1241 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1243 g_free(mac_lower_str);
1247 tizen_profile_t _get_tizen_profile()
1249 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
1250 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
1254 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
1255 switch (*profileName) {
1258 profile = TIZEN_PROFILE_MOBILE;
1262 profile = TIZEN_PROFILE_WEARABLE;
1266 profile = TIZEN_PROFILE_TV;
1270 profile = TIZEN_PROFILE_IVI;
1272 default: // common or unknown ==> ALL ARE COMMON.
1273 profile = TIZEN_PROFILE_COMMON;
1280 void netconfig_plugin_init()
1282 handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
1283 if (!handle_headed) {
1284 ERR("Can't load %s: %s", HEADED_PLUGIN_FILEPATH, dlerror());
1286 headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin");
1287 if (!headed_plugin) {
1288 ERR("Can't load symbol: %s", dlerror());
1289 dlclose(handle_headed);
1291 netconfig_plugin_headed_enabled = TRUE;
1295 handle_telephony = dlopen(TELEPHONY_PLUGIN_FILEPATH, RTLD_NOW);
1296 if (!handle_telephony) {
1297 ERR("Can't load %s: %s", TELEPHONY_PLUGIN_FILEPATH, dlerror());
1299 telephony_plugin = dlsym(handle_telephony, "netconfig_telephony_plugin");
1300 if (!telephony_plugin) {
1301 ERR("Can't load symbol: %s", dlerror());
1302 dlclose(handle_telephony);
1304 netconfig_plugin_telephony_enabled = TRUE;
1309 void netconfig_plugin_deinit()
1311 if (netconfig_plugin_headed_enabled) {
1312 netconfig_plugin_headed_enabled = FALSE;
1313 dlclose(handle_headed);
1316 if (netconfig_plugin_telephony_enabled) {
1317 netconfig_plugin_telephony_enabled = FALSE;
1318 dlclose(handle_telephony);
1322 gboolean netconfig_get_headed_plugin_flag()
1324 return netconfig_plugin_headed_enabled;
1327 gboolean netconfig_get_telephony_plugin_flag()
1329 return netconfig_plugin_telephony_enabled;
1332 bool netconfig_check_feature_supported(netconfig_supported_feature_e feature)
1334 const char *key = NULL;
1336 if (!is_feature_checked[feature]) {
1338 case NETCONFIG_SUPPORTED_FEATURE_ETHERNET:
1339 key = ETHERNET_FEATURE;
1341 case NETCONFIG_SUPPORTED_FEATURE_TETHERING:
1342 key = TETHERING_FEATURE;
1344 case NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT:
1345 key = WIFI_DIRECT_FEATURE;
1348 ERR("Uknown feature");
1352 if (system_info_get_platform_bool(key, &feature_supported[feature]) < 0) {
1353 ERR("Get feature is failed");
1356 is_feature_checked[feature] = true;
1358 return feature_supported[feature];