From c2c260526e6b9e68750ee3903cb64b1db9911d7d Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Mon, 30 May 2016 17:43:09 +0530 Subject: [PATCH] [wifi-direct-manager] Using Firmware start stop logic from wifi-direct-manager. Description: This patch removes dependency over net-config to start/stop firmware for p2p interface. Change-Id: I1935c9b0c72edaa95a62949e18cdd2e5697ef3d8 Signed-off-by: Nishant Chaprana --- files/p2p_supp.sh.in | 12 +- packaging/wifi-direct-manager.spec | 2 +- .../ctrl_iface_dbus/wfd-plugin-wpasupplicant.c | 106 ++----------- .../ctrl_iface_sock/wfd-plugin-wpasupplicant.c | 166 ++++++++++----------- 4 files changed, 98 insertions(+), 188 deletions(-) diff --git a/files/p2p_supp.sh.in b/files/p2p_supp.sh.in index 63b43ff..7d6066e 100755 --- a/files/p2p_supp.sh.in +++ b/files/p2p_supp.sh.in @@ -4,14 +4,14 @@ PROGRAM="@SBIN_DIR@/wpa_supplicant" start() { - HARDWARE_MODEL=`/bin/grep Hardware /proc/cpuinfo | /bin/awk "{print \\$3}"` - /bin/echo "Hardware Model=${HARDWARE_MODEL}" + HARDWARE_MODEL=`@BIN_DIR@/grep Hardware /proc/cpuinfo | @BIN_DIR@/awk "{print \\$3}"` + @BIN_DIR@/echo "Hardware Model=${HARDWARE_MODEL}" if [ -e @TZ_SYS_ETC@/p2p_supp.conf ]; then echo "File exist: @TZ_SYS_ETC@/p2p_supp.conf" else echo "File not exist. Reinstall: @TZ_SYS_ETC@/p2p_supp.conf" - /bin/cp @TZ_SYS_RO_ETC@/wifi-direct/p2p_supp.conf @TZ_SYS_ETC@/ + @BIN_DIR@/cp @TZ_SYS_RO_ETC@/wifi-direct/p2p_supp.conf @TZ_SYS_ETC@/ fi ## For Hawk-P Platform, Hardware model is Samsung if [ $HARDWARE_MODEL = "Samsung" ];then @@ -27,7 +27,7 @@ start_p2p0() echo "File exist: @TZ_SYS_ETC@/p2p_supp.conf" else echo "File not exist. Reinstall: @TZ_SYS_ETC@/p2p_supp.conf" - /bin/cp @TZ_SYS_RO_ETC@/wifi-direct/p2p_supp.conf @TZ_SYS_ETC@/ + @BIN_DIR@/cp @TZ_SYS_RO_ETC@/wifi-direct/p2p_supp.conf @TZ_SYS_ETC@/ fi @SBIN_DIR@/wpa_supplicant -t -B -ddd -Dnl80211 -ip2p0 -c@TZ_SYS_ETC@/p2p_supp.conf -f/var/log/wpa_supplicant.log } @@ -35,14 +35,14 @@ start_p2p0() start_dbus() { program=${PROGRAM} - run=`/bin/ps -eo comm|/bin/grep ${program}` + run=`@BIN_DIR@/ps -eo comm| @BIN_DIR@/grep ${program}` if [ "X${run}" == "X" ]; then echo "${program} is not running" if [ -e @TZ_SYS_ETC@/p2p_supp.conf ]; then echo "File exist: @TZ_SYS_ETC@/p2p_supp.conf" else echo "File not exist. Reinstall: @TZ_SYS_ETC@/p2p_supp.conf" - /bin/cp @TZ_SYS_RO_ETC@/wifi-direct/p2p_supp.conf @TZ_SYS_ETC@/ + @BIN_DIR@/cp @TZ_SYS_RO_ETC@/wifi-direct/p2p_supp.conf @TZ_SYS_ETC@/ fi @SBIN_DIR@/wpa_supplicant -t -B -u -ddd -K -f/var/log/wpa_supplicant.log else diff --git a/packaging/wifi-direct-manager.spec b/packaging/wifi-direct-manager.spec index aa464ad..df34bdf 100755 --- a/packaging/wifi-direct-manager.spec +++ b/packaging/wifi-direct-manager.spec @@ -1,6 +1,6 @@ Name: wifi-direct-manager Summary: Wi-Fi Direct manger -Version: 1.2.165 +Version: 1.2.166 Release: 1 Group: Network & Connectivity/Wireless License: Apache-2.0 diff --git a/plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c b/plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c index e9b4088..923ec6c 100755 --- a/plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c +++ b/plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c @@ -3287,109 +3287,31 @@ gboolean _ws_util_execute_file(const char *file_path, #ifndef TIZEN_WIFI_MODULE_BUNDLE static int __ws_p2p_firmware_start(void) { - GError *error = NULL; - GVariant *reply = NULL; - GVariant *param = NULL; - GDBusConnection *connection = NULL; - const char *device = "p2p"; + gboolean rv = FALSE; + const char *path = "/usr/bin/wlan.sh"; + char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL }; + char *const envs[] = { NULL }; - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (connection == NULL) { - if(error != NULL){ - WDP_LOGE("Error! Failed to connect to the D-BUS daemon: [%s]", - error->message); - g_error_free(error); - } - __WDP_LOG_FUNC_EXIT__; + rv = _ws_util_execute_file(path, args, envs); + if (rv != TRUE) return -1; - } - param = g_variant_new("(s)", device); - reply = g_dbus_connection_call_sync (connection, - NETCONFIG_SERVICE, /* bus name */ - NETCONFIG_WIFI_PATH, /* object path */ - NETCONFIG_WIFI_INTERFACE ".Firmware", /* interface name */ - "Start", /* method name */ - param, /* GVariant *params */ - NULL, /* reply_type */ - G_DBUS_CALL_FLAGS_NONE, /* flags */ - NETCONFIG_DBUS_REPLY_TIMEOUT , /* timeout */ - NULL, /* cancellable */ - &error); /* error */ - - if(error != NULL){ - if(strstr(error->message, ".AlreadyExists") != NULL) { - WDP_LOGD("p2p already enabled"); - g_error_free(error); - - } else { - WDP_LOGE("Error! Failed to call net-config method: [%s]", - error->message); - g_error_free(error); - if(reply) - g_variant_unref(reply); - g_object_unref(connection); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - } - if(reply) - g_variant_unref(reply); - g_object_unref(connection); + WDP_LOGI("Successfully loaded p2p device driver"); return 0; } static int __ws_p2p_firmware_stop(void) { - GError *error = NULL; - GVariant *reply = NULL; - GVariant *param = NULL; - GDBusConnection *connection = NULL; - const char *device = "p2p"; + gboolean rv = FALSE; + const char *path = "/usr/bin/wlan.sh"; + char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL }; + char *const envs[] = { NULL }; - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (connection == NULL) { - if(error != NULL){ - WDP_LOGE("Error! Failed to connect to the D-BUS daemon: [%s]", - error->message); - g_error_free(error); - } - __WDP_LOG_FUNC_EXIT__; + rv = _ws_util_execute_file(path, args, envs); + if (rv < 0) return -1; - } - param = g_variant_new("(s)", device); - reply = g_dbus_connection_call_sync (connection, - NETCONFIG_SERVICE, /* bus name */ - NETCONFIG_WIFI_PATH, /* object path */ - NETCONFIG_WIFI_INTERFACE ".Firmware", /* interface name */ - "Stop", /* method name */ - param, /* GVariant *params */ - NULL, /* reply_type */ - G_DBUS_CALL_FLAGS_NONE, /* flags */ - NETCONFIG_DBUS_REPLY_TIMEOUT , /* timeout */ - NULL, /* cancellable */ - &error); /* error */ - - if(error != NULL){ - if(strstr(error->message, ".AlreadyExists") != NULL) { - WDP_LOGD("p2p already disabled"); - g_error_free(error); - - } else { - WDP_LOGE("Error! Failed to call net-config method: [%s]", - error->message); - g_error_free(error); - if(reply) - g_variant_unref(reply); - g_object_unref(connection); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - } - if(reply) - g_variant_unref(reply); - g_object_unref(connection); + WDP_LOGI("Successfully removed p2p device driver"); return 0; } #endif diff --git a/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c b/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c index 9f850a3..b792321 100755 --- a/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c +++ b/plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c @@ -2448,111 +2448,99 @@ int ws_deinit() return 0; } -static int __ws_p2p_firmware_start(void) +gboolean _ws_util_interface_up(const char *ifname) { - GError *error = NULL; - GVariant *reply = NULL; - GVariant *param = NULL; - GDBusConnection *connection = NULL; - const char *device = "p2p"; + int fd; + struct ifreq ifr; - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (connection == NULL) { - if(error != NULL){ - WDP_LOGE("Error! Failed to connect to the D-BUS daemon: [%s]", - error->message); - g_error_free(error); - } - __WDP_LOG_FUNC_EXIT__; - return -1; + fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (fd < 0) + return FALSE; + + memset(&ifr, 0, sizeof(ifr)); + g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { + close(fd); + return FALSE; + } + + ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC); + if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { + close(fd); + return FALSE; } - param = g_variant_new("(s)", device); - reply = g_dbus_connection_call_sync (connection, - NETCONFIG_SERVICE, /* bus name */ - NETCONFIG_WIFI_PATH, /* object path */ - NETCONFIG_WIFI_INTERFACE ".Firmware", /* interface name */ - "Start", /* method name */ - param, /* GVariant *params */ - NULL, /* reply_type */ - G_DBUS_CALL_FLAGS_NONE, /* flags */ - NETCONFIG_DBUS_REPLY_TIMEOUT , /* timeout */ - NULL, /* cancellable */ - &error); /* error */ + close(fd); - if(error != NULL){ - if(strstr(error->message, ".AlreadyExists") != NULL) { - WDP_LOGD("p2p already enabled"); - g_error_free(error); + WDP_LOGI("Successfully activated [%s] interface", ifname); + return TRUE; +} - } else { - WDP_LOGE("Error! Failed to call net-config method: [%s]", - error->message); - g_error_free(error); - if(reply) - g_variant_unref(reply); - g_object_unref(connection); - __WDP_LOG_FUNC_EXIT__; - return -1; - } +gboolean _ws_util_interface_down(const char *ifname) +{ + int fd; + struct ifreq ifr; + + fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (fd < 0) + return FALSE; + + memset(&ifr, 0, sizeof(ifr)); + g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { + close(fd); + return FALSE; } - if(reply) - g_variant_unref(reply); - g_object_unref(connection); + + ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC; + if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { + close(fd); + return FALSE; + } + + close(fd); + + WDP_LOGI("Successfully de-activated [%s] interface", ifname); + return TRUE; +} + +static int __ws_p2p_firmware_start(void) +{ + gboolean rv = FALSE; + const char *path = "/usr/bin/wlan.sh"; + char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL }; + char *const envs[] = { NULL }; + + rv = _ws_util_execute_file(path, args, envs); + if (rv != TRUE) + return -1; + + rv = _ws_util_interface_up(COMMON_IFACE_NAME); + if (rv != TRUE) + return -1; + + WDP_LOGI("Successfully loaded p2p device driver"); return 0; } static int __ws_p2p_firmware_stop(void) { - GError *error = NULL; - GVariant *reply = NULL; - GVariant *param = NULL; - GDBusConnection *connection = NULL; - const char *device = "p2p"; + gboolean rv = FALSE; + const char *path = "/usr/bin/wlan.sh"; + char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL }; + char *const envs[] = { NULL }; - connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - if (connection == NULL) { - if(error != NULL){ - WDP_LOGE("Error! Failed to connect to the D-BUS daemon: [%s]", - error->message); - g_error_free(error); - } - __WDP_LOG_FUNC_EXIT__; + rv = _ws_util_interface_down(COMMON_IFACE_NAME); + if (rv != TRUE) return -1; - } - param = g_variant_new("(s)", device); - - reply = g_dbus_connection_call_sync (connection, - NETCONFIG_SERVICE, /* bus name */ - NETCONFIG_WIFI_PATH, /* object path */ - NETCONFIG_WIFI_INTERFACE ".Firmware", /* interface name */ - "Stop", /* method name */ - param, /* GVariant *params */ - NULL, /* reply_type */ - G_DBUS_CALL_FLAGS_NONE, /* flags */ - NETCONFIG_DBUS_REPLY_TIMEOUT , /* timeout */ - NULL, /* cancellable */ - &error); /* error */ - if(error != NULL){ - if(strstr(error->message, ".AlreadyExists") != NULL) { - WDP_LOGD("p2p already disabled"); - g_error_free(error); + rv = _ws_util_execute_file(path, args, envs); + if (rv < 0) + return -1; - } else { - WDP_LOGE("Error! Failed to call net-config method: [%s]", - error->message); - g_error_free(error); - if(reply) - g_variant_unref(reply); - g_object_unref(connection); - __WDP_LOG_FUNC_EXIT__; - return -1; - } - } - if(reply) - g_variant_unref(reply); - g_object_unref(connection); + WDP_LOGI("Successfully removed p2p device driver"); return 0; } -- 2.7.4