} 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);
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};
{
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;
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);
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);
return;
}
- Tethering *obj = (Tethering *)user_data;
+ void *obj = (Tethering *)user_data;
int ret;
if (result != WIFI_ERROR_NONE) {
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);
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;
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;
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();
{
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;
}