cinterion: start porting features from the old implementation
Currently ported: * Power Down * Flow control * After power up setup: ** Available functionality status ** Supported networks
This commit is contained in:
@@ -27,15 +27,224 @@
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-serial-parsers.h"
|
||||
#include "mm-log.h"
|
||||
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-iface-modem.h"
|
||||
#include "mm-base-modem-at.h"
|
||||
#include "mm-broadband-modem-cinterion.h"
|
||||
|
||||
G_DEFINE_TYPE (MMBroadbandModemCinterion, mm_broadband_modem_cinterion, MM_TYPE_BROADBAND_MODEM)
|
||||
static void iface_modem_init (MMIfaceModem *iface);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMBroadbandModemCinterion, mm_broadband_modem_cinterion, MM_TYPE_BROADBAND_MODEM, 0,
|
||||
G_IMPLEMENT_INTERFACE (MM_TYPE_IFACE_MODEM, iface_modem_init));
|
||||
|
||||
struct _MMBroadbandModemCinterionPrivate {
|
||||
gpointer dummy;
|
||||
/* Command to go into sleep mode */
|
||||
gchar *sleep_mode_cmd;
|
||||
|
||||
/* Supported networks */
|
||||
gboolean only_geran;
|
||||
gboolean only_utran;
|
||||
gboolean both_geran_utran;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* MODEM POWER UP */
|
||||
|
||||
static gboolean
|
||||
modem_power_down_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
/* Ignore errors */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
modem_power_down (MMIfaceModem *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMBroadbandModemCinterion *cinterion = MM_BROADBAND_MODEM_CINTERION (self);
|
||||
GSimpleAsyncResult *result;
|
||||
|
||||
if (cinterion->priv->sleep_mode_cmd)
|
||||
mm_base_modem_at_command_ignore_reply (MM_BASE_MODEM (self),
|
||||
cinterion->priv->sleep_mode_cmd,
|
||||
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);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* AFTER POWER UP */
|
||||
|
||||
static gboolean
|
||||
modem_after_power_up_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return !!mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_supported_functionality_status (MMBroadbandModemCinterion *self,
|
||||
gpointer none,
|
||||
const gchar *command,
|
||||
const gchar *response,
|
||||
const GError *error,
|
||||
GVariant **result,
|
||||
GError **result_error)
|
||||
{
|
||||
/* 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
|
||||
* off). According to the documentation of various Cinterion modems, some
|
||||
* support AT+CFUN=4 (HC25) and those which don't support it can use
|
||||
* AT+CFUN=7 (CYCLIC SLEEP mode with 2s timeout after last character
|
||||
* received in the serial port).
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
g_free (self->priv->sleep_mode_cmd);
|
||||
if (strstr (response, "4") != NULL) {
|
||||
mm_dbg ("Device supports CFUN=4 sleep mode");
|
||||
self->priv->sleep_mode_cmd = g_strdup ("+CFUN=4");
|
||||
} else if (strstr (response, "7") != NULL) {
|
||||
mm_dbg ("Device supports CFUN=7 sleep mode");
|
||||
self->priv->sleep_mode_cmd = g_strdup ("+CFUN=7");
|
||||
} else {
|
||||
mm_warn ("Unknown functionality mode to go into sleep mode");
|
||||
self->priv->sleep_mode_cmd = NULL;
|
||||
}
|
||||
|
||||
/* Keep on with next command */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_supported_networks (MMBroadbandModemCinterion *self,
|
||||
gpointer none,
|
||||
const gchar *command,
|
||||
const gchar *response,
|
||||
const GError *error,
|
||||
GVariant **result,
|
||||
GError **result_error)
|
||||
{
|
||||
/* Note: Documentation says that AT+WS46=? is replied with '+WS46:' followed
|
||||
* 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
|
||||
* numeric ID may appear in the list, that's why they are checked
|
||||
* separately. * */
|
||||
|
||||
if (strstr (response, "12") != NULL) {
|
||||
mm_dbg ("Device allows 2G-only network mode");
|
||||
self->priv->only_geran = TRUE;
|
||||
}
|
||||
|
||||
if (strstr (response, "22") != NULL) {
|
||||
mm_dbg ("Device allows 3G-only network mode");
|
||||
self->priv->only_utran = TRUE;
|
||||
}
|
||||
|
||||
if (strstr (response, "25") != NULL) {
|
||||
mm_dbg ("Device allows 2G/3G network mode");
|
||||
self->priv->both_geran_utran = TRUE;
|
||||
}
|
||||
|
||||
/* If no expected ID found, error */
|
||||
if (!self->priv->only_geran &&
|
||||
!self->priv->only_utran &&
|
||||
!self->priv->both_geran_utran) {
|
||||
mm_warn ("Invalid list of supported networks: '%s'", response);
|
||||
*result_error = g_error_new (MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"Invalid list of supported networks: '%s'",
|
||||
response);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Keep on with next command */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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
|
||||
modem_after_power_up (MMIfaceModem *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
mm_base_modem_at_sequence (
|
||||
MM_BASE_MODEM (self),
|
||||
after_power_up_commands,
|
||||
NULL, /* response_processor_context */
|
||||
NULL, /* response_processor_context_free */
|
||||
NULL, /* cancellable */
|
||||
callback,
|
||||
user_data);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* FLOW CONTROL */
|
||||
|
||||
static gboolean
|
||||
modem_flow_control_finish (MMIfaceModem *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
|
||||
}
|
||||
|
||||
static void
|
||||
modem_flow_control_ready (MMBroadbandModemCinterion *self,
|
||||
GAsyncResult *res,
|
||||
GSimpleAsyncResult *operation_result)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error))
|
||||
/* Let the error be critical. We DO need RTS/CTS in order to have
|
||||
* proper modem disabling. */
|
||||
g_simple_async_result_take_error (operation_result, error);
|
||||
else
|
||||
g_simple_async_result_set_op_res_gboolean (operation_result, TRUE);
|
||||
|
||||
g_simple_async_result_complete (operation_result);
|
||||
g_object_unref (operation_result);
|
||||
}
|
||||
|
||||
static void
|
||||
modem_flow_control (MMIfaceModem *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GSimpleAsyncResult *result;
|
||||
|
||||
result = g_simple_async_result_new (G_OBJECT (self),
|
||||
callback,
|
||||
user_data,
|
||||
modem_flow_control);
|
||||
|
||||
/* We need to enable RTS/CTS so that CYCLIC SLEEP mode works */
|
||||
mm_base_modem_at_command (MM_BASE_MODEM (self),
|
||||
"\\Q3",
|
||||
3,
|
||||
FALSE,
|
||||
NULL, /* cancellable */
|
||||
(GAsyncReadyCallback)modem_flow_control_ready,
|
||||
result);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
MMBroadbandModemCinterion *
|
||||
@@ -54,7 +263,6 @@ mm_broadband_modem_cinterion_new (const gchar *device,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mm_broadband_modem_cinterion_init (MMBroadbandModemCinterion *self)
|
||||
{
|
||||
@@ -67,9 +275,23 @@ mm_broadband_modem_cinterion_init (MMBroadbandModemCinterion *self)
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (object);
|
||||
|
||||
g_free (self->priv->sleep_mode_cmd);
|
||||
|
||||
G_OBJECT_CLASS (mm_broadband_modem_cinterion_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
iface_modem_init (MMIfaceModem *iface)
|
||||
{
|
||||
iface->modem_flow_control = modem_flow_control;
|
||||
iface->modem_flow_control_finish = modem_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_finish = modem_power_down_finish;
|
||||
}
|
||||
|
||||
static void
|
||||
mm_broadband_modem_cinterion_class_init (MMBroadbandModemCinterionClass *klass)
|
||||
|
Reference in New Issue
Block a user