[wifi-direct-manager] Using Firmware start stop logic from wifi-direct-manager. 92/72092/3
authorNishant Chaprana <n.chaprana@samsung.com>
Mon, 30 May 2016 12:13:09 +0000 (17:43 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Fri, 3 Jun 2016 05:20:39 +0000 (10:50 +0530)
Description: This patch removes dependency over net-config to start/stop
firmware for p2p interface.

Change-Id: I1935c9b0c72edaa95a62949e18cdd2e5697ef3d8
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
files/p2p_supp.sh.in
packaging/wifi-direct-manager.spec
plugin/wpasupplicant/ctrl_iface_dbus/wfd-plugin-wpasupplicant.c
plugin/wpasupplicant/ctrl_iface_sock/wfd-plugin-wpasupplicant.c

index 63b43ff..7d6066e 100755 (executable)
@@ -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
index aa464ad..df34bdf 100755 (executable)
@@ -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
index e9b4088..923ec6c 100755 (executable)
@@ -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
index 9f850a3..b792321 100755 (executable)
@@ -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;
 }