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 static void on_clat_handler()
427 clat_pid = waitpid(-1, &state, WNOHANG);
429 DBG("clat(%d) state(%d)", clat_pid, WEXITSTATUS(state));
432 int netconfig_execute_clatd(const char *file_path, char *const args[])
437 register unsigned int index = 0;
438 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
440 struct sigaction act;
443 act.sa_handler = on_clat_handler;
444 sigemptyset(&act.sa_mask);
447 state = sigaction(SIGCHLD, &act, 0);
449 DBG("sigaction() : %d");
453 while (args[index] != NULL) {
454 DBG("%s", args[index]);
458 if (!(pid = fork())) {
459 DBG("pid(%d), ppid (%d)", getpid(), getppid());
460 DBG("Inside child, exec (%s) command", file_path);
463 if (execvp(file_path, args) == -1) {
464 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
465 ERR("Fail to execute command (%s)", error_buf);
468 } else if (pid > 0) {
469 ERR("Success to launch clatd");
473 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
474 DBG("failed to fork(%s)", error_buf);
478 int __netconfig_get_interface_index(const char *interface_name)
483 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
485 if (interface_name == NULL) {
486 DBG("Inteface name is NULL");
491 sock = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
493 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
494 DBG("Failed to create socket : %s", error_buf);
498 memset(&ifr, 0, sizeof(ifr));
499 strncpy(ifr.ifr_name, interface_name, sizeof(ifr.ifr_name) - 1);
500 result = ioctl(sock, SIOCGIFINDEX, &ifr);
504 DBG("Failed to get ifr index: %s", error_buf);
508 return ifr.ifr_ifindex;
511 int netconfig_add_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
515 struct sockaddr_in addr_in;
517 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
519 memset(&ifr, 0, sizeof(ifr));
521 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
523 if (ifr.ifr_ifindex < 0)
526 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
528 memset(&rt, 0, sizeof(rt));
530 rt.rt_flags = RTF_UP | RTF_HOST;
531 memset(&addr_in, 0, sizeof(struct sockaddr_in));
532 addr_in.sin_family = address_family;
533 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
534 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
536 memset(&addr_in, 0, sizeof(struct sockaddr_in));
537 addr_in.sin_family = address_family;
538 addr_in.sin_addr.s_addr = INADDR_ANY;
539 memcpy(&rt.rt_gateway, &addr_in, sizeof(rt.rt_gateway));
541 memset(&addr_in, 0, sizeof(struct sockaddr_in));
542 addr_in.sin_family = AF_INET;
543 addr_in.sin_addr.s_addr = inet_addr(subnet);
544 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
546 rt.rt_dev = ifr.ifr_name;
549 sock = socket(PF_INET, SOCK_DGRAM, 0);
552 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
553 DBG("Failed to create socket : %s", error_buf);
557 if (ioctl(sock, SIOCADDRT, &rt) < 0) {
558 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
559 DBG("Failed to set route address : %s", error_buf);
569 int netconfig_del_route_ipv4(gchar *ip_addr, gchar *subnet, gchar *interface, gint address_family)
573 struct sockaddr_in addr_in;
575 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
577 memset(&ifr, 0, sizeof(ifr));
578 ifr.ifr_ifindex = __netconfig_get_interface_index(interface);
580 if (ifr.ifr_ifindex < 0)
583 strncpy(ifr.ifr_name, interface, IFNAMSIZ-1);
585 memset(&rt, 0, sizeof(rt));
587 rt.rt_flags = RTF_UP;
588 memset(&addr_in, 0, sizeof(struct sockaddr_in));
589 addr_in.sin_family = address_family;
590 addr_in.sin_addr.s_addr = inet_addr(ip_addr);
591 memcpy(&rt.rt_dst, &addr_in, sizeof(rt.rt_dst));
593 memset(&addr_in, 0, sizeof(struct sockaddr_in));
594 addr_in.sin_family = address_family;
595 addr_in.sin_addr.s_addr = inet_addr(subnet);
596 memcpy(&rt.rt_genmask, &addr_in, sizeof(rt.rt_genmask));
597 rt.rt_dev = ifr.ifr_name;
600 sock = socket(PF_INET, SOCK_DGRAM, 0);
603 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
604 DBG("Failed to create socket : %s", error_buf);
608 if (ioctl(sock, SIOCDELRT, &rt) < 0) {
609 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
610 DBG("Failed to set route address : %s", error_buf);
620 int netconfig_add_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
625 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
627 memset(&rt, 0, sizeof(rt));
629 rt.rtmsg_dst_len = prefix_len;
631 rt.rtmsg_flags = RTF_UP | RTF_HOST;
634 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
635 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
636 DBG("inet_pton failed : %s", error_buf);
640 if (gateway != NULL) {
641 rt.rtmsg_flags |= RTF_GATEWAY;
642 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
643 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
644 DBG("inet_pton failed : %s", error_buf);
651 fd = socket(AF_INET6, SOCK_DGRAM, 0);
653 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
654 DBG("Failed to create socket : %s", error_buf);
658 rt.rtmsg_ifindex = 0;
662 memset(&ifr, 0, sizeof(ifr));
663 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
664 ioctl(fd, SIOCGIFINDEX, &ifr);
665 rt.rtmsg_ifindex = ifr.ifr_ifindex;
668 if ((err = ioctl(fd, SIOCADDRT, &rt)) < 0) {
669 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
670 DBG("Failed to add route: %s", error_buf);
680 int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, unsigned char prefix_len)
686 memset(&rt, 0, sizeof(rt));
688 rt.rtmsg_dst_len = prefix_len;
690 rt.rtmsg_flags = RTF_UP | RTF_HOST;
692 if (inet_pton(AF_INET6, ip_addr, &rt.rtmsg_dst) < 0) {
697 if (gateway != NULL) {
698 rt.rtmsg_flags |= RTF_GATEWAY;
699 if (inet_pton(AF_INET6, gateway, &rt.rtmsg_gateway) < 0) {
707 fd = socket(AF_INET6, SOCK_DGRAM, 0);
711 rt.rtmsg_ifindex = 0;
715 memset(&ifr, 0, sizeof(ifr));
716 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)-1);
717 ioctl(fd, SIOCGIFINDEX, &ifr);
718 rt.rtmsg_ifindex = ifr.ifr_ifindex;
721 if ((err = ioctl(fd, SIOCDELRT, &rt)) < 0) {
722 DBG("Failed to del route: %d\n", err);
732 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
734 #if defined TIZEN_P2P_ENABLE
736 DBG("Launch Wi-Fi direct daemon");
738 const char *path = "/usr/bin/wifi-direct-server.sh";
739 char *const args[] = { "wifi-direct-server.sh", "start", NULL };
740 char *const envs[] = { NULL };
742 ret = netconfig_execute_file(path, args, envs);
744 ERR("Failed to launch Wi-Fi direct daemon");
745 netconfig_error_wifi_direct_failed(context);
749 wifi_complete_launch_direct(wifi, context);
752 wifi_complete_launch_direct(wifi, context);
757 int execute_mdnsd_script(char* op)
759 const char *path = "/usr/bin/mdnsresponder-server.sh";
760 char *const args[] = { "mdnsresponder-server.sh", op, NULL };
761 char *const envs[] = { NULL };
763 return netconfig_execute_file(path, args, envs);
766 static void __dnssd_conn_destroyed_cb(GDBusConnection *conn,
767 const gchar *Name, const gchar *path, const gchar *interface,
768 const gchar *sig, GVariant *param, gpointer user_data)
773 dnssd_conn_destroy_data *data = user_data;
774 GDBusConnection *connection = NULL;
775 connection = netdbus_get_connection();
780 g_variant_get(param, "(sss)", &name, &old, &new);
782 if (g_strcmp0(name, data->conn_name) == 0 && *new == '\0') {
783 DBG("Connection %s Destroyed: name %s id %d", data->conn_name, name,
786 g_dbus_connection_signal_unsubscribe(connection, data->conn_id);
787 if (mdnsd_ref_count == 0) {
788 if (execute_mdnsd_script("stop") < 0)
789 ERR("Failed to stop mdnsresponder daemon");
795 g_free(data->conn_name);
800 static void register_dnssd_conn_destroy_signal(gchar *name)
802 dnssd_conn_destroy_data *data;
803 GDBusConnection *connection = NULL;
804 connection = netdbus_get_connection();
806 if (connection == NULL) {
807 ERR("Failed to get GDbus Connection");
811 data = g_try_malloc0(sizeof(dnssd_conn_destroy_data));
812 data->conn_name = g_strdup(name);
814 data->conn_id = g_dbus_connection_signal_subscribe(connection,
815 DBUS_SERVICE_DBUS, DBUS_INTERFACE_DBUS,
816 "NameOwnerChanged", NULL, name,
817 G_DBUS_SIGNAL_FLAGS_NONE, __dnssd_conn_destroyed_cb,
822 gboolean handle_launch_mdns(Network *object, GDBusMethodInvocation *context,
825 DBG("Launch mdnsresponder daemon");
827 if (execute_mdnsd_script("start") < 0) {
828 ERR("Failed to launch mdnsresponder daemon");
829 netconfig_error_invalid_parameter(context);
834 register_dnssd_conn_destroy_signal(name);
835 DBG("Ref mdnsresponder daemon. ref count: %d", mdnsd_ref_count);
837 network_complete_launch_mdns(object, context);
841 gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid)
843 if (!netconfig_plugin_headed_enabled)
849 return headed_plugin->send_notification_to_net_popup(noti, ssid);
852 int netconfig_send_message_to_net_popup(const char *title,
853 const char *content, const char *type, const char *ssid)
855 if (!netconfig_plugin_headed_enabled)
861 return headed_plugin->send_message_to_net_popup(title, content, type, ssid);
864 int netconfig_send_restriction_to_net_popup(const char *title,
865 const char *type, const char *restriction)
867 if (!netconfig_plugin_headed_enabled)
873 return headed_plugin->send_restriction_to_net_popup(title, type, restriction);
876 void netconfig_set_system_event(int sys_evt, int evt_key, int evt_val)
878 if (!netconfig_plugin_headed_enabled)
884 headed_plugin->set_system_event(sys_evt, evt_key, evt_val);
887 void __netconfig_pop_wifi_connected_poppup(const char *ssid)
889 if (!netconfig_plugin_headed_enabled)
895 headed_plugin->pop_wifi_connected_poppup(ssid);
898 void netconfig_set_vconf_int(const char * key, int value)
902 DBG("[%s: %d]", key, value);
904 ret = vconf_set_int(key, value);
906 ERR("Failed to set");
909 void netconfig_set_vconf_str(const char * key, const char * value)
913 DBG("[%s: %s]", key, value);
915 ret = vconf_set_str(key, value);
917 ERR("Failed to set");
920 int netconfig_vconf_get_int(const char * key, int *value)
924 ret = vconf_get_int(key, value);
925 if (ret != VCONF_OK) {
926 ERR("Failed to get vconfkey [%s] value", key);
933 int netconfig_vconf_get_bool(const char * key, int *value)
937 ret = vconf_get_bool(key, value);
938 if (ret != VCONF_OK) {
939 ERR("Failed to get vconfkey [%s] value", key);
946 char* netconfig_get_env(const char *key)
949 char buf[256], *entry = NULL, *value = NULL, *last;
955 fp = fopen(NETCONFIG_TIZEN_SYSTEM_ENV, "r");
959 while (fgets(buf, sizeof(buf), fp)) {
961 entry = strtok_r(entry, "=", &last);
963 if (strstr(entry, key)) {
964 entry = strtok_r(NULL, "\n", &last);
967 value = (char*)malloc(len+1);
968 g_strlcpy(value, entry, len+1);
970 value = (char*)malloc(sizeof(char));
971 g_strlcpy(value, "\n", sizeof(char));
982 void netconfig_set_mac_address_from_file(void)
985 char mac_str[MAC_ADDRESS_MAX_LEN];
986 gchar *mac_lower_str = NULL;
989 file = fopen(MAC_INFO_FILEPATH, "r");
991 ERR("Fail to open %s", MAC_INFO_FILEPATH);
992 file = fopen(MAC_ADDRESS_FILEPATH, "r");
994 ERR("Fail to open %s", MAC_ADDRESS_FILEPATH);
998 if (fgets(mac_str, sizeof(mac_str), file) == NULL) {
999 ERR("Fail to read mac address");
1004 mac_len = strlen(mac_str);
1006 ERR("mac.info is empty");
1011 mac_lower_str = g_ascii_strup(mac_str, (gssize)mac_len);
1012 netconfig_set_vconf_str(VCONFKEY_WIFI_BSSID_ADDRESS, mac_lower_str);
1014 g_free(mac_lower_str);
1018 tizen_profile_t _get_tizen_profile()
1020 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
1021 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
1025 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
1026 switch (*profileName) {
1029 profile = TIZEN_PROFILE_MOBILE;
1033 profile = TIZEN_PROFILE_WEARABLE;
1037 profile = TIZEN_PROFILE_TV;
1041 profile = TIZEN_PROFILE_IVI;
1043 default: // common or unknown ==> ALL ARE COMMON.
1044 profile = TIZEN_PROFILE_COMMON;
1051 void netconfig_plugin_init()
1053 handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
1054 if (!handle_headed) {
1055 ERR("Can't load %s: %s", HEADED_PLUGIN_FILEPATH, dlerror());
1059 headed_plugin = dlsym(handle_headed, "netconfig_headed_plugin");
1060 if (!headed_plugin) {
1061 ERR("Can't load symbol: %s", dlerror());
1062 dlclose(handle_headed);
1066 netconfig_plugin_headed_enabled = TRUE;
1069 void netconfig_plugin_deinit()
1071 if (!netconfig_plugin_headed_enabled)
1074 netconfig_plugin_headed_enabled = FALSE;
1075 dlclose(handle_headed);
1078 gboolean netconfig_get_headed_plugin_flag()
1080 return netconfig_plugin_headed_enabled;