aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2009-06-29 13:14:11 -0400
committerDan Williams <dcbw@redhat.com>2009-06-29 13:14:11 -0400
commitc106368ce7c06e0ae5b64cc6146ad05c3b9fa819 (patch)
tree1d0535148b8ed0b4e97823a8778841684793832f /src
parentff58936f1f7ef1645be9062095c35de2b03c0cc1 (diff)
parentc397247c05dbefb33edccc0987734eb715312b85 (diff)
Merge commit 'origin/master' into udev
Diffstat (limited to 'src')
-rw-r--r--src/mm-generic-gsm.c136
1 files changed, 66 insertions, 70 deletions
diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c
index 67b9a105..15765a7e 100644
--- a/src/mm-generic-gsm.c
+++ b/src/mm-generic-gsm.c
@@ -30,7 +30,7 @@ typedef struct {
gboolean unsolicited_registration;
MMModemGsmNetworkRegStatus reg_status;
- guint pending_registration;
+ guint pending_reg_id;
guint32 signal_quality;
guint32 cid;
@@ -712,57 +712,18 @@ read_operator_name_done (MMSerialPort *port,
/* Registration */
-static gboolean
-pending_registration_timed_out (gpointer data)
-{
- MMCallbackInfo *info = (MMCallbackInfo *) data;
-
- MM_GENERIC_GSM_GET_PRIVATE (info->modem)->pending_registration = 0;
-
- return FALSE;
-}
-
void
mm_generic_gsm_pending_registration_stop (MMGenericGsm *modem)
{
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (modem);
- if (priv->pending_registration) {
- g_source_remove (priv->pending_registration);
- priv->pending_registration = 0;
+ if (priv->pending_reg_id) {
+ g_source_remove (priv->pending_reg_id);
+ priv->pending_reg_id = 0;
}
}
static void
-pending_registration_done (gpointer data)
-{
- MMCallbackInfo *info = (MMCallbackInfo *) data;
-
- if (!info->error) {
- switch (MM_GENERIC_GSM_GET_PRIVATE (info->modem)->reg_status) {
- case MM_MODEM_GSM_NETWORK_REG_STATUS_HOME:
- case MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING:
- /* Successfully registered */
- break;
- case MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED:
- info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_NETWORK_NOT_ALLOWED);
- break;
- case MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING:
- info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_NETWORK_TIMEOUT);
- break;
- case MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE:
- info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_NO_NETWORK);
- break;
- default:
- info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN);
- break;
- }
- }
-
- mm_callback_info_schedule (info);
-}
-
-static void
reg_status_updated (MMGenericGsm *self, int new_value)
{
MMModemGsmNetworkRegStatus status;
@@ -821,7 +782,7 @@ reg_status_again (gpointer data)
MMCallbackInfo *info = (MMCallbackInfo *) data;
priv = MM_GENERIC_GSM_GET_PRIVATE (info->modem);
- if (priv->pending_registration)
+ if (priv->pending_reg_id)
get_registration_status (priv->primary, info);
return FALSE;
@@ -840,37 +801,62 @@ get_reg_status_done (MMSerialPort *port,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
- MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (info->modem);
+ MMGenericGsm *self = MM_GENERIC_GSM (info->modem);
+ MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
+ int unsolicited, stat;
+ guint id;
if (error) {
info->error = g_error_copy (error);
- pending_registration_done (info);
+ mm_generic_gsm_pending_registration_stop (self);
+ mm_callback_info_schedule (info);
return;
}
- if (g_str_has_prefix (response->str, "+CREG: ")) {
- /* Got valid reply */
- int unsolicited, stat;
-
- if (sscanf (response->str + 7, "%d,%d", &unsolicited, &stat)) {
- reg_status_updated (MM_GENERIC_GSM (info->modem), stat);
-
- if (!unsolicited && priv->pending_registration) {
- guint id;
-
- id = g_timeout_add_seconds (1, reg_status_again, info);
- mm_callback_info_set_data (info, "reg-status-again",
- GINT_TO_POINTER (id),
- reg_status_again_remove);
- }
- }
- } else {
- g_debug ("unknown response: %s", response->str);
+ if ( !g_str_has_prefix (response->str, "+CREG: ")
+ || (sscanf (response->str + 7, "%d,%d", &unsolicited, &stat) != 2)) {
+ g_debug ("%s: unknown response: %s", __func__, response->str);
info->error = g_error_new_literal (MM_MODEM_ERROR,
MM_MODEM_ERROR_GENERAL,
"Could not parse the response");
- pending_registration_done (info);
+ mm_generic_gsm_pending_registration_stop (self);
+ mm_callback_info_schedule (info);
+ return;
}
+
+ reg_status_updated (self, stat);
+
+ if (priv->pending_reg_id) {
+ /* Registration is still going */
+ id = g_timeout_add_seconds (1, reg_status_again, info);
+ mm_callback_info_set_data (info, "reg-status-again",
+ GINT_TO_POINTER (id),
+ reg_status_again_remove);
+ return;
+ }
+
+ /* Registration has either completed successfully or completely failed */
+ switch (priv->reg_status) {
+ case MM_MODEM_GSM_NETWORK_REG_STATUS_HOME:
+ case MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING:
+ /* Successfully registered */
+ break;
+ case MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED:
+ info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_NETWORK_NOT_ALLOWED);
+ break;
+ case MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING:
+ info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_NETWORK_TIMEOUT);
+ break;
+ case MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE:
+ info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_NO_NETWORK);
+ break;
+ default:
+ info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_UNKNOWN);
+ break;
+ }
+
+ mm_generic_gsm_pending_registration_stop (self);
+ mm_callback_info_schedule (info);
}
static void
@@ -889,6 +875,20 @@ register_done (MMSerialPort *port,
get_registration_status (port, (MMCallbackInfo *) user_data);
}
+static gboolean
+registration_timed_out (gpointer data)
+{
+ MMCallbackInfo *info = (MMCallbackInfo *) data;
+ MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (info->modem);
+
+ priv->pending_reg_id = 0;
+ priv->reg_status = MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE;
+
+ info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_NETWORK_TIMEOUT);
+ mm_callback_info_schedule (info);
+ return FALSE;
+}
+
static void
do_register (MMModemGsmNetwork *modem,
const char *network_id,
@@ -901,11 +901,7 @@ do_register (MMModemGsmNetwork *modem,
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
- priv->pending_registration =
- g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 60,
- pending_registration_timed_out,
- info,
- pending_registration_done);
+ priv->pending_reg_id = g_timeout_add_seconds (60, registration_timed_out, info);
if (network_id)
command = g_strdup_printf ("+COPS=1,2,\"%s\"", network_id);