gsm: implement enable/connecting/disconnecting state handling
And consolidate generic port enable code in one place since pretty much every modem needs that.
This commit is contained in:
@@ -288,33 +288,30 @@ mm_hso_modem_authenticate (MMModemHso *self,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
generic_done (MMModem *modem, GError *error, gpointer user_data)
|
enable_done (MMModem *modem, GError *error, gpointer user_data)
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error)
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (modem), error, info);
|
||||||
info->error = g_error_copy (error);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parent_enable_done (MMModem *modem, GError *error, gpointer user_data)
|
parent_enable_done (MMModem *modem, GError *error, gpointer user_data)
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
MMGenericGsm *self = MM_GENERIC_GSM (modem);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (self, error, info);
|
||||||
mm_callback_info_schedule (info);
|
return;
|
||||||
} else {
|
|
||||||
/* HSO needs manual PIN checking */
|
|
||||||
mm_generic_gsm_check_pin (MM_GENERIC_GSM (modem), generic_done, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* HSO needs manual PIN checking */
|
||||||
|
mm_generic_gsm_check_pin (self, enable_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable (MMModem *modem,
|
enable (MMModem *modem, MMModemFn callback, gpointer user_data)
|
||||||
MMModemFn callback,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
MMModem *parent_modem_iface;
|
MMModem *parent_modem_iface;
|
||||||
MMCallbackInfo *info;
|
MMCallbackInfo *info;
|
||||||
@@ -324,6 +321,16 @@ enable (MMModem *modem,
|
|||||||
parent_modem_iface->enable (info->modem, parent_enable_done, info);
|
parent_modem_iface->enable (info->modem, parent_enable_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
parent_disable_done (MMModem *modem, GError *error, gpointer user_data)
|
||||||
|
{
|
||||||
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
info->error = g_error_copy (error);
|
||||||
|
mm_callback_info_schedule (info);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disable_done (MMModem *modem,
|
disable_done (MMModem *modem,
|
||||||
GError *error,
|
GError *error,
|
||||||
@@ -334,7 +341,7 @@ disable_done (MMModem *modem,
|
|||||||
|
|
||||||
/* Do the normal disable stuff */
|
/* Do the normal disable stuff */
|
||||||
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem));
|
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem));
|
||||||
parent_modem_iface->disable (info->modem, generic_done, info);
|
parent_modem_iface->disable (info->modem, parent_disable_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -63,7 +63,7 @@ typedef struct {
|
|||||||
guint reg_id;
|
guint reg_id;
|
||||||
gboolean have_emrdy;
|
gboolean have_emrdy;
|
||||||
char *network_device;
|
char *network_device;
|
||||||
MMCallbackInfo *do_connect_done_info;
|
MMCallbackInfo *pending_connect_info;
|
||||||
int account_index;
|
int account_index;
|
||||||
int network_mode;
|
int network_mode;
|
||||||
const char *username;
|
const char *username;
|
||||||
@@ -322,15 +322,7 @@ mbm_enable_done (MMSerialPort *port,
|
|||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error)
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
info->error = g_error_copy (error);
|
|
||||||
else {
|
|
||||||
/* We're enabled; update our state */
|
|
||||||
mm_generic_gsm_update_enabled_state (MM_GENERIC_GSM (info->modem),
|
|
||||||
FALSE,
|
|
||||||
MM_MODEM_STATE_REASON_NONE);
|
|
||||||
}
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -345,6 +337,7 @@ mbm_enap0_done (MMSerialPort *port,
|
|||||||
|
|
||||||
if (!priv->network_mode)
|
if (!priv->network_mode)
|
||||||
priv->network_mode = MBM_NETWORK_MODE_ANY;
|
priv->network_mode = MBM_NETWORK_MODE_ANY;
|
||||||
|
|
||||||
command = g_strdup_printf ("+CFUN=%d", priv->network_mode);
|
command = g_strdup_printf ("+CFUN=%d", priv->network_mode);
|
||||||
mm_serial_port_queue_command (port, command, 3, mbm_enable_done, info);
|
mm_serial_port_queue_command (port, command, 3, mbm_enable_done, info);
|
||||||
g_free (command);
|
g_free (command);
|
||||||
@@ -360,19 +353,20 @@ mbm_init_done (MMSerialPort *port,
|
|||||||
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (info->modem);
|
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (info->modem);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
mm_callback_info_schedule (info);
|
return;
|
||||||
} else {
|
|
||||||
if (!priv->network_mode)
|
|
||||||
priv->network_mode = MBM_NETWORK_MODE_ANY;
|
|
||||||
mm_serial_port_queue_command (port, "*ENAP=0", 3, mbm_enap0_done, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!priv->network_mode)
|
||||||
|
priv->network_mode = MBM_NETWORK_MODE_ANY;
|
||||||
|
|
||||||
|
mm_serial_port_queue_command (port, "*ENAP=0", 3, mbm_enap0_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_init (MMSerialPort *port, gpointer user_data)
|
do_init (MMSerialPort *port, MMCallbackInfo *info)
|
||||||
{
|
{
|
||||||
mm_serial_port_queue_command (port, "&F E0 V1 X4 &C1 +CMEE=1", 3, mbm_init_done, user_data);
|
mm_serial_port_queue_command (port, "&F E0 V1 X4 &C1 +CMEE=1", 3, mbm_init_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -391,31 +385,21 @@ mbm_emrdy_done (MMSerialPort *port,
|
|||||||
} else
|
} else
|
||||||
priv->have_emrdy = TRUE;
|
priv->have_emrdy = TRUE;
|
||||||
|
|
||||||
do_init (port, user_data);
|
do_init (port, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable (MMModem *modem,
|
do_enable (MMGenericGsm *self, MMModemFn callback, gpointer user_data)
|
||||||
MMModemFn callback,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (modem);
|
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (self);
|
||||||
MMCallbackInfo *info;
|
MMCallbackInfo *info;
|
||||||
MMSerialPort *primary;
|
MMSerialPort *primary;
|
||||||
|
|
||||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
|
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||||
|
|
||||||
info = mm_callback_info_new (modem, callback, user_data);
|
primary = mm_generic_gsm_get_port (self, MM_PORT_TYPE_PRIMARY);
|
||||||
|
|
||||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
|
||||||
g_assert (primary);
|
g_assert (primary);
|
||||||
|
|
||||||
if (!mm_serial_port_open (primary, &info->error)) {
|
|
||||||
g_assert (info->error);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (priv->have_emrdy) {
|
if (priv->have_emrdy) {
|
||||||
/* Modem is ready, no need to check EMRDY */
|
/* Modem is ready, no need to check EMRDY */
|
||||||
do_init (primary, info);
|
do_init (primary, info);
|
||||||
@@ -423,27 +407,14 @@ enable (MMModem *modem,
|
|||||||
mm_serial_port_queue_command (primary, "*EMRDY?", 5, mbm_emrdy_done, info);
|
mm_serial_port_queue_command (primary, "*EMRDY?", 5, mbm_emrdy_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
parent_disable_done (MMModem *modem, GError *error, gpointer user_data)
|
|
||||||
{
|
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
|
||||||
|
|
||||||
if (error)
|
|
||||||
info->error = g_error_copy (error);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disable (MMModem *modem,
|
disable (MMModem *modem,
|
||||||
MMModemFn callback,
|
MMModemFn callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMModem *parent_modem_iface;
|
MMModem *parent_modem_iface;
|
||||||
MMCallbackInfo *info;
|
|
||||||
MMSerialPort *primary;
|
MMSerialPort *primary;
|
||||||
|
|
||||||
info = mm_callback_info_new (modem, callback, user_data);
|
|
||||||
|
|
||||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||||
g_assert (primary);
|
g_assert (primary);
|
||||||
|
|
||||||
@@ -452,7 +423,7 @@ disable (MMModem *modem,
|
|||||||
mm_serial_port_queue_command (primary, "+CMER=0", 5, NULL, NULL);
|
mm_serial_port_queue_command (primary, "+CMER=0", 5, NULL, NULL);
|
||||||
|
|
||||||
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem));
|
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem));
|
||||||
parent_modem_iface->disable (modem, parent_disable_done, info);
|
parent_modem_iface->disable (modem, callback, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -464,8 +435,10 @@ do_connect (MMModem *modem,
|
|||||||
MMCallbackInfo *info;
|
MMCallbackInfo *info;
|
||||||
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (modem);
|
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (modem);
|
||||||
|
|
||||||
|
mm_modem_set_state (modem, MM_MODEM_STATE_CONNECTING, MM_MODEM_STATE_REASON_NONE);
|
||||||
|
|
||||||
info = mm_callback_info_new (modem, callback, user_data);
|
info = mm_callback_info_new (modem, callback, user_data);
|
||||||
priv->do_connect_done_info = info;
|
priv->pending_connect_info = info;
|
||||||
|
|
||||||
mbm_modem_authenticate (MM_MODEM_MBM (modem), priv->username, priv->password, info);
|
mbm_modem_authenticate (MM_MODEM_MBM (modem), priv->username, priv->password, info);
|
||||||
}
|
}
|
||||||
@@ -478,10 +451,15 @@ disconnect (MMModem *modem,
|
|||||||
MMCallbackInfo *info;
|
MMCallbackInfo *info;
|
||||||
MMSerialPort *primary;
|
MMSerialPort *primary;
|
||||||
|
|
||||||
info = mm_callback_info_new (modem, callback, user_data);
|
mm_modem_set_state (modem, MM_MODEM_STATE_DISCONNECTING, MM_MODEM_STATE_REASON_NONE);
|
||||||
|
|
||||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||||
g_assert (primary);
|
g_assert (primary);
|
||||||
mm_serial_port_queue_command (primary, "AT*ENAP=0", 3, NULL, info);
|
mm_serial_port_queue_command (primary, "*ENAP=0", 3, NULL, NULL);
|
||||||
|
|
||||||
|
mm_generic_gsm_update_enabled_state (MM_GENERIC_GSM (modem), FALSE, MM_MODEM_STATE_REASON_NONE);
|
||||||
|
|
||||||
|
info = mm_callback_info_new (modem, callback, user_data);
|
||||||
mm_callback_info_schedule (info);
|
mm_callback_info_schedule (info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,7 +474,7 @@ mbm_emrdy_received (MMSerialPort *port,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mbm_pacsp0_received (MMSerialPort *port,
|
mbm_pacsp_received (MMSerialPort *port,
|
||||||
GMatchInfo *info,
|
GMatchInfo *info,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
@@ -527,9 +505,12 @@ mbm_ciev_received (MMSerialPort *port,
|
|||||||
static void
|
static void
|
||||||
mbm_do_connect_done (MMModemMbm *self)
|
mbm_do_connect_done (MMModemMbm *self)
|
||||||
{
|
{
|
||||||
/* unset the poll id which should remove the source in destroy func */
|
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (self);
|
||||||
g_return_if_fail (MM_MODEM_MBM_GET_PRIVATE (self)->do_connect_done_info);
|
|
||||||
mm_callback_info_schedule (MM_MODEM_MBM_GET_PRIVATE (self)->do_connect_done_info);
|
if (priv->pending_connect_info) {
|
||||||
|
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (self), NULL, priv->pending_connect_info);
|
||||||
|
priv->pending_connect_info = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -559,10 +540,10 @@ mbm_e2nap_received (MMSerialPort *port,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enap_poll_done (MMSerialPort *port,
|
enap_poll_response (MMSerialPort *port,
|
||||||
GString *response,
|
GString *response,
|
||||||
GError *error,
|
GError *error,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
guint state;
|
guint state;
|
||||||
@@ -573,15 +554,20 @@ enap_poll_done (MMSerialPort *port,
|
|||||||
count = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "mbm-enap-poll-count"));
|
count = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "mbm-enap-poll-count"));
|
||||||
|
|
||||||
if (sscanf (response->str, "*ENAP: %d", &state) == 1 && state == 1) {
|
if (sscanf (response->str, "*ENAP: %d", &state) == 1 && state == 1) {
|
||||||
mm_callback_info_schedule (info);
|
/* Success! Connected... */
|
||||||
} else {
|
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), NULL, info);
|
||||||
mm_callback_info_set_data (info, "mbm-enap-poll-count", GUINT_TO_POINTER (++count), NULL);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* lets give it about 50 seconds */
|
mm_callback_info_set_data (info, "mbm-enap-poll-count", GUINT_TO_POINTER (++count), NULL);
|
||||||
if (count > 50) {
|
|
||||||
info -> error = mm_modem_connect_error_for_code (MM_MODEM_CONNECT_ERROR_BUSY);
|
/* lets give it about 50 seconds */
|
||||||
mm_callback_info_schedule (info);
|
if (count > 50) {
|
||||||
}
|
GError *poll_error;
|
||||||
|
|
||||||
|
poll_error = mm_modem_connect_error_for_code (MM_MODEM_CONNECT_ERROR_BUSY);
|
||||||
|
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), poll_error, info);
|
||||||
|
g_error_free (poll_error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,8 +579,8 @@ enap_poll (gpointer user_data)
|
|||||||
|
|
||||||
g_assert (port);
|
g_assert (port);
|
||||||
|
|
||||||
mm_serial_port_queue_command (port, "AT*ENAP?", 3, enap_poll_done, user_data);
|
mm_serial_port_queue_command (port, "AT*ENAP?", 3, enap_poll_response, user_data);
|
||||||
/* we cancle this in the _done function if all is fine */
|
/* we cancel this in the _done function if all is fine */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,16 +591,17 @@ enap_done (MMSerialPort *port,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
guint tid;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
mm_callback_info_schedule (info);
|
return;
|
||||||
} else {
|
|
||||||
guint tid = g_timeout_add_seconds (1, enap_poll, user_data);
|
|
||||||
/* remember poll id as callback info object, with source_remove as free func */
|
|
||||||
mm_callback_info_set_data (info, "mbm-enap-poll-id", GUINT_TO_POINTER (tid), (GFreeFunc) g_source_remove);
|
|
||||||
mm_serial_port_queue_command (port, "AT*E2NAP=1", 3, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tid = g_timeout_add_seconds (1, enap_poll, user_data);
|
||||||
|
/* remember poll id as callback info object, with source_remove as free func */
|
||||||
|
mm_callback_info_set_data (info, "mbm-enap-poll-id", GUINT_TO_POINTER (tid), (GFreeFunc) g_source_remove);
|
||||||
|
mm_serial_port_queue_command (port, "AT*E2NAP=1", 3, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -624,17 +611,19 @@ mbm_auth_done (MMSerialPort *port,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
MMGenericGsm *modem = MM_GENERIC_GSM (info->modem);
|
||||||
|
char *command;
|
||||||
|
guint32 cid;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_connect_complete (modem, error, info);
|
||||||
mm_callback_info_schedule (info);
|
return;
|
||||||
} else {
|
|
||||||
char *command;
|
|
||||||
guint32 cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (info->modem));
|
|
||||||
command = g_strdup_printf ("AT*ENAP=1,%d", cid);
|
|
||||||
mm_serial_port_queue_command (port, command, 3, enap_done, user_data);
|
|
||||||
g_free (command);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cid = mm_generic_gsm_get_cid (modem);
|
||||||
|
command = g_strdup_printf ("AT*ENAP=1,%d", cid);
|
||||||
|
mm_serial_port_queue_command (port, command, 3, enap_done, user_data);
|
||||||
|
g_free (command);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -738,8 +727,8 @@ grab_port (MMModem *modem,
|
|||||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, mbm_e2nap_received, modem, NULL);
|
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, mbm_e2nap_received, modem, NULL);
|
||||||
g_regex_unref (regex);
|
g_regex_unref (regex);
|
||||||
|
|
||||||
regex = g_regex_new ("\\r\\n\\+PACSP0\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
regex = g_regex_new ("\\r\\n\\+PACSP(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, mbm_pacsp0_received, modem, NULL);
|
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, mbm_pacsp_received, modem, NULL);
|
||||||
g_regex_unref (regex);
|
g_regex_unref (regex);
|
||||||
|
|
||||||
regex = g_regex_new ("\\r\\n\\+CIEV: (\\d),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
regex = g_regex_new ("\\r\\n\\+CIEV: (\\d),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||||
@@ -779,7 +768,6 @@ static void
|
|||||||
modem_init (MMModem *modem_class)
|
modem_init (MMModem *modem_class)
|
||||||
{
|
{
|
||||||
modem_class->grab_port = grab_port;
|
modem_class->grab_port = grab_port;
|
||||||
modem_class->enable = enable;
|
|
||||||
modem_class->disable = disable;
|
modem_class->disable = disable;
|
||||||
modem_class->connect = do_connect;
|
modem_class->connect = do_connect;
|
||||||
modem_class->disconnect = disconnect;
|
modem_class->disconnect = disconnect;
|
||||||
@@ -807,11 +795,14 @@ static void
|
|||||||
mm_modem_mbm_class_init (MMModemMbmClass *klass)
|
mm_modem_mbm_class_init (MMModemMbmClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass);
|
||||||
|
|
||||||
mm_modem_mbm_parent_class = g_type_class_peek_parent (klass);
|
mm_modem_mbm_parent_class = g_type_class_peek_parent (klass);
|
||||||
g_type_class_add_private (object_class, sizeof (MMModemMbmPrivate));
|
g_type_class_add_private (object_class, sizeof (MMModemMbmPrivate));
|
||||||
|
|
||||||
/* Virtual methods */
|
/* Virtual methods */
|
||||||
object_class->finalize = finalize;
|
object_class->finalize = finalize;
|
||||||
|
|
||||||
|
gsm_class->do_enable = do_enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,27 +56,25 @@ init_modem_done (MMSerialPort *port,
|
|||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error)
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
info->error = g_error_copy (error);
|
|
||||||
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pin_check_done (MMModem *modem, GError *error, gpointer user_data)
|
pin_check_done (MMModem *modem, GError *error, gpointer user_data)
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
MMGenericGsm *self = MM_GENERIC_GSM (modem);
|
||||||
MMSerialPort *primary;
|
MMSerialPort *primary;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (self, error, info);
|
||||||
mm_callback_info_schedule (info);
|
return;
|
||||||
} else {
|
|
||||||
/* Finish the initialization */
|
|
||||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
|
||||||
g_assert (primary);
|
|
||||||
mm_serial_port_queue_command (primary, "Z E0 V1 X4 &C1 +CMEE=1;+CFUN=1", 10, init_modem_done, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Finish the initialization */
|
||||||
|
primary = mm_generic_gsm_get_port (self, MM_PORT_TYPE_PRIMARY);
|
||||||
|
g_assert (primary);
|
||||||
|
mm_serial_port_queue_command (primary, "Z E0 V1 X4 &C1 +CMEE=1;+CFUN=1", 10, init_modem_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -88,13 +86,14 @@ pre_init_done (MMSerialPort *port,
|
|||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
mm_callback_info_schedule (info);
|
return;
|
||||||
} else {
|
|
||||||
/* Now check the PIN explicitly, novatel doesn't seem to report
|
|
||||||
that it needs it otherwise */
|
|
||||||
mm_generic_gsm_check_pin (MM_GENERIC_GSM (info->modem), pin_check_done, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Now check the PIN explicitly, novatel doesn't seem to report
|
||||||
|
* that it needs it otherwise.
|
||||||
|
*/
|
||||||
|
mm_generic_gsm_check_pin (MM_GENERIC_GSM (info->modem), pin_check_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -102,37 +101,22 @@ enable_flash_done (MMSerialPort *port, GError *error, gpointer user_data)
|
|||||||
{
|
{
|
||||||
MMCallbackInfo *info = user_data;
|
MMCallbackInfo *info = user_data;
|
||||||
|
|
||||||
if (error) {
|
if (error)
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
mm_callback_info_schedule (info);
|
else
|
||||||
return;
|
mm_serial_port_queue_command (port, "E0 V1", 3, pre_init_done, user_data);
|
||||||
}
|
|
||||||
|
|
||||||
mm_serial_port_queue_command (port, "E0 V1", 3, pre_init_done, user_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable (MMModem *modem,
|
do_enable (MMGenericGsm *modem, MMModemFn callback, gpointer user_data)
|
||||||
MMModemFn callback,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info;
|
MMCallbackInfo *info;
|
||||||
MMSerialPort *primary;
|
MMSerialPort *primary;
|
||||||
|
|
||||||
/* First, reset the previously used CID */
|
primary = mm_generic_gsm_get_port (modem, MM_PORT_TYPE_PRIMARY);
|
||||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
|
|
||||||
|
|
||||||
info = mm_callback_info_new (modem, callback, user_data);
|
|
||||||
|
|
||||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
|
||||||
g_assert (primary);
|
g_assert (primary);
|
||||||
|
|
||||||
if (!mm_serial_port_open (primary, &info->error)) {
|
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
|
||||||
g_assert (info->error);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mm_serial_port_flash (primary, 100, enable_flash_done, info);
|
mm_serial_port_flash (primary, 100, enable_flash_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +164,6 @@ grab_port (MMModem *modem,
|
|||||||
static void
|
static void
|
||||||
modem_init (MMModem *modem_class)
|
modem_init (MMModem *modem_class)
|
||||||
{
|
{
|
||||||
modem_class->enable = enable;
|
|
||||||
modem_class->grab_port = grab_port;
|
modem_class->grab_port = grab_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,6 +175,10 @@ mm_modem_novatel_gsm_init (MMModemNovatelGsm *self)
|
|||||||
static void
|
static void
|
||||||
mm_modem_novatel_gsm_class_init (MMModemNovatelGsmClass *klass)
|
mm_modem_novatel_gsm_class_init (MMModemNovatelGsmClass *klass)
|
||||||
{
|
{
|
||||||
|
MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass);
|
||||||
|
|
||||||
mm_modem_novatel_gsm_parent_class = g_type_class_peek_parent (klass);
|
mm_modem_novatel_gsm_parent_class = g_type_class_peek_parent (klass);
|
||||||
|
|
||||||
|
gsm_class->do_enable = do_enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,9 +53,7 @@ pin_check_done (MMModem *modem, GError *error, gpointer user_data)
|
|||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error)
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (modem), error, info);
|
||||||
info->error = g_error_copy (error);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -64,9 +62,9 @@ option_enabled (gpointer data)
|
|||||||
MMCallbackInfo *info = (MMCallbackInfo *) data;
|
MMCallbackInfo *info = (MMCallbackInfo *) data;
|
||||||
|
|
||||||
/* Now check the PIN explicitly, option doesn't seem to report
|
/* Now check the PIN explicitly, option doesn't seem to report
|
||||||
that it needs it otherwise */
|
* that it needs it otherwise.
|
||||||
|
*/
|
||||||
mm_generic_gsm_check_pin (MM_GENERIC_GSM (info->modem), pin_check_done, info);
|
mm_generic_gsm_check_pin (MM_GENERIC_GSM (info->modem), pin_check_done, info);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,13 +74,14 @@ parent_enable_done (MMModem *modem, GError *error, gpointer user_data)
|
|||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (modem), error, info);
|
||||||
mm_callback_info_schedule (info);
|
return;
|
||||||
} else {
|
|
||||||
/* Option returns OK on +CFUN=1 right away but needs some time
|
|
||||||
to finish initialization */
|
|
||||||
g_timeout_add_seconds (10, option_enabled, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Option returns OK on +CFUN=1 right away but needs some time
|
||||||
|
* to finish initialization
|
||||||
|
*/
|
||||||
|
g_timeout_add_seconds (10, option_enabled, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -53,9 +53,7 @@ pin_check_done (MMModem *modem, GError *error, gpointer user_data)
|
|||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error)
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (modem), error, info);
|
||||||
info->error = g_error_copy (error);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -64,9 +62,9 @@ sierra_enabled (gpointer data)
|
|||||||
MMCallbackInfo *info = (MMCallbackInfo *) data;
|
MMCallbackInfo *info = (MMCallbackInfo *) data;
|
||||||
|
|
||||||
/* Now check the PIN explicitly, sierra doesn't seem to report
|
/* Now check the PIN explicitly, sierra doesn't seem to report
|
||||||
that it needs it otherwise */
|
* that it needs it otherwise.
|
||||||
|
*/
|
||||||
mm_generic_gsm_check_pin (MM_GENERIC_GSM (info->modem), pin_check_done, info);
|
mm_generic_gsm_check_pin (MM_GENERIC_GSM (info->modem), pin_check_done, info);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,19 +74,18 @@ parent_enable_done (MMModem *modem, GError *error, gpointer user_data)
|
|||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (modem), error, info);
|
||||||
mm_callback_info_schedule (info);
|
return;
|
||||||
} else {
|
|
||||||
/* Sierra returns OK on +CFUN=1 right away but needs some time
|
|
||||||
to finish initialization */
|
|
||||||
g_timeout_add_seconds (10, sierra_enabled, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Sierra returns OK on +CFUN=1 right away but needs some time
|
||||||
|
* to finish initialization.
|
||||||
|
*/
|
||||||
|
g_timeout_add_seconds (10, sierra_enabled, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable (MMModem *modem,
|
enable (MMModem *modem, MMModemFn callback, gpointer user_data)
|
||||||
MMModemFn callback,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
MMModem *parent_modem_iface;
|
MMModem *parent_modem_iface;
|
||||||
MMCallbackInfo *info;
|
MMCallbackInfo *info;
|
||||||
|
@@ -62,10 +62,7 @@ init_modem_done (MMSerialPort *port,
|
|||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error)
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
info->error = g_error_copy (error);
|
|
||||||
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -75,14 +72,14 @@ pin_check_done (MMModem *modem, GError *error, gpointer user_data)
|
|||||||
MMSerialPort *primary;
|
MMSerialPort *primary;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (modem), error, info);
|
||||||
mm_callback_info_schedule (info);
|
return;
|
||||||
} else {
|
|
||||||
/* Finish the initialization */
|
|
||||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
|
||||||
g_assert (primary);
|
|
||||||
mm_serial_port_queue_command (primary, "Z E0 V1 X4 &C1 +CMEE=1;+CFUN=1;", 10, init_modem_done, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Finish the initialization */
|
||||||
|
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||||
|
g_assert (primary);
|
||||||
|
mm_serial_port_queue_command (primary, "Z E0 V1 X4 &C1 +CMEE=1;+CFUN=1;", 10, init_modem_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enable_flash_done (MMSerialPort *port,
|
static void enable_flash_done (MMSerialPort *port,
|
||||||
@@ -104,10 +101,8 @@ pre_init_done (MMSerialPort *port,
|
|||||||
&& g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_RESPONSE_TIMEOUT)) {
|
&& g_error_matches (error, MM_SERIAL_ERROR, MM_SERIAL_RESPONSE_TIMEOUT)) {
|
||||||
priv->init_retried = TRUE;
|
priv->init_retried = TRUE;
|
||||||
enable_flash_done (port, NULL, user_data);
|
enable_flash_done (port, NULL, user_data);
|
||||||
} else {
|
} else
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* Now check the PIN explicitly, zte doesn't seem to report
|
/* Now check the PIN explicitly, zte doesn't seem to report
|
||||||
that it needs it otherwise */
|
that it needs it otherwise */
|
||||||
@@ -120,19 +115,14 @@ enable_flash_done (MMSerialPort *port, GError *error, gpointer user_data)
|
|||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error) {
|
if (error)
|
||||||
info->error = g_error_copy (error);
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
mm_callback_info_schedule (info);
|
else
|
||||||
return;
|
mm_serial_port_queue_command (port, "E0 V1", 3, pre_init_done, user_data);
|
||||||
}
|
|
||||||
|
|
||||||
mm_serial_port_queue_command (port, "E0 V1", 3, pre_init_done, user_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable (MMModem *modem,
|
do_enable (MMGenericGsm *modem, MMModemFn callback, gpointer user_data)
|
||||||
MMModemFn callback,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (modem);
|
MMModemZtePrivate *priv = MM_MODEM_ZTE_GET_PRIVATE (modem);
|
||||||
MMCallbackInfo *info;
|
MMCallbackInfo *info;
|
||||||
@@ -140,20 +130,10 @@ enable (MMModem *modem,
|
|||||||
|
|
||||||
priv->init_retried = FALSE;
|
priv->init_retried = FALSE;
|
||||||
|
|
||||||
/* First, reset the previously used CID */
|
primary = mm_generic_gsm_get_port (modem, MM_PORT_TYPE_PRIMARY);
|
||||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
|
|
||||||
|
|
||||||
info = mm_callback_info_new (modem, callback, user_data);
|
|
||||||
|
|
||||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
|
||||||
g_assert (primary);
|
g_assert (primary);
|
||||||
|
|
||||||
if (!mm_serial_port_open (primary, &info->error)) {
|
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
|
||||||
g_assert (info->error);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mm_serial_port_flash (primary, 100, enable_flash_done, info);
|
mm_serial_port_flash (primary, 100, enable_flash_done, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +204,6 @@ grab_port (MMModem *modem,
|
|||||||
static void
|
static void
|
||||||
modem_init (MMModem *modem_class)
|
modem_init (MMModem *modem_class)
|
||||||
{
|
{
|
||||||
modem_class->enable = enable;
|
|
||||||
modem_class->disable = disable;
|
modem_class->disable = disable;
|
||||||
modem_class->grab_port = grab_port;
|
modem_class->grab_port = grab_port;
|
||||||
}
|
}
|
||||||
@@ -238,8 +217,11 @@ static void
|
|||||||
mm_modem_zte_class_init (MMModemZteClass *klass)
|
mm_modem_zte_class_init (MMModemZteClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
MMGenericGsmClass *gsm_class = MM_GENERIC_GSM_CLASS (klass);
|
||||||
|
|
||||||
mm_modem_zte_parent_class = g_type_class_peek_parent (klass);
|
mm_modem_zte_parent_class = g_type_class_peek_parent (klass);
|
||||||
g_type_class_add_private (object_class, sizeof (MMModemZtePrivate));
|
g_type_class_add_private (object_class, sizeof (MMModemZtePrivate));
|
||||||
|
|
||||||
|
gsm_class->do_enable = do_enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -398,6 +398,29 @@ release_port (MMModem *modem, const char *subsys, const char *name)
|
|||||||
check_valid (MM_GENERIC_GSM (modem));
|
check_valid (MM_GENERIC_GSM (modem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mm_generic_gsm_enable_complete (MMGenericGsm *modem,
|
||||||
|
GError *error,
|
||||||
|
MMCallbackInfo *info)
|
||||||
|
{
|
||||||
|
g_return_if_fail (modem != NULL);
|
||||||
|
g_return_if_fail (MM_IS_GENERIC_GSM (modem));
|
||||||
|
g_return_if_fail (info != NULL);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
mm_modem_set_state (MM_MODEM (modem),
|
||||||
|
MM_MODEM_STATE_DISABLED,
|
||||||
|
MM_MODEM_STATE_REASON_NONE);
|
||||||
|
|
||||||
|
info->error = g_error_copy (error);
|
||||||
|
} else {
|
||||||
|
/* Modem is enabled; update the state */
|
||||||
|
mm_generic_gsm_update_enabled_state (modem, FALSE, MM_MODEM_STATE_REASON_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
mm_callback_info_schedule (info);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable_done (MMSerialPort *port,
|
enable_done (MMSerialPort *port,
|
||||||
GString *response,
|
GString *response,
|
||||||
@@ -415,11 +438,7 @@ enable_done (MMSerialPort *port,
|
|||||||
* errors or ignore them.
|
* errors or ignore them.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mm_generic_gsm_update_enabled_state (MM_GENERIC_GSM (info->modem),
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), NULL, info);
|
||||||
FALSE,
|
|
||||||
MM_MODEM_STATE_REASON_NONE);
|
|
||||||
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -432,34 +451,30 @@ init_done (MMSerialPort *port,
|
|||||||
char *cmd = NULL;
|
char *cmd = NULL;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
mm_modem_set_state (MM_MODEM (info->modem),
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
MM_MODEM_STATE_DISABLED,
|
return;
|
||||||
MM_MODEM_STATE_REASON_NONE);
|
|
||||||
|
|
||||||
info->error = g_error_copy (error);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
} else {
|
|
||||||
/* Ensure echo is off after the init command; some modems ignore the
|
|
||||||
* E0 when it's in the same like as ATZ (Option GIO322).
|
|
||||||
*/
|
|
||||||
mm_serial_port_queue_command (port, "E0 +CMEE=1", 2, NULL, NULL);
|
|
||||||
|
|
||||||
g_object_get (G_OBJECT (info->modem), MM_GENERIC_GSM_INIT_CMD_OPTIONAL, &cmd, NULL);
|
|
||||||
mm_serial_port_queue_command (port, cmd, 2, NULL, NULL);
|
|
||||||
g_free (cmd);
|
|
||||||
|
|
||||||
if (MM_GENERIC_GSM_GET_PRIVATE (info->modem)->unsolicited_registration)
|
|
||||||
mm_serial_port_queue_command (port, "+CREG=1", 5, NULL, NULL);
|
|
||||||
else
|
|
||||||
mm_serial_port_queue_command (port, "+CREG=0", 5, NULL, NULL);
|
|
||||||
|
|
||||||
g_object_get (G_OBJECT (info->modem), MM_GENERIC_GSM_POWER_UP_CMD, &cmd, NULL);
|
|
||||||
if (cmd && strlen (cmd))
|
|
||||||
mm_serial_port_queue_command (port, cmd, 5, enable_done, user_data);
|
|
||||||
else
|
|
||||||
enable_done (port, NULL, NULL, user_data);
|
|
||||||
g_free (cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Ensure echo is off after the init command; some modems ignore the
|
||||||
|
* E0 when it's in the same like as ATZ (Option GIO322).
|
||||||
|
*/
|
||||||
|
mm_serial_port_queue_command (port, "E0 +CMEE=1", 2, NULL, NULL);
|
||||||
|
|
||||||
|
g_object_get (G_OBJECT (info->modem), MM_GENERIC_GSM_INIT_CMD_OPTIONAL, &cmd, NULL);
|
||||||
|
mm_serial_port_queue_command (port, cmd, 2, NULL, NULL);
|
||||||
|
g_free (cmd);
|
||||||
|
|
||||||
|
if (MM_GENERIC_GSM_GET_PRIVATE (info->modem)->unsolicited_registration)
|
||||||
|
mm_serial_port_queue_command (port, "+CREG=1", 5, NULL, NULL);
|
||||||
|
else
|
||||||
|
mm_serial_port_queue_command (port, "+CREG=0", 5, NULL, NULL);
|
||||||
|
|
||||||
|
g_object_get (G_OBJECT (info->modem), MM_GENERIC_GSM_POWER_UP_CMD, &cmd, NULL);
|
||||||
|
if (cmd && strlen (cmd))
|
||||||
|
mm_serial_port_queue_command (port, cmd, 5, enable_done, user_data);
|
||||||
|
else
|
||||||
|
enable_done (port, NULL, NULL, user_data);
|
||||||
|
g_free (cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -469,12 +484,7 @@ enable_flash_done (MMSerialPort *port, GError *error, gpointer user_data)
|
|||||||
char *cmd = NULL;
|
char *cmd = NULL;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
mm_modem_set_state (MM_MODEM (info->modem),
|
mm_generic_gsm_enable_complete (MM_GENERIC_GSM (info->modem), error, info);
|
||||||
MM_MODEM_STATE_DISABLED,
|
|
||||||
MM_MODEM_STATE_REASON_NONE);
|
|
||||||
|
|
||||||
info->error = g_error_copy (error);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,30 +493,41 @@ enable_flash_done (MMSerialPort *port, GError *error, gpointer user_data)
|
|||||||
g_free (cmd);
|
g_free (cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
real_do_enable (MMGenericGsm *self, MMModemFn callback, gpointer user_data)
|
||||||
|
{
|
||||||
|
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
|
||||||
|
MMCallbackInfo *info;
|
||||||
|
|
||||||
|
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||||
|
mm_serial_port_flash (priv->primary, 100, enable_flash_done, info);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable (MMModem *modem,
|
enable (MMModem *modem,
|
||||||
MMModemFn callback,
|
MMModemFn callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (modem);
|
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (modem);
|
||||||
MMCallbackInfo *info;
|
GError *error = NULL;
|
||||||
|
|
||||||
/* First, reset the previously used CID */
|
/* First, reset the previously used CID */
|
||||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
|
mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
|
||||||
|
|
||||||
info = mm_callback_info_new (modem, callback, user_data);
|
if (!mm_serial_port_open (priv->primary, &error)) {
|
||||||
|
MMCallbackInfo *info;
|
||||||
|
|
||||||
if (!mm_serial_port_open (priv->primary, &info->error)) {
|
g_assert (error);
|
||||||
g_assert (info->error);
|
info = mm_callback_info_new (modem, callback, user_data);
|
||||||
|
info->error = error;
|
||||||
mm_callback_info_schedule (info);
|
mm_callback_info_schedule (info);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mm_modem_set_state (MM_MODEM (info->modem),
|
mm_modem_set_state (modem, MM_MODEM_STATE_ENABLING, MM_MODEM_STATE_REASON_NONE);
|
||||||
MM_MODEM_STATE_ENABLING,
|
|
||||||
MM_MODEM_STATE_REASON_NONE);
|
|
||||||
|
|
||||||
mm_serial_port_flash (priv->primary, 100, enable_flash_done, info);
|
g_assert (MM_GENERIC_GSM_GET_CLASS (modem)->do_enable);
|
||||||
|
MM_GENERIC_GSM_GET_CLASS (modem)->do_enable (MM_GENERIC_GSM (modem), callback, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1190,6 +1211,33 @@ get_registration_info (MMModemGsmNetwork *self,
|
|||||||
mm_callback_info_schedule (info);
|
mm_callback_info_schedule (info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mm_generic_gsm_connect_complete (MMGenericGsm *modem,
|
||||||
|
GError *error,
|
||||||
|
MMCallbackInfo *info)
|
||||||
|
{
|
||||||
|
MMGenericGsmPrivate *priv;
|
||||||
|
|
||||||
|
g_return_if_fail (modem != NULL);
|
||||||
|
g_return_if_fail (MM_IS_GENERIC_GSM (modem));
|
||||||
|
g_return_if_fail (info != NULL);
|
||||||
|
|
||||||
|
priv = MM_GENERIC_GSM_GET_PRIVATE (modem);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
mm_generic_gsm_update_enabled_state (modem, FALSE, MM_MODEM_STATE_REASON_NONE);
|
||||||
|
info->error = g_error_copy (error);
|
||||||
|
} else {
|
||||||
|
/* Modem is connected; update the state */
|
||||||
|
mm_port_set_connected (priv->data, TRUE);
|
||||||
|
mm_modem_set_state (MM_MODEM (modem),
|
||||||
|
MM_MODEM_STATE_CONNECTED,
|
||||||
|
MM_MODEM_STATE_REASON_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
mm_callback_info_schedule (info);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
connect_report_done (MMSerialPort *port,
|
connect_report_done (MMSerialPort *port,
|
||||||
GString *response,
|
GString *response,
|
||||||
@@ -1197,14 +1245,28 @@ connect_report_done (MMSerialPort *port,
|
|||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
GError *real_error;
|
||||||
|
|
||||||
if (!error && g_str_has_prefix (response->str, "+CEER: ")) {
|
/* If the CEER command was successful, copy that error reason into the
|
||||||
g_free (info->error->message);
|
* callback's error. If not, use the original error.
|
||||||
info->error->message = g_strdup (response->str + 7); /* skip the "+CEER: " */
|
*/
|
||||||
|
|
||||||
|
/* Have to do this little dance since mm_generic_gsm_connect_complete()
|
||||||
|
* copies the provided error into the callback info.
|
||||||
|
*/
|
||||||
|
real_error = info->error;
|
||||||
|
info->error = NULL;
|
||||||
|
|
||||||
|
if ( !error
|
||||||
|
&& g_str_has_prefix (response->str, "+CEER: ")
|
||||||
|
&& (strlen (response->str) > 7)) {
|
||||||
|
/* copy the connect failure reason into the error */
|
||||||
|
g_free (real_error->message);
|
||||||
|
real_error->message = g_strdup (response->str + 7); /* skip the "+CEER: " */
|
||||||
}
|
}
|
||||||
|
|
||||||
mm_generic_gsm_update_enabled_state (MM_GENERIC_GSM (info->modem), FALSE, MM_MODEM_STATE_REASON_NONE);
|
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), real_error, info);
|
||||||
mm_callback_info_schedule (info);
|
g_error_free (real_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1221,12 +1283,8 @@ connect_done (MMSerialPort *port,
|
|||||||
/* Try to get more information why it failed */
|
/* Try to get more information why it failed */
|
||||||
priv = MM_GENERIC_GSM_GET_PRIVATE (info->modem);
|
priv = MM_GENERIC_GSM_GET_PRIVATE (info->modem);
|
||||||
mm_serial_port_queue_command (priv->primary, "+CEER", 3, connect_report_done, info);
|
mm_serial_port_queue_command (priv->primary, "+CEER", 3, connect_report_done, info);
|
||||||
} else {
|
} else
|
||||||
/* Done */
|
mm_generic_gsm_connect_complete (MM_GENERIC_GSM (info->modem), NULL, info);
|
||||||
mm_port_set_connected (priv->data, TRUE);
|
|
||||||
mm_modem_set_state (info->modem, MM_MODEM_STATE_CONNECTED, MM_MODEM_STATE_REASON_NONE);
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -2155,6 +2213,8 @@ mm_generic_gsm_class_init (MMGenericGsmClass *klass)
|
|||||||
object_class->get_property = get_property;
|
object_class->get_property = get_property;
|
||||||
object_class->finalize = finalize;
|
object_class->finalize = finalize;
|
||||||
|
|
||||||
|
klass->do_enable = real_do_enable;
|
||||||
|
|
||||||
/* Properties */
|
/* Properties */
|
||||||
g_object_class_override_property (object_class,
|
g_object_class_override_property (object_class,
|
||||||
MM_MODEM_PROP_DATA_DEVICE,
|
MM_MODEM_PROP_DATA_DEVICE,
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include "mm-modem-gsm-network.h"
|
#include "mm-modem-gsm-network.h"
|
||||||
#include "mm-modem-base.h"
|
#include "mm-modem-base.h"
|
||||||
#include "mm-serial-port.h"
|
#include "mm-serial-port.h"
|
||||||
|
#include "mm-callback-info.h"
|
||||||
|
|
||||||
#define MM_TYPE_GENERIC_GSM (mm_generic_gsm_get_type ())
|
#define MM_TYPE_GENERIC_GSM (mm_generic_gsm_get_type ())
|
||||||
#define MM_GENERIC_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_GENERIC_GSM, MMGenericGsm))
|
#define MM_GENERIC_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_GENERIC_GSM, MMGenericGsm))
|
||||||
@@ -52,6 +53,15 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MMModemBaseClass parent;
|
MMModemBaseClass parent;
|
||||||
|
|
||||||
|
/* Called after opening the primary serial port and updating the modem's
|
||||||
|
* state to ENABLING, but before sending any commands to the device. Modems
|
||||||
|
* that need to perform custom initialization sequences or other setup should
|
||||||
|
* generally override this method instead of the MMModem interface's enable()
|
||||||
|
* method, unless the customization must happen *after* the generic init
|
||||||
|
* sequence has completed.
|
||||||
|
*/
|
||||||
|
void (*do_enable) (MMGenericGsm *self, MMModemFn callback, gpointer user_data);
|
||||||
} MMGenericGsmClass;
|
} MMGenericGsmClass;
|
||||||
|
|
||||||
GType mm_generic_gsm_get_type (void);
|
GType mm_generic_gsm_get_type (void);
|
||||||
@@ -98,4 +108,22 @@ void mm_generic_gsm_update_enabled_state (MMGenericGsm *modem,
|
|||||||
gboolean stay_connected,
|
gboolean stay_connected,
|
||||||
MMModemStateReason reason);
|
MMModemStateReason reason);
|
||||||
|
|
||||||
|
/* Called to complete the enable operation for custom enable() handling; if an
|
||||||
|
* error is passed in, it copies the error to the callback info. This function
|
||||||
|
* always schedules the callback info. It will also update the modem with the
|
||||||
|
* correct state for both failure and success of the enable operation.
|
||||||
|
*/
|
||||||
|
void mm_generic_gsm_enable_complete (MMGenericGsm *modem,
|
||||||
|
GError *error,
|
||||||
|
MMCallbackInfo *info);
|
||||||
|
|
||||||
|
/* Called to complete the enable operation for custom connect() handling; if an
|
||||||
|
* error is passed in, it copies the error to the callback info. This function
|
||||||
|
* always schedules the callback info. It will also update the modem with the
|
||||||
|
* correct state for both failure and success of the connect operation.
|
||||||
|
*/
|
||||||
|
void mm_generic_gsm_connect_complete (MMGenericGsm *modem,
|
||||||
|
GError *error,
|
||||||
|
MMCallbackInfo *info);
|
||||||
|
|
||||||
#endif /* MM_GENERIC_GSM_H */
|
#endif /* MM_GENERIC_GSM_H */
|
||||||
|
Reference in New Issue
Block a user