cinterion: avoid after-power-up step

Split the after power up step into:
 * querying supported functionality status during the first power-down request.
 * querying supported networks during supported modes loading.
This commit is contained in:
Aleksander Morgado
2012-01-14 22:53:11 +01:00
parent d76f545322
commit 15f2c56f89

View File

@@ -48,7 +48,7 @@ struct _MMBroadbandModemCinterionPrivate {
}; };
/*****************************************************************************/ /*****************************************************************************/
/* MODEM POWER UP */ /* MODEM POWER DOWN */
static gboolean static gboolean
modem_power_down_finish (MMIfaceModem *self, modem_power_down_finish (MMIfaceModem *self,
@@ -60,48 +60,33 @@ modem_power_down_finish (MMIfaceModem *self,
} }
static void static void
modem_power_down (MMIfaceModem *self, send_sleep_mode_command (MMBroadbandModemCinterion *self,
GAsyncReadyCallback callback, GSimpleAsyncResult *operation_result)
gpointer user_data)
{ {
MMBroadbandModemCinterion *cinterion = MM_BROADBAND_MODEM_CINTERION (self); if (self->priv->sleep_mode_cmd &&
GSimpleAsyncResult *result; self->priv->sleep_mode_cmd[0])
if (cinterion->priv->sleep_mode_cmd)
mm_base_modem_at_command_ignore_reply (MM_BASE_MODEM (self), mm_base_modem_at_command_ignore_reply (MM_BASE_MODEM (self),
cinterion->priv->sleep_mode_cmd, self->priv->sleep_mode_cmd,
5); 5);
result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
modem_power_down);
g_simple_async_result_set_op_res_gboolean (result, TRUE);
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
} }
/*****************************************************************************/ static void
/* AFTER POWER UP */ supported_functionality_status_query_ready (MMBroadbandModemCinterion *self,
static gboolean
modem_after_power_up_finish (MMIfaceModem *self,
GAsyncResult *res, GAsyncResult *res,
GError **error) GSimpleAsyncResult *operation_result)
{ {
return !!mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, error); const gchar *response;
} GError *error = NULL;
static gboolean g_assert (self->priv->sleep_mode_cmd == NULL);
parse_supported_functionality_status (MMBroadbandModemCinterion *self,
gpointer none, response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
const gchar *command, if (!response) {
const gchar *response, mm_warn ("Couldn't query supported functionality status: '%s'",
gboolean last_command, error->message);
const GError *error, g_error_free (error);
GVariant **result, self->priv->sleep_mode_cmd = g_strdup ("");
GError **result_error) } else {
{
/* We need to get which power-off command to use to put the modem in low /* We need to get which power-off command to use to put the modem in low
* power mode (with serial port open for AT commands, but with RF switched * power mode (with serial port open for AT commands, but with RF switched
* off). According to the documentation of various Cinterion modems, some * off). According to the documentation of various Cinterion modems, some
@@ -112,7 +97,6 @@ parse_supported_functionality_status (MMBroadbandModemCinterion *self,
* So, just look for '4' in the reply; if not found, look for '7', and if * So, just look for '4' in the reply; if not found, look for '7', and if
* not found, report warning and don't use any. * not found, report warning and don't use any.
*/ */
g_free (self->priv->sleep_mode_cmd);
if (strstr (response, "4") != NULL) { if (strstr (response, "4") != NULL) {
mm_dbg ("Device supports CFUN=4 sleep mode"); mm_dbg ("Device supports CFUN=4 sleep mode");
self->priv->sleep_mode_cmd = g_strdup ("+CFUN=4"); self->priv->sleep_mode_cmd = g_strdup ("+CFUN=4");
@@ -121,79 +105,136 @@ parse_supported_functionality_status (MMBroadbandModemCinterion *self,
self->priv->sleep_mode_cmd = g_strdup ("+CFUN=7"); self->priv->sleep_mode_cmd = g_strdup ("+CFUN=7");
} else { } else {
mm_warn ("Unknown functionality mode to go into sleep mode"); mm_warn ("Unknown functionality mode to go into sleep mode");
self->priv->sleep_mode_cmd = NULL; self->priv->sleep_mode_cmd = g_strdup ("");
}
} }
/* Keep on with next command */ send_sleep_mode_command (self, operation_result);
return FALSE;
} }
static gboolean static void
parse_supported_networks (MMBroadbandModemCinterion *self, modem_power_down (MMIfaceModem *self,
gpointer none, GAsyncReadyCallback callback,
const gchar *command, gpointer user_data)
const gchar *response,
gboolean last_command,
const GError *error,
GVariant **result,
GError **result_error)
{ {
MMBroadbandModemCinterion *cinterion = MM_BROADBAND_MODEM_CINTERION (self);
GSimpleAsyncResult *result;
result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
modem_power_down);
/* If sleep command already decided, use it. */
if (cinterion->priv->sleep_mode_cmd)
send_sleep_mode_command (MM_BROADBAND_MODEM_CINTERION (self),
result);
else
mm_base_modem_at_command (
MM_BASE_MODEM (self),
"+CFUN=?",
3,
FALSE,
NULL, /* cancellable */
(GAsyncReadyCallback)supported_functionality_status_query_ready,
result);
}
/*****************************************************************************/
/* SUPPORTED MODES */
static MMModemMode
load_supported_modes_finish (MMIfaceModem *self,
GAsyncResult *res,
GError **error)
{
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return MM_MODEM_MODE_NONE;
return (MMModemMode) GPOINTER_TO_UINT (g_simple_async_result_get_op_res_gpointer (
G_SIMPLE_ASYNC_RESULT (res)));
}
static void
supported_networks_query_ready (MMBroadbandModemCinterion *self,
GAsyncResult *res,
GSimpleAsyncResult *operation_result)
{
const gchar *response;
GError *error = NULL;
MMModemMode mode;
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!response) {
/* Let the error be critical. */
g_simple_async_result_take_error (operation_result, error);
g_simple_async_result_complete (operation_result);
g_object_unref (operation_result);
return;
}
/* Note: Documentation says that AT+WS46=? is replied with '+WS46:' followed /* Note: Documentation says that AT+WS46=? is replied with '+WS46:' followed
* by a list of supported network modes between parenthesis, but the EGS5 * by a list of supported network modes between parenthesis, but the EGS5
* used to test this didn't use the 'WS46:' prefix. Also, more than one * used to test this didn't use the 'WS46:' prefix. Also, more than one
* numeric ID may appear in the list, that's why they are checked * numeric ID may appear in the list, that's why they are checked
* separately. * */ * separately. */
mode = MM_MODEM_MODE_NONE;
if (strstr (response, "12") != NULL) { if (strstr (response, "12") != NULL) {
mm_dbg ("Device allows 2G-only network mode"); mm_dbg ("Device allows 2G-only network mode");
self->priv->only_geran = TRUE; self->priv->only_geran = TRUE;
mode |= MM_MODEM_MODE_2G;
} }
if (strstr (response, "22") != NULL) { if (strstr (response, "22") != NULL) {
mm_dbg ("Device allows 3G-only network mode"); mm_dbg ("Device allows 3G-only network mode");
self->priv->only_utran = TRUE; self->priv->only_utran = TRUE;
mode |= MM_MODEM_MODE_3G;
} }
if (strstr (response, "25") != NULL) { if (strstr (response, "25") != NULL) {
mm_dbg ("Device allows 2G/3G network mode"); mm_dbg ("Device allows 2G/3G network mode");
self->priv->both_geran_utran = TRUE; self->priv->both_geran_utran = TRUE;
mode |= (MM_MODEM_MODE_2G | MM_MODEM_MODE_3G);
} }
/* If no expected ID found, error */ /* If no expected ID found, error */
if (!self->priv->only_geran && if (mode == MM_MODEM_MODE_NONE)
!self->priv->only_utran && g_simple_async_result_set_error (operation_result,
!self->priv->both_geran_utran) { MM_CORE_ERROR,
mm_warn ("Invalid list of supported networks: '%s'", response);
*result_error = g_error_new (MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"Invalid list of supported networks: '%s'", "Invalid list of supported networks: '%s'",
response); response);
return FALSE; else
} g_simple_async_result_set_op_res_gpointer (operation_result,
GUINT_TO_POINTER (mode),
NULL);
/* Keep on with next command */ g_simple_async_result_complete (operation_result);
return FALSE; g_object_unref (operation_result);
} }
static const MMBaseModemAtCommand after_power_up_commands[] = {
{ "+CFUN=?", 3, FALSE, (MMBaseModemAtResponseProcessor)parse_supported_functionality_status },
{ "+WS46=?", 3, FALSE, (MMBaseModemAtResponseProcessor)parse_supported_networks },
{ NULL }
};
static void static void
modem_after_power_up (MMIfaceModem *self, load_supported_modes (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
mm_base_modem_at_sequence ( GSimpleAsyncResult *result;
MM_BASE_MODEM (self),
after_power_up_commands, result = g_simple_async_result_new (G_OBJECT (self),
NULL, /* response_processor_context */
NULL, /* response_processor_context_free */
NULL, /* cancellable */
callback, callback,
user_data); user_data,
load_supported_modes);
mm_base_modem_at_command (
MM_BASE_MODEM (self),
"+WS46=?",
3,
FALSE,
NULL, /* cancellable */
(GAsyncReadyCallback)supported_networks_query_ready,
result);
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -287,10 +328,10 @@ finalize (GObject *object)
static void static void
iface_modem_init (MMIfaceModem *iface) iface_modem_init (MMIfaceModem *iface)
{ {
iface->load_supported_modes = load_supported_modes;
iface->load_supported_modes_finish = load_supported_modes_finish;
iface->setup_flow_control = setup_flow_control; iface->setup_flow_control = setup_flow_control;
iface->setup_flow_control_finish = setup_flow_control_finish; iface->setup_flow_control_finish = setup_flow_control_finish;
iface->modem_after_power_up = modem_after_power_up;
iface->modem_after_power_up_finish = modem_after_power_up_finish;
iface->modem_power_down = modem_power_down; iface->modem_power_down = modem_power_down;
iface->modem_power_down_finish = modem_power_down_finish; iface->modem_power_down_finish = modem_power_down_finish;
} }