[TSAM-8583] Deactvie Wi-Fi before enabling Soft AP 65/90965/2 accepted/tizen/3.0/ivi/20161011.055429 accepted/tizen/3.0/mobile/20161015.033833 accepted/tizen/3.0/tv/20161016.005205 accepted/tizen/3.0/wearable/20161015.083721 accepted/tizen/common/20161006.153623 accepted/tizen/ivi/20161006.080221 accepted/tizen/mobile/20161006.080120 accepted/tizen/tv/20161006.080147 accepted/tizen/wearable/20161006.080203 submit/tizen/20161006.010203 submit/tizen_3.0_ivi/20161010.000005 submit/tizen_3.0_mobile/20161015.000004 submit/tizen_3.0_tv/20161015.000004 submit/tizen_3.0_wearable/20161015.000004
authorSeonah Moon <seonah1.moon@samsung.com>
Wed, 5 Oct 2016 07:13:51 +0000 (16:13 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Wed, 5 Oct 2016 07:33:47 +0000 (16:33 +0900)
Change-Id: Iaa9959d394f05bc6e4b09ee6dd83c3cda0511dd0
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
include/mobileap_wifi.h
packaging/mobileap-agent.spec
src/mobileap_wifi.c

index 72c9fff..ad60d94 100644 (file)
@@ -47,26 +47,40 @@ typedef struct {
 } wifi_saved_settings;
 
 int _get_wifi_name_from_lease_info(const char *mac, char **name_buf);
+
+/* Wi-Fi tethering */
 mobile_ap_error_code_e _enable_wifi_tethering(Tethering *obj, gchar *ssid,
        gchar *passphrase, gchar* mode, gint channel, int hide_mode, int mac_filter, int max_sta, softap_security_type_e security_type);
+
 mobile_ap_error_code_e _disable_wifi_tethering(Tethering *obj);
 gboolean _is_trying_wifi_operation(void);
+
 mobile_ap_error_code_e _reload_softap_settings(Tethering *obj,
                gchar *ssid, gchar *key, gchar* mode, gint channel, gint hide_mode, gint mac_filter, gint max_sta, gint security_type);
+
 mobile_ap_error_code_e _reload_softap_settings_for_ap(Tethering *obj,
        gchar *ssid, gchar *key, gint hide_mode, gint security_type);
 
-/* Dbus method */
 mobile_ap_error_code_e _enable_wifi_ap(Tethering *obj, gchar *ssid,
                gchar *passphrase, int hide_mode,
                 softap_security_type_e security_type);
+
 mobile_ap_error_code_e _disable_wifi_ap(Tethering *obj);
+
 gboolean tethering_enable_wifi_tethering(Tethering *obj,
                GDBusMethodInvocation *context, gchar *ssid,
                gchar *key, gchar* mode, gint channel, gint visibility, gint mac_filter, gint max_sta, gint security_type);
 
+/* Soft AP */
 softap_settings_t  *_get_softap_settings();
 
+mobile_ap_error_code_e _enable_soft_ap(Softap *obj, gchar *ssid, gchar *passphrase, int hide_mode,
+               softap_security_type_e security_type);
+
+mobile_ap_error_code_e _disable_soft_ap(Softap *obj);
+
+
+/* Dbus method for Wi-Fi tethering APIs */
 gboolean tethering_disable_wifi_tethering(Tethering *obj,
                GDBusMethodInvocation *context);
 
index 51fb717..62d0d74 100644 (file)
@@ -1,6 +1,6 @@
 Name:          mobileap-agent
 Summary:       Mobile AP daemon for setting tethering environments
-Version:       1.0.75
+Version:       1.0.76
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index 4d441c6..60c19d0 100755 (executable)
@@ -42,12 +42,13 @@ static mobile_ap_error_code_e __get_passphrase(char *passphrase,
        unsigned int passphrase_size, unsigned int *passphrase_len);
 static mobile_ap_error_code_e __set_passphrase(const char *passphrase, const unsigned int size);
 static char *__get_key_manager_alias(const char* name);
-static int __turn_off_wifi(Tethering *obj);
+static int __turn_off_wifi(void *obj);
 static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size);
 
 static GDBusMethodInvocation *g_context = NULL;
 static guint wifi_recovery_timeout_id = 0;
 static gboolean prev_wifi_on = FALSE;
+static gboolean is_softap = FALSE;
 static wifi_saved_settings wifi_settings = {0, 0, 0,  NULL, NULL, NULL, 0};
 static softap_settings_t obj_softap_settings = {0, "", "", "", "", 0, 0, 0};
 
@@ -55,6 +56,7 @@ softap_settings_t *_get_softap_settings()
 {
        return &obj_softap_settings;
 }
+
 static void _wifi_direct_state_cb(int error_code, wifi_direct_device_state_e state, void *user_data)
 {
        bool wifi_state = false;
@@ -66,8 +68,8 @@ static void _wifi_direct_state_cb(int error_code, wifi_direct_device_state_e sta
                return;
        }
 
-       Tethering *obj = (Tethering *)user_data;
        int ret = 0;
+       void *obj = user_data;
 
        if (state != WIFI_DIRECT_DEVICE_STATE_DEACTIVATED) {
                ERR("Unknown state : %d\n", state);
@@ -95,17 +97,31 @@ static void _wifi_direct_state_cb(int error_code, wifi_direct_device_state_e sta
                return;
        }
 
-       ret = _enable_wifi_tethering(obj, wifi_settings.ssid, wifi_settings.key,
-                       wifi_settings.mode, wifi_settings.channel, wifi_settings.hide_mode, wifi_settings.mac_filter, wifi_settings.max_sta, wifi_settings.security_type);
-       if (ret != MOBILE_AP_ERROR_NONE) {
-               ERR("_enable_wifi_tethering is failed\n");
+       if (!is_softap) {
+               ret = _enable_wifi_tethering((Tethering *)obj, wifi_settings.ssid, wifi_settings.key,
+                               wifi_settings.mode, wifi_settings.channel, wifi_settings.hide_mode, wifi_settings.mac_filter, wifi_settings.max_sta, wifi_settings.security_type);
+               if (ret != MOBILE_AP_ERROR_NONE) {
+                       ERR("_enable_wifi_tethering is failed\n");
+               } else {
+                       tethering_emit_wifi_on((Tethering *)obj);
+                       _create_tethering_active_noti();
+               }
        } else {
-               tethering_emit_wifi_on(obj);
-               _create_tethering_active_noti();
+               ret = _enable_soft_ap((Softap *)obj, wifi_settings.ssid, wifi_settings.key,
+                               wifi_settings.hide_mode, wifi_settings.security_type);
+               if (ret != MOBILE_AP_ERROR_NONE)
+                       ERR("_enable_soft_ap is failed\n");
+               else
+                       softap_emit_soft_ap_on((Softap *)obj);
        }
 
 DONE:
-       tethering_complete_enable_wifi_tethering(obj, g_context, ret);
+       if (!is_softap) {
+               tethering_complete_enable_wifi_tethering((Tethering *)obj, g_context, ret);
+       } else {
+               softap_complete_enable((Softap *)obj, g_context, ret);
+               is_softap = FALSE;
+       }
        g_context = NULL;
 
        g_free(wifi_settings.ssid);
@@ -133,7 +149,7 @@ static void __wifi_deactivated_cb(wifi_error_e result, void *user_data)
                return;
        }
 
-       Tethering *obj = (Tethering *)user_data;
+       void  *obj = (Tethering *)user_data;
        int ret;
 
        if (result != WIFI_ERROR_NONE) {
@@ -144,19 +160,32 @@ static void __wifi_deactivated_cb(wifi_error_e result, void *user_data)
 
        DBG("Wi-Fi is turned off\n");
 
-       ret = _enable_wifi_tethering(obj, wifi_settings.ssid, wifi_settings.key,
-                       wifi_settings.mode, wifi_settings.channel, wifi_settings.hide_mode, wifi_settings.mac_filter, wifi_settings.max_sta, wifi_settings.security_type);
-       if (ret != MOBILE_AP_ERROR_NONE) {
-               ERR("_enable_wifi_tethering is failed\n");
+       if (!is_softap) {
+               ret = _enable_wifi_tethering(obj, wifi_settings.ssid, wifi_settings.key,
+                               wifi_settings.mode, wifi_settings.channel, wifi_settings.hide_mode, wifi_settings.mac_filter, wifi_settings.max_sta, wifi_settings.security_type);
+               if (ret != MOBILE_AP_ERROR_NONE) {
+                       ERR("_enable_wifi_tethering is failed\n");
+               } else {
+                       prev_wifi_on = TRUE;
+                       tethering_emit_wifi_on(obj);
+                       _create_tethering_active_noti();
+               }
        } else {
-               prev_wifi_on = TRUE;
-               tethering_emit_wifi_on(obj);
-               _create_tethering_active_noti();
+               ret = _enable_soft_ap((Softap *)obj, wifi_settings.ssid, wifi_settings.key,
+                               wifi_settings.hide_mode, wifi_settings.security_type);
+               if (ret != MOBILE_AP_ERROR_NONE)
+                       ERR("_enable_soft_ap is failed\n");
+               else
+                       softap_emit_soft_ap_on((Softap *)obj);
        }
 
 DONE:
-       tethering_complete_enable_wifi_tethering(obj, g_context, ret);
-
+       if (!is_softap) {
+               tethering_complete_enable_wifi_tethering((Tethering *)obj, g_context, ret);
+       } else {
+               softap_complete_enable((Softap *)obj, g_context, ret);
+               is_softap = FALSE;
+       }
        g_context = NULL;
 
        g_free(wifi_settings.ssid);
@@ -168,11 +197,11 @@ DONE:
        return;
 }
 
-static int __turn_off_wifi(Tethering *obj)
+static int __turn_off_wifi(void *obj)
 {
        int ret;
 
-       ret = wifi_deactivate(__wifi_deactivated_cb, (void *)obj);
+       ret = wifi_deactivate(__wifi_deactivated_cb, obj);
        if (ret != WIFI_ERROR_NONE) {
                ERR("wifi_deactivate() is failed : %d\n", ret);
                return MOBILE_AP_ERROR_INTERNAL;
@@ -230,7 +259,7 @@ static gboolean __is_wifi_direct_on(void)
        return wifi_direct_state != 0 ? TRUE : FALSE;
 }
 
-static int __turn_off_wifi_direct(Tethering *obj)
+static int __turn_off_wifi_direct(void *obj)
 {
        int ret;
 
@@ -240,7 +269,7 @@ static int __turn_off_wifi_direct(Tethering *obj)
                return MOBILE_AP_ERROR_INTERNAL;
        }
 
-       ret = wifi_direct_set_device_state_changed_cb(_wifi_direct_state_cb, (void *)obj);
+       ret = wifi_direct_set_device_state_changed_cb(_wifi_direct_state_cb, obj);
        if (ret < 0) {
                ERR("wifi_direct_set_device_state_changed_cb() is failed : %d\n", ret);
                ret = wifi_direct_deinitialize();
@@ -1372,27 +1401,78 @@ gboolean softap_enable(Softap *obj, GDBusMethodInvocation *context,
 {
        mobile_ap_error_code_e ret = MOBILE_AP_ERROR_NONE;
        gboolean ret_val = FALSE;
+       bool wifi_state = false;
 
        DBG("+");
 
        g_assert(obj != NULL);
        g_assert(context != NULL);
 
+       if (g_context) {
+               DBG("It is turnning on\n");
+               softap_complete_enable(obj, g_context, MOBILE_AP_ERROR_IN_PROGRESS);
+               return FALSE;
+       }
+       g_context = context;
+       is_softap = TRUE;
+
+       wifi_settings.ssid = g_strdup(ssid);
+       if (security_type == SOFTAP_SECURITY_TYPE_WPA2_PSK) {
+               wifi_settings.key = g_strdup(key);
+               wifi_settings.security_type = SOFTAP_SECURITY_TYPE_WPA2_PSK;
+       } else {
+               wifi_settings.security_type = SOFTAP_SECURITY_TYPE_OPEN;
+       }
+       wifi_settings.hide_mode = (!hide_mode);
+       wifi_settings.channel = MOBILE_AP_WIFI_CHANNEL;
+       wifi_settings.max_sta = MOBILE_AP_MAX_WIFI_STA;
+
        if (wifi_recovery_timeout_id) {
                DBG("Wi-Fi recovery is cancelled\n");
                g_source_remove(wifi_recovery_timeout_id);
                wifi_recovery_timeout_id = 0;
        }
 
+       if (__is_wifi_direct_on() == TRUE) {
+               DBG("Wi-Fi and Wi-Fi direct are turned on\n");
+               if (__turn_off_wifi_direct(obj) != MOBILE_AP_ERROR_NONE) {
+                       ERR("_turn_off_wifi_direct is failed\n");
+                       ret = MOBILE_AP_ERROR_INTERNAL;
+                       goto DONE;
+               }
+
+               return TRUE;
+       }
+
+       wifi_is_activated(&wifi_state);
+       if (wifi_state == true) {
+               DBG("Wi-Fi is turned on\n");
+               if (__turn_off_wifi(obj) != MOBILE_AP_ERROR_NONE) {
+                       ERR("_turn_off_wifi is failed\n");
+                       ret = MOBILE_AP_ERROR_INTERNAL;
+                       goto DONE;
+               }
+
+               return TRUE;
+       }
        ret = _enable_soft_ap(obj, ssid, key, !hide_mode,
                        (softap_security_type_e)security_type);
        if (ret != MOBILE_AP_ERROR_NONE) {
-               ERR("_enable_wifi_tethering is failed\n");
+               ERR("_enable_soft_ap is failed\n");
        } else {
                softap_emit_soft_ap_on(obj);
                ret_val = TRUE;
        }
-       softap_complete_enable(obj, context, ret);
+
+DONE:
+       softap_complete_enable(obj, g_context, ret);
+       is_softap = FALSE;
+       g_context = NULL;
+
+       g_free(wifi_settings.ssid);
+       g_free(wifi_settings.key);
+       memset(&wifi_settings, 0, sizeof(wifi_settings));
+
        return ret_val;
 }