#define WLAN_DRIVER_SCRIPT "/usr/bin/wlan.sh"
+static gboolean power_in_progress = FALSE;
+static gboolean fm_waiting = FALSE;
-static gboolean __netconfig_wifi_enable_technology(void)
+static void __netconfig_wifi_technology_reply(DBusPendingCall *call, void *data)
{
- DBusMessage *reply = NULL;
- char param1[] = "string:Powered";
- char param2[] = "variant:boolean:true";
- char *param_array[] = {NULL, NULL, NULL};
+ DBusMessage *message;
- param_array[0] = param1;
- param_array[1] = param2;
+ message = dbus_pending_call_steal_reply(call);
- reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX,
- CONNMAN_TECHNOLOGY_INTERFACE, "SetProperty", param_array);
+ if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) {
+ ERR("%s", dbus_message_get_error_name(message));
- if (reply == NULL) {
- ERR("Error! Request failed");
- return FALSE;
+ if (dbus_message_is_error(message,
+ CONNMAN_ERROR_INTERFACE ".AlreadyEnabled") == TRUE) {
+ netconfig_wifi_update_power_state(TRUE);
+ power_in_progress = FALSE;
+ } else if (dbus_message_is_error(message,
+ CONNMAN_ERROR_INTERFACE ".AlreadyDisabled") == TRUE) {
+ netconfig_wifi_update_power_state(FALSE);
+ power_in_progress = FALSE;
+ }
+ } else {
+ DBG("Successfully requested");
}
- dbus_message_unref(reply);
+ dbus_message_unref(message);
+ dbus_pending_call_unref(call);
+}
- return TRUE;
+static gboolean __netconfig_wifi_enable_technology(void)
+{
+ gboolean reply = FALSE;
+ char param0[] = "string:Powered";
+ char param1[] = "variant:boolean:true";
+ char *param_array[] = { NULL, NULL, NULL };
+
+ param_array[0] = param0;
+ param_array[1] = param1;
+
+ reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
+ CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE,
+ "SetProperty", param_array, __netconfig_wifi_technology_reply);
+
+ if (reply != TRUE)
+ ERR("Fail to enable Wi-Fi");
+
+ return reply;
}
static gboolean __netconfig_wifi_disable_technology(void)
{
- DBusMessage *reply = NULL;
- char param1[] = "string:Powered";
- char param2[] = "variant:boolean:false";
- char *param_array[] = {NULL, NULL, NULL};
+ gboolean reply = FALSE;
+ char param0[] = "string:Powered";
+ char param1[] = "variant:boolean:false";
+ char *param_array[] = { NULL, NULL, NULL };
- param_array[0] = param1;
- param_array[1] = param2;
+ param_array[0] = param0;
+ param_array[1] = param1;
- reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX,
- CONNMAN_TECHNOLOGY_INTERFACE, "SetProperty", param_array);
+ reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
+ CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE,
+ "SetProperty", param_array, __netconfig_wifi_technology_reply);
- if (reply == NULL) {
- ERR("Error! Request failed");
- return FALSE;
- }
-
- dbus_message_unref(reply);
+ if (reply != TRUE)
+ ERR("Fail to disable Wi-Fi");
- return TRUE;
+ return reply;
}
static gboolean __netconfig_wifi_load_driver(void)
if (device_state == WIFI_DIRECT_DEVICE_STATE_DEACTIVATED) {
if (__netconfig_wifi_try_to_load_driver() < 0) {
+ power_in_progress = FALSE;
/* TODO: error report */
return;
}
-
- netconfig_wifi_notify_power_completed(TRUE);
}
}
}
if (netconfig_is_wifi_direct_on() == TRUE) {
- if (__netconfig_wifi_direct_power_off() == TRUE)
+ if (__netconfig_wifi_direct_power_off() == TRUE) {
+ power_in_progress = TRUE;
return -EINPROGRESS;
- else
+ } else
return -EBUSY;
}
return -EIO;
}
- __netconfig_wifi_enable_technology();
+ if (__netconfig_wifi_enable_technology() != TRUE) {
+ netconfig_wifi_remove_driver();
+ return -EIO;
+ }
+
+ power_in_progress = TRUE;
return 0;
}
netconfig_wifi_statistics_update_powered_off();
- __netconfig_wifi_disable_technology();
+ if (__netconfig_wifi_disable_technology() != TRUE)
+ return FALSE;
+
+ power_in_progress = TRUE;
return TRUE;
}
int wifi_state = 0;
static gboolean powered_off_by_flightmode = FALSE;
+ if (power_in_progress) {
+ fm_waiting = TRUE;
+ return;
+ }
+
+ fm_waiting = FALSE;
+
vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &value);
vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
prev_state = value;
}
+void netconfig_set_power_in_progress(gboolean in_progress)
+{
+ power_in_progress = in_progress;
+}
+
+void netconfig_check_fm_waiting(void)
+{
+ if (fm_waiting)
+ __netconfig_wifi_airplane_mode(NULL, NULL);
+}
+
void netconfig_wifi_power_configuration(void)
{
int wifi_last_power_state = 0;
return FALSE;
}
+ if (power_in_progress) {
+ netconfig_error_wifi_driver_failed(error);
+ return FALSE;
+ }
+
err = __netconfig_wifi_try_to_load_driver();
if (err < 0) {
if (err == -EINPROGRESS)
g_return_val_if_fail(wifi != NULL, FALSE);
+ if (power_in_progress) {
+ netconfig_error_wifi_driver_failed(error);
+ return FALSE;
+ }
+
if (__netconfig_wifi_try_to_remove_driver() != TRUE) {
netconfig_error_wifi_driver_failed(error);