Fixed incorrect comparision and memory leaks
[platform/core/connectivity/net-config.git] / src / wifi-firmware.c
index 12ee7bf..d9a41f9 100755 (executable)
 #include "netsupplicant.h"
 #include "wifi-firmware.h"
 #include "network-statistics.h"
-#if defined WLAN_CHECK_POWERSAVE
-#include "wifi-powersave.h"
-#endif
 
 #define WLAN_DRIVER_SCRIPT                     "/usr/bin/wlan.sh"
 #define WLAN_IFACE_NAME                                "wlan0"
 
-#if defined(TIZEN_TV)
-#define WLAN_P2P_IFACE_NAME                    "p2p0"
-#else /* defined(TIZEN_TV) */
-#define WLAN_P2P_IFACE_NAME                    "wlan0"
-#endif /* defined(TIZEN_TV) */
+#define WLAN_P2P_IFACE_NAME_TV                 "p2p0"
+#define WLAN_P2P_IFACE_NAME_COMMON                     "wlan0"
+#define WLAN_P2P_IFACE_NAME ((TIZEN_TV) ? (WLAN_P2P_IFACE_NAME_TV) : (WLAN_P2P_IFACE_NAME_COMMON))
 
 static int __netconfig_sta_firmware_start(void)
 {
@@ -178,7 +173,7 @@ static int __netconfig_softap_firmware_stop(void)
 
 static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type)
 {
-       if (netconfig_emulator_is_emulated() == TRUE)
+       if (emulator_is_emulated() == TRUE)
                return -EIO;
 
        switch (type) {
@@ -197,7 +192,7 @@ static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type)
 
 static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type)
 {
-       if (netconfig_emulator_is_emulated() == TRUE)
+       if (emulator_is_emulated() == TRUE)
                return -EIO;
 
        switch (type) {
@@ -234,19 +229,9 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
                if (current_driver == NETCONFIG_WIFI_OFF) {
                        return -EALREADY;
                } else if (current_driver == alias) {
-#if defined WLAN_CHECK_POWERSAVE
-                       if (type == NETCONFIG_WIFI_STA &&
-                                       netconfig_wifi_is_powersave_mode() == TRUE) {
-                               netconfig_interface_down(WIFI_IFNAME);
-
-                               return -EALREADY;
-                       }
-#endif
 
 #if defined WLAN_CONCURRENT_MODE
-#if defined TIZEN_TELEPHONY_ENABLE
-                       vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
-#endif
+                       netconfig_vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
                        if (flight_mode == 0 && type == NETCONFIG_WIFI_STA &&
                                        netconfig_is_wifi_direct_on() == TRUE) {
                                netconfig_interface_down(WIFI_IFNAME);
@@ -254,9 +239,7 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
                                return -EALREADY;
                        }
 
-                       if (type == NETCONFIG_WIFI_P2P &&
-                                       netconfig_wifi_state_get_technology_state() >
-                                               NETCONFIG_WIFI_TECH_OFF) {
+                       if (type == NETCONFIG_WIFI_P2P && wifi_state_get_technology_state() > NETCONFIG_WIFI_TECH_OFF) {
                                netconfig_interface_down(WLAN_P2P_IFACE_NAME);
 
                                return -EALREADY;
@@ -276,14 +259,6 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
 
        if (current_driver > NETCONFIG_WIFI_OFF) {
                if (current_driver == alias) {
-#if defined WLAN_CHECK_POWERSAVE
-                       if (type == NETCONFIG_WIFI_STA &&
-                                       netconfig_wifi_is_powersave_mode() == TRUE) {
-                               netconfig_interface_up(WIFI_IFNAME);
-
-                               return -EALREADY;
-                       }
-#endif
 
 #if defined WLAN_CONCURRENT_MODE
                        if (type == NETCONFIG_WIFI_STA)
@@ -326,10 +301,15 @@ gboolean handle_start(WifiFirmware *firmware, GDBusMethodInvocation *context, co
        if (err < 0) {
                if (err == -EALREADY)
                        netconfig_error_already_exists(context);
-               else
+               else if (g_strcmp0("softap", device) == 0 && err == -EIO && netconfig_is_wifi_direct_on() == FALSE) {
+                       if (netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE) == 0 && netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE) == 0) {
+                               wifi_firmware_complete_start(firmware, context);
+                               return TRUE;
+                       } else
+                               netconfig_error_wifi_driver_failed(context);
+               } else
                        netconfig_error_wifi_driver_failed(context);
 
-               wifi_firmware_complete_start(firmware, context);
                return FALSE;
        }
 
@@ -358,10 +338,9 @@ gboolean handle_stop(WifiFirmware *firmware, GDBusMethodInvocation *context, con
                else
                        netconfig_error_wifi_driver_failed(context);
 
-               wifi_firmware_complete_start(firmware, context);
                return FALSE;
        }
 
-       wifi_firmware_complete_start(firmware, context);
+       wifi_firmware_complete_stop(firmware, context);
        return TRUE;
 }