diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2011-11-25 15:20:32 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:27 +0100 |
commit | 491758c266bdc22b8b0ab3c369da9b36815c2d0c (patch) | |
tree | a66a737d8df1cfc36abafa810209d6b2637db188 | |
parent | ea7a939201bdde4cf0630c9564183b18031ffaa5 (diff) |
broadband-modem: implement modem initialization commands
-rw-r--r-- | src/mm-broadband-modem.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 35c65d06..fb6169bd 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -701,6 +701,77 @@ load_unlock_required (MMIfaceModem *self, /*****************************************************************************/ +static gboolean +modem_init_finish (MMIfaceModem *self, + GAsyncResult *res, + GError **error) +{ + return !mm_at_sequence_finish (G_OBJECT (self), res, error); +} + +static gboolean +parse_init_response (MMBroadbandModem *self, + gpointer none, + const gchar *command, + const gchar *response, + const GError *error, + GVariant **variant, + GError **result_error) +{ + /* Errors in the mandatory init commands will abort the whole modem + * initialization process */ + if (error) + *result_error = g_error_copy (error); + + /* Return FALSE so that we keep on with the next steps in the sequence */ + return FALSE; +} + +static const MMAtCommand modem_init_sequence[] = { + /* Send the init command twice; some devices (Nokia N900) appear to take a + * few commands before responding correctly. Instead of penalizing them for + * being stupid the first time by failing to enable the device, just + * try again. + + * TODO: only send init command 2nd time if 1st time failed? + */ + { "Z E0 V1", 3, NULL }, + { "Z E0 V1", 3, (MMAtResponseProcessor)parse_init_response }, + + /* Ensure echo is off after the init command; some modems ignore the + * E0 when it's in the same line as ATZ (Option GIO322). + */ + { "E0", 3, NULL }, + + /* Some phones (like Blackberries) don't support +CMEE=1, so make it + * optional. It completely violates 3GPP TS 27.007 (9.1) but what can we do... + */ + { "+CMEE=1", 3, NULL }, + + /* Additional OPTIONAL initialization */ + { "X4 &C1", 3, NULL }, + + { NULL } +}; + +static void +modem_init (MMIfaceModem *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + mm_at_sequence (G_OBJECT (self), + mm_base_modem_get_port_primary (MM_BASE_MODEM (self)), + (MMAtCommand *)modem_init_sequence, + NULL, /* response processor context */ + FALSE, /* free sequence */ + NULL, /* result signature */ + NULL, /* cancellable */ + callback, + user_data); +} + +/*****************************************************************************/ + static void enable (MMBaseModem *self, GCancellable *cancellable, @@ -934,6 +1005,9 @@ iface_modem_init (MMIfaceModem *iface) iface->load_device_identifier_finish = load_device_identifier_finish; iface->load_unlock_required = load_unlock_required; iface->load_unlock_required_finish = load_unlock_required_finish; + + iface->modem_init = modem_init; + iface->modem_init_finish = modem_init_finish; } static void |