Merge commit 'origin/master' into udev

This commit is contained in:
Dan Williams
2009-06-29 13:14:11 -04:00
2 changed files with 69 additions and 80 deletions
+3 -10
View File
@@ -143,11 +143,8 @@ do_register (MMModemGsmNetwork *modem,
{
MMModemMbm *self = MM_MODEM_MBM (modem);
MMModemMbmPrivate *priv = MM_MODEM_MBM_GET_PRIVATE (self);
MMCallbackInfo *info;
RegisterData *reg_data;
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
reg_data = g_malloc0 (sizeof(RegisterData));
reg_data->modem = modem;
reg_data->network_id = network_id;
@@ -169,17 +166,13 @@ mbm_cind_done (MMSerialPort *port,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
char *cind;
int quality = 0, batt;
int quality = 0, ignored;
if (error)
info->error = g_error_copy (error);
else {
cind = strstr (response->str, "+CIND:");
if (cind) {
if (sscanf (cind, " %d,%d", &batt, &quality) == 2)
quality *= 20; /* normalize to percent */
}
if (sscanf (response->str, "+CIND: %d,%d", &ignored, &quality) == 2)
quality *= 20; /* normalize to percent */
mm_callback_info_set_result (info, GUINT_TO_POINTER (quality), NULL);
}
+66 -70
View File
@@ -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,56 +712,17 @@ 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)
{
@@ -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);