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"
50 static gboolean netconfig_device_picker_test = FALSE;
51 static int mdnsd_ref_count = 0;
55 } dnssd_conn_destroy_data;
57 static gboolean netconfig_plugin_headed_enabled = FALSE;
58 static void *handle_headed;
59 static struct netconfig_headed_plugin_t *headed_plugin;
61 GKeyFile *netconfig_keyfile_load(const char *pathname)
63 GKeyFile *keyfile = NULL;
66 keyfile = g_key_file_new();
67 if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) {
68 DBG("Unable to open %s, error %s", pathname, error->message);
71 g_key_file_free(keyfile);
75 DBG("loaded keyfile %s", pathname);
79 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname)
83 gchar *keydata = NULL;
84 gchar *needle = NULL, *directory = NULL;
86 directory = g_strdup(pathname);
87 needle = g_strrstr(directory, "/");
92 if (directory == NULL || (*directory) == '\0') {
94 ERR("directory is NULL");
98 if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) {
99 if (g_mkdir_with_parents(directory,
100 S_IRUSR | S_IWUSR | S_IXUSR) != 0) {
102 ERR("failed to make directory");
108 keydata = g_key_file_to_data(keyfile, &size, &error);
109 if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) {
110 ERR("Unable to save %s, error %s", pathname, error->message);
114 chmod(pathname, S_IRUSR | S_IWUSR);
115 DBG("Successfully saved keyfile %s", pathname);
120 void netconfig_start_timer_seconds(guint secs,
121 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
125 if (callback == NULL) {
126 ERR("callback function is NULL");
130 if ((timer_id != NULL && *timer_id != 0)) {
131 ERR("timer already is registered");
135 t_id = g_timeout_add_seconds(secs, callback, user_data);
138 ERR("Can't add timer");
142 if (timer_id != NULL)
146 void netconfig_start_timer(guint msecs,
147 gboolean(*callback) (gpointer), void *user_data, guint *timer_id)
151 INFO("Register timer with callback pointer (%p)", callback);
153 if (callback == NULL) {
154 ERR("callback function is NULL");
158 if ((timer_id != NULL && *timer_id != 0)) {
159 ERR("timer already is registered");
163 t_id = g_timeout_add(msecs, callback, user_data);
166 ERR("Can't add timer");
170 if (timer_id != NULL)
174 void netconfig_stop_timer(guint *timer_id)
176 if (timer_id == NULL) {
177 ERR("timer is NULL");
181 if (*timer_id != 0) {
182 g_source_remove(*timer_id);
187 static gboolean __netconfig_test_device_picker()
189 char *favorite_wifi_service = NULL;
191 favorite_wifi_service = wifi_get_favorite_service();
192 if (favorite_wifi_service != NULL) {
193 ERR("favorite_wifi_service is existed[%s] : Donot launch device picker", favorite_wifi_service);
194 g_free(favorite_wifi_service);
201 static void __netconfig_pop_device_picker(void)
203 if (!netconfig_plugin_headed_enabled)
209 headed_plugin->pop_device_picker();
212 static gboolean __netconfig_wifi_try_device_picker(gpointer data)
214 if (__netconfig_test_device_picker() == TRUE)
215 __netconfig_pop_device_picker();
220 static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, guint timer_id)
222 static guint netconfig_wifi_device_picker_service_timer = 0;
224 if (is_set_method != TRUE)
225 return netconfig_wifi_device_picker_service_timer;
227 if (netconfig_wifi_device_picker_service_timer != timer_id)
228 netconfig_wifi_device_picker_service_timer = timer_id;
230 return netconfig_wifi_device_picker_service_timer;
233 static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id)
235 __netconfig_wifi_device_picker_timer_id(TRUE, timer_id);
238 static guint __netconfig_wifi_device_picker_get_timer_id(void)
240 return __netconfig_wifi_device_picker_timer_id(FALSE, -1);
243 void netconfig_wifi_enable_device_picker_test(void)
245 netconfig_device_picker_test = TRUE;
248 void netconfig_wifi_device_picker_service_start(void)
250 const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700;
253 if (netconfig_device_picker_test == TRUE)
254 netconfig_device_picker_test = FALSE;
260 netconfig_vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state);
261 if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND)
264 DBG("Register device picker timer with %d milliseconds", NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL);
265 netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, __netconfig_wifi_try_device_picker, NULL, &timer_id);
267 __netconfig_wifi_device_picker_set_timer_id(timer_id);
270 void netconfig_wifi_device_picker_service_stop(void)
274 timer_id = __netconfig_wifi_device_picker_get_timer_id();
278 DBG("Clear device picker timer with timer_id %d", timer_id);
280 netconfig_stop_timer(&timer_id);
282 __netconfig_wifi_device_picker_set_timer_id(timer_id);
285 gboolean netconfig_is_wifi_direct_on(void)
287 #if defined TIZEN_P2P_ENABLE
288 int wifi_direct_state = 0;
290 netconfig_vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
292 DBG("Wi-Fi direct mode %d", wifi_direct_state);
293 return (wifi_direct_state != 0) ? TRUE : FALSE;
299 gboolean netconfig_is_wifi_tethering_on(void)
301 #if defined TIZEN_TETHERING_ENABLE
302 int wifi_tethering_state = 0;
304 netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
305 DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
306 if ((wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
307 || (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP)) {
308 DBG("Mobile AP is on");
312 DBG("Mobile AP is off");
316 gboolean netconfig_interface_up(const char *ifname)
321 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
325 memset(&ifr, 0, sizeof(ifr));
326 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
328 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
333 ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC);
334 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
341 DBG("Successfully activated wireless interface %s", ifname);
345 gboolean netconfig_interface_down(const char *ifname)
350 fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
354 memset(&ifr, 0, sizeof(ifr));
355 g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
357 if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
362 ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC;
363 if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) {
370 DBG("Successfully de-activated wireless interface %s", ifname);
374 int netconfig_execute_file(const char *file_path,
375 char *const args[], char *const envs[])
381 register unsigned int index = 0;
382 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
384 while (args[index] != NULL) {
385 DBG("%s", args[index]);
389 if (!(pid = fork())) {
390 DBG("pid(%d), ppid (%d)", getpid(), getppid());
391 DBG("Inside child, exec (%s) command", file_path);
394 if (execve(file_path, args, envs) == -1) {
395 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
396 DBG("Fail to execute command (%s)", error_buf);
399 } else if (pid > 0) {
400 if (waitpid(pid, &status, 0) == -1)
401 DBG("wait pid (%u) status (%d)", pid, status);
403 if (WIFEXITED(status)) {
404 rv = WEXITSTATUS(status);
405 DBG("exited, status=%d", rv);
406 } else if (WIFSIGNALED(status)) {
407 DBG("killed by signal %d", WTERMSIG(status));
408 } else if (WIFSTOPPED(status)) {
409 DBG("stopped by signal %d", WSTOPSIG(status));
410 } else if (WIFCONTINUED(status)) {
417 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
418 DBG("failed to fork(%s)", error_buf);
422 int netconfig_execute_cmd(const char *cmd)
431 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
434 DBG("command: %s", cmd);
436 args = g_strsplit_set(cmd, " ", -1);
438 if (!(pid = fork())) {
439 DBG("pid(%d), ppid (%d)", getpid(), getppid());
442 if (execv(args[0], args) == -1) {
443 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
444 DBG("Fail to execute command (%s)", error_buf);
448 } else if (pid > 0) {
449 if (waitpid(pid, &status, 0) == -1)
450 DBG("wait pid (%u) status (%d)", pid, status);
452 if (WIFEXITED(status)) {
453 rv = WEXITSTATUS(status);
454 DBG("exited, status=%d", rv);
455 } else if (WIFSIGNALED(status)) {
456 DBG("killed by signal %d", WTERMSIG(status));
457 } else if (WIFSTOPPED(status)) {
458 DBG("stopped by signal %d", WSTOPSIG(status));
459 } else if (WIFCONTINUED(status)) {
467 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
468 DBG("failed to fork(%s)", error_buf);
474 static void on_clat_handler()
479 clat_pid = waitpid(-1, &state, WNOHANG);
481 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
484 int netconfig_execute_clatd(const char *file_path, char *const args[])
489 register unsigned int index = 0;
490 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
492 struct sigaction act;
495 act.sa_handler = on_clat_handler;
496 sigemptyset(&act.sa_mask);
499 state = sigaction(SIGCHLD, &act, 0);
501 DBG("sigaction() : %d");
505 while (args[index] != NULL) {
506 DBG("%s", args[index]);
510 if (!(pid = fork())) {
511 DBG("pid(%d), ppid (%d)", getpid(), getppid());
512 DBG("Inside child, exec (%s) command", file_path);
515 if (execvp(file_path, args) == -1) {
516 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
517 ERR("Fail to execute command (%s)", error_buf);
520 } else if (pid > 0) {
521 ERR("Success to launch clatd");
525 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
526 DBG("failed to fork(%s)", error_buf);
530 int __netconfig_get_interface_index(const char *interface_name)
535 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
537 if (interface_name == NULL) {
538 DBG("Inteface name is NULL");
543 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
545 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
546 DBG("Failed to create socket : %s", error_buf);
550 memset(&ifr, 0, sizeof(ifr));
551 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
552 result = ioctl(sock, SIOCGIFINDEX, &ifr);
556 DBG("Failed to get ifr index: %s", error_buf);
560 return ifr.ifr_ifindex;
563 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
567 struct sockaddr_in addr_in;
569 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
571 memset(&ifr, 0, sizeof(ifr));
573 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
575 if (ifr.ifr_ifindex < 0)
578 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
580 memset(&rt, 0, sizeof(rt));
582 rt.rt_flags = RTF_UP | RTF_HOST;
583 memset(&addr_in, 0, sizeof(struct sockaddr_in));
584 addr_in.sin_family = address_family;
585 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
586 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
588 memset(&addr_in, 0, sizeof(struct sockaddr_in));
589 addr_in.sin_family = address_family;
590 addr_in.sin_addr.s_addr = INADDR_ANY;
591 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
593 memset(&addr_in, 0, sizeof(struct sockaddr_in));
594 addr_in.sin_family = AF_INET;
595 addr_in.sin_addr.s_addr = inet_addr(subnet);
596 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
598 rt.rt_dev = ifr.ifr_name;
601 sock = socket(PF_INET, SOCK_DGRAM, 0);
604 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
605 DBG("Failed to create socket : %s", error_buf);
609 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
610 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
611 DBG("Failed to set route address : %s", error_buf);
621 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
625 struct sockaddr_in addr_in;
627 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
629 memset(&ifr, 0, sizeof(ifr));
630 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
632 if (ifr.ifr_ifindex < 0)
635 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
637 memset(&rt, 0, sizeof(rt));
639 rt.rt_flags = RTF_UP;
640 memset(&addr_in, 0, sizeof(struct sockaddr_in));
641 addr_in.sin_family = address_family;
642 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
643 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
645 memset(&addr_in, 0, sizeof(struct sockaddr_in));
646 addr_in.sin_family = address_family;
647 addr_in.sin_addr.s_addr = inet_addr(subnet);
648 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
649 rt.rt_dev = ifr.ifr_name;
652 sock = socket(PF_INET, SOCK_DGRAM, 0);
655 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
656 DBG("Failed to create socket : %s", error_buf);
660 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
661 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
662 DBG("Failed to set route address : %s", error_buf);
672 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
677 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
679 memset(&rt, 0, sizeof(rt));
681 rt.rtmsg_dst_len = prefix_len;
683 rt.rtmsg_flags = RTF_UP | RTF_HOST;
686 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
687 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
688 DBG("inet_pton failed : %s", error_buf);
692 if (gateway != NULL) {
693 rt.rtmsg_flags |= RTF_GATEWAY;
694 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
695 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
696 DBG("inet_pton failed : %s", error_buf);
703 fd = socket(AF_INET6, SOCK_DGRAM, 0);
705 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
706 DBG("Failed to create socket : %s", error_buf);
710 rt.rtmsg_ifindex = 0;
714 memset(&ifr, 0, sizeof(ifr));
715 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
716 ioctl(fd, SIOCGIFINDEX, &ifr);
717 rt.rtmsg_ifindex = ifr.ifr_ifindex;
720 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
721 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
722 DBG("Failed to add route: %s", error_buf);
732 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
738 memset(&rt, 0, sizeof(rt));
740 rt.rtmsg_dst_len = prefix_len;
742 rt.rtmsg_flags = RTF_UP | RTF_HOST;
744 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
749 if (gateway != NULL) {
750 rt.rtmsg_flags |= RTF_GATEWAY;
751 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
759 fd = socket(AF_INET6, SOCK_DGRAM, 0);
763 rt.rtmsg_ifindex = 0;
767 memset(&ifr, 0, sizeof(ifr));
768 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
769 ioctl(fd, SIOCGIFINDEX, &ifr);
770 rt.rtmsg_ifindex = ifr.ifr_ifindex;
773 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
774 DBG("Failed to del route: %d\n", err);
784 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
786 #if defined TIZEN_P2P_ENABLE
788 DBG("Launch Wi-Fi direct daemon");
790 const char *path = "/usr/bin/wifi-direct-server.sh";
791 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
792 char *const envs[] = { NULL };
794 ret = netconfig_execute_file(path, args, envs);
796 ERR("Failed to launch Wi-Fi direct daemon");
797 netconfig_error_wifi_direct_failed(context);
801 wifi_complete_launch_direct(wifi, context);
804 wifi_complete_launch_direct(wifi, context);
809 int execute_mdnsd_script(char* op)
811 const char *path = "/usr/bin/mdnsresponder-server.sh";
812 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
813 char *const envs[] = { NULL };
815 return netconfig_execute_file(path, args, envs);
818 static void __dnssd_conn_destroyed_cb(GDBusConnection *conn,
819 const gchar *Name, const gchar *path, const gchar *interface,
820 const gchar *sig, GVariant *param, gpointer user_data)
825 dnssd_conn_destroy_data *data = user_data;
826 GDBusConnection *connection = NULL;
827 connection = netdbus_get_connection();
832 g_variant_get(param, "(sss)", &name, &old, &new);
834 if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
835 DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name,
838 g_dbus_connection_signal_unsubscribe(connection, data->conn_id);
839 if (mdnsd_ref_count == 0) {
840 if (execute_mdnsd_script("stop") < 0)
841 ERR("Failed to stop mdnsresponder daemon");
847 g_free(data->conn_name);
852 static void register_dnssd_conn_destroy_signal(gchar *name)
854 dnssd_conn_destroy_data *data;
855 GDBusConnection *connection = NULL;
856 connection = netdbus_get_connection();
858 if (connection == NULL) {
859 ERR("Failed to get GDbus Connection");
863 data = g_try_malloc0(sizeof(dnssd_conn_destroy_data));
864 data->conn_name = g_strdup(name);
866 data->conn_id = g_dbus_connection_signal_subscribe(connection,
867 DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
868 "NameOwnerChanged", NULL, name,
869 G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb,
874 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context,
877 DBG("Launch mdnsresponder daemon");
879 if (execute_mdnsd_script("start") < 0) {
880 ERR("Failed to launch mdnsresponder daemon");
881 netconfig_error_invalid_parameter(context);
886 register_dnssd_conn_destroy_signal(name);
887 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
889 network_complete_launch_mdns(object, context);
893 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
895 if (!netconfig_plugin_headed_enabled)
901 return headed_plugin->send_notification_to_net_popup(noti, ssid);
904 int netconfig_send_message_to_net_popup(const char *title,
905 const char *content, const char *type, const char *ssid)
907 if (!netconfig_plugin_headed_enabled)
913 return headed_plugin->send_message_to_net_popup(title, content, type, ssid);
916 int netconfig_send_restriction_to_net_popup(const char *title,
917 const char *type, const char *restriction)
919 if (!netconfig_plugin_headed_enabled)
925 return headed_plugin->send_restriction_to_net_popup(title, type, restriction);
928 void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val)
930 if (!netconfig_plugin_headed_enabled)
936 headed_plugin->set_system_event(sys_evt, evt_key, evt_val);
939 void __netconfig_pop_wifi_connected_poppup(const char *ssid)
941 if (!netconfig_plugin_headed_enabled)
947 headed_plugin->pop_wifi_connected_poppup(ssid);
950 void netconfig_set_vconf_int(const char * key, int value)
954 DBG("[%s: %d]", key, value);
956 ret = vconf_set_int(key, value);
958 ERR("Failed to set");
961 void netconfig_set_vconf_str(const char * key, const char * value)
965 DBG("[%s: %s]", key, value);
967 ret = vconf_set_str(key, value);
969 ERR("Failed to set");
972 int netconfig_vconf_get_int(const char * key, int *value)
976 ret = vconf_get_int(key, value);
977 if (ret != VCONF_OK) {
978 ERR("Failed to get vconfkey [%s] value", key);
985 int netconfig_vconf_get_bool(const char * key, int *value)
989 ret = vconf_get_bool(key, value);
990 if (ret != VCONF_OK) {
991 ERR("Failed to get vconfkey [%s] value", key);
998 char* netconfig_get_env(const char *key)
1001 char buf[256], *entry = NULL, *value = NULL, *last;
1007 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
1011 while (fgets(buf, sizeof(buf), fp)) {
1013 entry = strtok_r(entry, "=", &last);
1015 if (strstr(entry, key)) {
1016 entry = strtok_r(NULL, "\n", &last);
1018 len = strlen(entry);
1019 value = (char*)malloc(len+1);
1020 g_strlcpy(value, entry, len+1);
1022 value = (char*)malloc(sizeof(char));
1023 g_strlcpy(value, "\n", sizeof(char));
1034 void netconfig_set_mac_address_from_file(void)
1037 char mac_str[MAC_ADDRESS_MAX_LEN];
1038 gchar *mac_lower_str = NULL;
1041 file = fopen(MAC_INFO_FILEPATH, "r");
1043 ERR("Fail to open %s", MAC_INFO_FILEPATH);
1044 file = fopen(MAC_ADDRESS_FILEPATH, "r");
1046 ERR("Fail to open %s", MAC_ADDRESS_FILEPATH);
1050 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
1051 ERR("Fail to read mac address");
1056 mac_len = strlen(mac_str);
1058 ERR("mac.info is empty");
1063 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1064 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1066 g_free(mac_lower_str);
1070 tizen_profile_t _get_tizen_profile()
1072 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
1073 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
1077 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
1078 switch (*profileName) {
1081 profile = TIZEN_PROFILE_MOBILE;
1085 profile = TIZEN_PROFILE_WEARABLE;
1089 profile = TIZEN_PROFILE_TV;
1093 profile = TIZEN_PROFILE_IVI;
1095 default: // common or unknown ==> ALL ARE COMMON.
1096 profile = TIZEN_PROFILE_COMMON;
1103 void netconfig_plugin_init()
1105 handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
1106 if (!handle_headed) {
1107 ERR("Can't load %s: %s", HEADED_PLUGIN_FILEPATH, dlerror());
1111 headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin");
1112 if (!headed_plugin) {
1113 ERR("Can't load symbol: %s", dlerror());
1114 dlclose(handle_headed);
1118 netconfig_plugin_headed_enabled = TRUE;
1121 void netconfig_plugin_deinit()
1123 if (!netconfig_plugin_headed_enabled)
1126 netconfig_plugin_headed_enabled = FALSE;
1127 dlclose(handle_headed);
1130 gboolean netconfig_get_headed_plugin_flag()
1132 return netconfig_plugin_headed_enabled;