cdma: fix subclass registration state checking in error paths (rh #569067)

The generic CDMA superclass already checks minimal registration state,
and when some of the additional query_registration_state() subclass checks
were being performed, if the device returned an error (if it didn't support
the subclass' specific registration command like *STATE or ^SYSINFO) the
superclass' registration state checks would be thrown away.

Fix that by specifying the behavior of the subclass'
query_registration_state() methods to ignore most errors and leave the
superclass' registration state intact if a non-critical error occurs.
This commit is contained in:
Dan Williams
2010-04-05 18:46:53 -07:00
parent 49c363d83a
commit f3dd034aad
5 changed files with 153 additions and 120 deletions

View File

@@ -123,15 +123,8 @@ evdo_state_done (MMAtSerialPort *port,
GRegex *r; GRegex *r;
GMatchInfo *match_info; GMatchInfo *match_info;
info->error = mm_modem_check_removed (info->modem, error); if (error) {
if (info->error) { /* Leave superclass' reg state alone if AT*HSTATE isn't supported */
if (info->modem) {
/* If HSTATE returned an error, assume the device is not EVDO capable
* or EVDO is not registered.
*/
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
}
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
return; return;
} }
@@ -143,13 +136,8 @@ evdo_state_done (MMAtSerialPort *port,
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
if (!r) { if (!r) {
/* Parse error; warn about it and assume EVDO is not available */ /* Parse error; warn about it and assume EVDO is not available */
g_warning ("AnyData(%s): failed to create EVDO state regex: (%d) %s", g_warning ("AnyDATA(%s): *HSTATE parse regex creation failed.", __func__);
__func__, goto done;
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
mm_callback_info_schedule (info);
return;
} }
g_regex_match (r, reply, 0, &match_info); g_regex_match (r, reply, 0, &match_info);
@@ -185,8 +173,8 @@ evdo_state_done (MMAtSerialPort *port,
} }
} }
done:
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, reg_state); mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, reg_state);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
} }
@@ -202,17 +190,8 @@ state_done (MMAtSerialPort *port,
GRegex *r; GRegex *r;
GMatchInfo *match_info; GMatchInfo *match_info;
info->error = mm_modem_check_removed (info->modem, error); if (error) {
if (info->error) { /* Leave superclass' reg state alone if AT*STATE isn't supported */
if (info->modem) {
/* Assume if we got this far, we're registered even if an error
* occurred. We're not sure if all AnyData CDMA modems support
* the *STATE and *HSTATE commands.
*/
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED);
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
}
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
return; return;
} }
@@ -223,9 +202,7 @@ state_done (MMAtSerialPort *port,
r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*([^,\\)]*)\\s*,.*", r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*([^,\\)]*)\\s*,.*",
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
if (!r) { if (!r) {
info->error = g_error_new_literal (MM_MODEM_ERROR, g_warning ("AnyDATA(%s): *STATE parse regex creation failed.", __func__);
MM_MODEM_ERROR_GENERAL,
"Could not parse sysinfo results (regex creation failed).");
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
return; return;
} }
@@ -254,7 +231,7 @@ state_done (MMAtSerialPort *port,
reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED; reg_state = MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED;
break; break;
default: default:
g_message ("ANYDATA: unknown *STATE (%d); assuming no service.", val); g_warning ("ANYDATA: unknown *STATE (%d); assuming no service.", val);
/* fall through */ /* fall through */
case 0: /* NO SERVICE */ case 0: /* NO SERVICE */
break; break;
@@ -270,13 +247,15 @@ state_done (MMAtSerialPort *port,
static void static void
query_registration_state (MMGenericCdma *cdma, query_registration_state (MMGenericCdma *cdma,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback, MMModemCdmaRegistrationStateFn callback,
gpointer user_data) gpointer user_data)
{ {
MMCallbackInfo *info; MMCallbackInfo *info;
MMAtSerialPort *port; MMAtSerialPort *port;
info = mm_generic_cdma_query_reg_state_callback_info_new (cdma, callback, user_data); info = mm_generic_cdma_query_reg_state_callback_info_new (cdma, cur_cdma_state, cur_evdo_state, callback, user_data);
port = mm_generic_cdma_get_best_at_port (cdma, &info->error); port = mm_generic_cdma_get_best_at_port (cdma, &info->error);
if (!port) { if (!port) {

View File

@@ -161,12 +161,10 @@ sysinfo_done (MMAtSerialPort *port,
GRegex *r; GRegex *r;
GMatchInfo *match_info; GMatchInfo *match_info;
const char *reply; const char *reply;
gboolean success = FALSE;
if (error) { if (error) {
info->error = g_error_copy (error); /* Leave superclass' reg state alone if AT^SYSINFO isn't supported */
mm_callback_info_schedule (info); goto done;
return;
} }
reply = strip_response (response->str, "^SYSINFO:"); reply = strip_response (response->str, "^SYSINFO:");
@@ -175,9 +173,7 @@ sysinfo_done (MMAtSerialPort *port,
r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)", r = g_regex_new ("\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)",
G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL); G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
if (!r) { if (!r) {
info->error = g_error_new_literal (MM_MODEM_ERROR, g_warning ("Huawei(%s): ^SYSINFO parse regex creation failed.", __func__);
MM_MODEM_ERROR_GENERAL,
"Could not parse sysinfo results (regex creation failed).");
goto done; goto done;
} }
@@ -217,31 +213,27 @@ sysinfo_done (MMAtSerialPort *port,
/* Say we're registered to something even though sysmode parsing failed */ /* Say we're registered to something even though sysmode parsing failed */
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, reg_state); mm_generic_cdma_query_reg_state_set_callback_1x_state (info, reg_state);
} }
success = TRUE; } else
} g_warning ("Huawei(%s): failed to parse ^SYSINFO response.", __func__);
done:
g_match_info_free (match_info); g_match_info_free (match_info);
g_regex_unref (r); g_regex_unref (r);
if (!success && !info->error) { done:
info->error = g_error_new_literal (MM_MODEM_ERROR,
MM_MODEM_ERROR_GENERAL,
"Could not parse sysinfo results.");
}
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
} }
static void static void
query_registration_state (MMGenericCdma *cdma, query_registration_state (MMGenericCdma *cdma,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback, MMModemCdmaRegistrationStateFn callback,
gpointer user_data) gpointer user_data)
{ {
MMCallbackInfo *info; MMCallbackInfo *info;
MMAtSerialPort *port; MMAtSerialPort *port;
info = mm_generic_cdma_query_reg_state_callback_info_new (cdma, callback, user_data); info = mm_generic_cdma_query_reg_state_callback_info_new (cdma, cur_cdma_state, cur_evdo_state, callback, user_data);
port = mm_generic_cdma_get_best_at_port (cdma, &info->error); port = mm_generic_cdma_get_best_at_port (cdma, &info->error);
if (!port) { if (!port) {

View File

@@ -125,13 +125,13 @@ status_done (MMAtSerialPort *port,
gboolean cdma_1x_set = FALSE, evdo_set = FALSE; gboolean cdma_1x_set = FALSE, evdo_set = FALSE;
if (error) { if (error) {
info->error = g_error_copy (error); /* Leave superclass' reg state alone if AT!STATUS isn't supported */
goto done; goto done;
} }
lines = g_strsplit_set (response->str, "\n\r", 0); lines = g_strsplit_set (response->str, "\n\r", 0);
if (!lines) { if (!lines) {
/* Whatever, just use default registration state */ /* Whatever, just use superclass' registration state */
goto done; goto done;
} }
@@ -289,13 +289,15 @@ done:
static void static void
query_registration_state (MMGenericCdma *cdma, query_registration_state (MMGenericCdma *cdma,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback, MMModemCdmaRegistrationStateFn callback,
gpointer user_data) gpointer user_data)
{ {
MMCallbackInfo *info; MMCallbackInfo *info;
MMAtSerialPort *port; MMAtSerialPort *port;
info = mm_generic_cdma_query_reg_state_callback_info_new (cdma, callback, user_data); info = mm_generic_cdma_query_reg_state_callback_info_new (cdma, cur_cdma_state, cur_evdo_state, callback, user_data);
port = mm_generic_cdma_get_best_at_port (cdma, &info->error); port = mm_generic_cdma_get_best_at_port (cdma, &info->error);
if (!port) { if (!port) {

View File

@@ -1286,9 +1286,23 @@ get_serving_system (MMModemCdma *modem,
legacy_get_serving_system (self, info); legacy_get_serving_system (self, info);
} }
/*****************************************************************************/
/* Registration state stuff */
#define CDMA_1X_STATE_TAG "cdma-1x-reg-state" #define CDMA_1X_STATE_TAG "cdma-1x-reg-state"
#define EVDO_STATE_TAG "evdo-reg-state" #define EVDO_STATE_TAG "evdo-reg-state"
MMModemCdmaRegistrationState
mm_generic_cdma_query_reg_state_get_callback_1x_state (MMCallbackInfo *info)
{
g_return_val_if_fail (info != NULL, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
g_return_val_if_fail (info->modem != NULL, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
g_return_val_if_fail (MM_IS_GENERIC_CDMA (info->modem), MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
return GPOINTER_TO_UINT (mm_callback_info_get_data (info, CDMA_1X_STATE_TAG));
}
void void
mm_generic_cdma_query_reg_state_set_callback_1x_state (MMCallbackInfo *info, mm_generic_cdma_query_reg_state_set_callback_1x_state (MMCallbackInfo *info,
MMModemCdmaRegistrationState new_state) MMModemCdmaRegistrationState new_state)
@@ -1300,6 +1314,16 @@ mm_generic_cdma_query_reg_state_set_callback_1x_state (MMCallbackInfo *info,
mm_callback_info_set_data (info, CDMA_1X_STATE_TAG, GUINT_TO_POINTER (new_state), NULL); mm_callback_info_set_data (info, CDMA_1X_STATE_TAG, GUINT_TO_POINTER (new_state), NULL);
} }
MMModemCdmaRegistrationState
mm_generic_cdma_query_reg_state_get_callback_evdo_state (MMCallbackInfo *info)
{
g_return_val_if_fail (info != NULL, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
g_return_val_if_fail (info->modem != NULL, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
g_return_val_if_fail (MM_IS_GENERIC_CDMA (info->modem), MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
return GPOINTER_TO_UINT (mm_callback_info_get_data (info, EVDO_STATE_TAG));
}
void void
mm_generic_cdma_query_reg_state_set_callback_evdo_state (MMCallbackInfo *info, mm_generic_cdma_query_reg_state_set_callback_evdo_state (MMCallbackInfo *info,
MMModemCdmaRegistrationState new_state) MMModemCdmaRegistrationState new_state)
@@ -1318,18 +1342,19 @@ registration_state_invoke (MMCallbackInfo *info)
/* note: This is the MMModemCdma interface callback */ /* note: This is the MMModemCdma interface callback */
callback (MM_MODEM_CDMA (info->modem), callback (MM_MODEM_CDMA (info->modem),
GPOINTER_TO_UINT (mm_callback_info_get_data (info, CDMA_1X_STATE_TAG)), mm_generic_cdma_query_reg_state_get_callback_1x_state (info),
GPOINTER_TO_UINT (mm_callback_info_get_data (info, EVDO_STATE_TAG)), mm_generic_cdma_query_reg_state_get_callback_evdo_state (info),
info->error, info->error,
info->user_data); info->user_data);
} }
MMCallbackInfo * MMCallbackInfo *
mm_generic_cdma_query_reg_state_callback_info_new (MMGenericCdma *self, mm_generic_cdma_query_reg_state_callback_info_new (MMGenericCdma *self,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback, MMModemCdmaRegistrationStateFn callback,
gpointer user_data) gpointer user_data)
{ {
MMGenericCdmaPrivate *priv;
MMCallbackInfo *info; MMCallbackInfo *info;
g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self != NULL, NULL);
@@ -1342,15 +1367,8 @@ mm_generic_cdma_query_reg_state_callback_info_new (MMGenericCdma *self,
user_data); user_data);
/* Fill with current state */ /* Fill with current state */
priv = MM_GENERIC_CDMA_GET_PRIVATE (self); mm_generic_cdma_query_reg_state_set_callback_1x_state (info, cur_cdma_state);
mm_callback_info_set_data (info, mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, cur_evdo_state);
CDMA_1X_STATE_TAG,
GUINT_TO_POINTER (priv->cdma_1x_reg_state),
NULL);
mm_callback_info_set_data (info,
EVDO_STATE_TAG,
GUINT_TO_POINTER (priv->evdo_reg_state),
NULL);
return info; return info;
} }
@@ -1381,18 +1399,18 @@ set_callback_evdo_state_helper (MMCallbackInfo *info,
} }
static void static void
reg_state_query_done (MMModemCdma *cdma, subclass_reg_query_done (MMModemCdma *cdma,
MMModemCdmaRegistrationState cdma_1x_reg_state, MMModemCdmaRegistrationState cdma_reg_state,
MMModemCdmaRegistrationState evdo_reg_state, MMModemCdmaRegistrationState evdo_reg_state,
GError *error, GError *error,
gpointer user_data) gpointer user_data)
{ {
MMCallbackInfo *info = (MMCallbackInfo *) user_data; MMCallbackInfo *info = (MMCallbackInfo *) user_data;
if (error) info->error = mm_modem_check_removed (info->modem, error);
info->error = g_error_copy (error); if (!info->error) {
else { /* Set final registration state */
set_callback_1x_state_helper (info, cdma_1x_reg_state); set_callback_1x_state_helper (info, cdma_reg_state);
set_callback_evdo_state_helper (info, evdo_reg_state); set_callback_evdo_state_helper (info, evdo_reg_state);
} }
@@ -1406,25 +1424,26 @@ reg_query_speri_done (MMAtSerialPort *port,
gpointer user_data) gpointer user_data)
{ {
MMCallbackInfo *info = user_data; MMCallbackInfo *info = user_data;
MMModemCdmaRegistrationState cdma_state;
MMModemCdmaRegistrationState evdo_state;
cdma_state = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "tmp-cdma-state"));
evdo_state = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "tmp-evdo-state"));
if (!error) {
gboolean roam = FALSE; gboolean roam = FALSE;
if (mm_cdma_parse_speri_response (response->str, &roam, NULL)) { if (error)
cdma_state = roam ? MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING goto done;
: MM_MODEM_CDMA_REGISTRATION_STATE_HOME;
evdo_state = roam ? MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING if (!mm_cdma_parse_speri_response (response->str, &roam, NULL))
: MM_MODEM_CDMA_REGISTRATION_STATE_HOME; goto done;
}
/* Change the 1x and EVDO registration states to roaming if they were
* anything other than UNKNOWN.
*/
if (roam) {
if (mm_generic_cdma_query_reg_state_get_callback_1x_state (info))
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING);
if (mm_generic_cdma_query_reg_state_get_callback_evdo_state (info))
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING);
} }
set_callback_1x_state_helper (info, cdma_state); done:
set_callback_evdo_state_helper (info, evdo_state);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
} }
@@ -1440,32 +1459,36 @@ reg_query_spservice_done (MMAtSerialPort *port,
if (error) if (error)
info->error = g_error_copy (error); info->error = g_error_copy (error);
else if (mm_cdma_parse_spservice_response (response->str, else if (mm_cdma_parse_spservice_response (response->str, &cdma_state, &evdo_state)) {
&cdma_state, mm_generic_cdma_query_reg_state_set_callback_1x_state (info, cdma_state);
&evdo_state)) { mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, evdo_state);
if (MM_GENERIC_CDMA_GET_PRIVATE (info->modem)->has_speri) { if (MM_GENERIC_CDMA_GET_PRIVATE (info->modem)->has_speri) {
/* Get roaming status to override generic registration state */ /* Get roaming status to override generic registration state */
mm_callback_info_set_data (info, "tmp-cdma-state", GUINT_TO_POINTER (cdma_state), NULL);
mm_callback_info_set_data (info, "tmp-evdo-state", GUINT_TO_POINTER (evdo_state), NULL);
mm_at_serial_port_queue_command (port, "$SPERI?", 3, reg_query_speri_done, info); mm_at_serial_port_queue_command (port, "$SPERI?", 3, reg_query_speri_done, info);
return; return;
} }
} }
set_callback_1x_state_helper (info, cdma_state);
set_callback_evdo_state_helper (info, evdo_state);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
} }
static void static void
real_query_registration_state (MMGenericCdma *self, real_query_registration_state (MMGenericCdma *self,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback, MMModemCdmaRegistrationStateFn callback,
gpointer user_data) gpointer user_data)
{ {
MMCallbackInfo *info; MMCallbackInfo *info;
MMAtSerialPort *port; MMAtSerialPort *port;
info = mm_generic_cdma_query_reg_state_callback_info_new (self, callback, user_data); /* Seed this CallbackInfo with any previously determined registration state */
info = mm_generic_cdma_query_reg_state_callback_info_new (self,
cur_cdma_state,
cur_evdo_state,
callback,
user_data);
port = mm_generic_cdma_get_best_at_port (self, &info->error); port = mm_generic_cdma_get_best_at_port (self, &info->error);
if (!port) { if (!port) {
@@ -1477,9 +1500,11 @@ real_query_registration_state (MMGenericCdma *self,
/* Try Sprint-specific commands */ /* Try Sprint-specific commands */
mm_at_serial_port_queue_command (port, "+SPSERVICE?", 3, reg_query_spservice_done, info); mm_at_serial_port_queue_command (port, "+SPSERVICE?", 3, reg_query_spservice_done, info);
} else { } else {
/* Assume we're registered if we passed CAD and CSS checking */ /* Assume we're registered on the 1x network if we passed +CAD, +CSS,
set_callback_1x_state_helper (info, MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); * and QCDM Call Manager checking.
set_callback_evdo_state_helper (info, MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED); */
mm_generic_cdma_query_reg_state_set_callback_1x_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED);
mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
} }
} }
@@ -1498,8 +1523,7 @@ reg_state_css_response (MMModemCdma *cdma,
* report unknown registration state. * report unknown registration state.
*/ */
if (error) { if (error) {
if ( (error->domain == MM_MOBILE_ERROR) if (g_error_matches (error, MM_MOBILE_ERROR, MM_MOBILE_ERROR_NO_NETWORK)) {
&& (error->code == MM_MOBILE_ERROR_NO_NETWORK)) {
set_callback_1x_state_helper (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); set_callback_1x_state_helper (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
set_callback_evdo_state_helper (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN); set_callback_evdo_state_helper (info, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN);
} else { } else {
@@ -1507,13 +1531,17 @@ reg_state_css_response (MMModemCdma *cdma,
info->error = g_error_copy (error); info->error = g_error_copy (error);
} }
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
return; } else {
} /* We're registered on the CDMA 1x network at least, but let subclasses
* do more specific registration checking.
*/
MM_GENERIC_CDMA_GET_CLASS (cdma)->query_registration_state (MM_GENERIC_CDMA (info->modem), MM_GENERIC_CDMA_GET_CLASS (cdma)->query_registration_state (MM_GENERIC_CDMA (info->modem),
reg_state_query_done, MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED,
MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
subclass_reg_query_done,
info); info);
} }
}
static void static void
get_analog_digital_done (MMAtSerialPort *port, get_analog_digital_done (MMAtSerialPort *port,
@@ -1564,7 +1592,9 @@ get_analog_digital_done (MMAtSerialPort *port,
* state, so skip AT+CSS? query. * state, so skip AT+CSS? query.
*/ */
MM_GENERIC_CDMA_GET_CLASS (info->modem)->query_registration_state (MM_GENERIC_CDMA (info->modem), MM_GENERIC_CDMA_GET_CLASS (info->modem)->query_registration_state (MM_GENERIC_CDMA (info->modem),
reg_state_query_done, MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
subclass_reg_query_done,
info); info);
} }
return; return;
@@ -1623,13 +1653,16 @@ reg_cmstate_cb (MMQcdmSerialPort *port,
* better idea of whether we're roaming or not and what the * better idea of whether we're roaming or not and what the
* access technology is. * access technology is.
*/ */
if (MM_GENERIC_CDMA_GET_CLASS (info->modem)->query_registration_state) if (MM_GENERIC_CDMA_GET_CLASS (info->modem)->query_registration_state) {
MM_GENERIC_CDMA_GET_CLASS (info->modem)->query_registration_state (MM_GENERIC_CDMA (info->modem), MM_GENERIC_CDMA_GET_CLASS (info->modem)->query_registration_state (MM_GENERIC_CDMA (info->modem),
reg_state_query_done, cdma_state,
evdo_state,
subclass_reg_query_done,
info); info);
return; return;
} }
} }
}
set_callback_1x_state_helper (info, cdma_state); set_callback_1x_state_helper (info, cdma_state);
set_callback_evdo_state_helper (info, evdo_state); set_callback_evdo_state_helper (info, evdo_state);
@@ -1654,20 +1687,18 @@ get_registration_state (MMModemCdma *modem,
MMCallbackInfo *info; MMCallbackInfo *info;
MMAtSerialPort *port; MMAtSerialPort *port;
info = mm_generic_cdma_query_reg_state_callback_info_new (MM_GENERIC_CDMA (modem), callback, user_data); info = mm_generic_cdma_query_reg_state_callback_info_new (MM_GENERIC_CDMA (modem),
MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN,
callback,
user_data);
port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error); port = mm_generic_cdma_get_best_at_port (MM_GENERIC_CDMA (modem), &info->error);
if (!port && !priv->qcdm) { if (!port && !priv->qcdm) {
g_message ("Returning saved registration states: 1x: %d EVDO: %d", g_message ("Returning saved registration states: 1x: %d EVDO: %d",
priv->cdma_1x_reg_state, priv->evdo_reg_state); priv->cdma_1x_reg_state, priv->evdo_reg_state);
mm_callback_info_set_data (info, mm_generic_cdma_query_reg_state_set_callback_1x_state (info, priv->cdma_1x_reg_state);
CDMA_1X_STATE_TAG, mm_generic_cdma_query_reg_state_set_callback_evdo_state (info, priv->evdo_reg_state);
GUINT_TO_POINTER (priv->cdma_1x_reg_state),
NULL);
mm_callback_info_set_data (info,
EVDO_STATE_TAG,
GUINT_TO_POINTER (priv->evdo_reg_state),
NULL);
mm_callback_info_schedule (info); mm_callback_info_schedule (info);
return; return;
} }
@@ -1983,8 +2014,11 @@ modem_state_changed (MMGenericCdma *self, GParamSpec *pspec, gpointer user_data)
state = mm_modem_get_state (MM_MODEM (self)); state = mm_modem_get_state (MM_MODEM (self));
if (state >= MM_MODEM_STATE_ENABLED) { if (state >= MM_MODEM_STATE_ENABLED) {
if (!priv->poll_id) if (!priv->poll_id) {
priv->poll_id = g_timeout_add_seconds (30, periodic_poll_cb, self); priv->poll_id = g_timeout_add_seconds (30, periodic_poll_cb, self);
/* Kick one off immediately */
periodic_poll_cb (self);
}
} else { } else {
if (priv->poll_id) if (priv->poll_id)
g_source_remove (priv->poll_id); g_source_remove (priv->poll_id);

View File

@@ -42,7 +42,27 @@ typedef struct {
typedef struct { typedef struct {
MMModemBaseClass parent; MMModemBaseClass parent;
/* Subclasses should implement this function if they can more accurately
* determine the registration state and/or roaming status than the base
* class can (by using manufacturer custom AT commands or whatever).
* The base class passes its detected registration state in the
* cur_cdma_state and cur_evdo_state arguments, which the subclass should
* override if necessary before passing to the callback.
*
* Subclasses can use the helper functions
* mm_generic_cdma_query_reg_state_callback_info_new(),
* mm_generic_cdma_query_reg_state_set_callback_1x_state(), and
* mm_generic_cdma_query_reg_state_set_callback_evdo_state() to create the
* MMCallbackInfo object and to set the registration state which is passed
* to the callback when the subclass' registration query completes.
*
* Subclasses should generally not return parsing or other non-critical
* errors to the callback since that fails the entire registration check,
* rendering the superclass' checks useless.
*/
void (*query_registration_state) (MMGenericCdma *self, void (*query_registration_state) (MMGenericCdma *self,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback, MMModemCdmaRegistrationStateFn callback,
gpointer user_data); gpointer user_data);
@@ -100,12 +120,18 @@ MMModemCdmaRegistrationState mm_generic_cdma_evdo_get_registration_state_sync (M
/* query_registration_state class function helpers */ /* query_registration_state class function helpers */
MMCallbackInfo *mm_generic_cdma_query_reg_state_callback_info_new (MMGenericCdma *self, MMCallbackInfo *mm_generic_cdma_query_reg_state_callback_info_new (MMGenericCdma *self,
MMModemCdmaRegistrationState cur_cdma_state,
MMModemCdmaRegistrationState cur_evdo_state,
MMModemCdmaRegistrationStateFn callback, MMModemCdmaRegistrationStateFn callback,
gpointer user_data); gpointer user_data);
MMModemCdmaRegistrationState mm_generic_cdma_query_reg_state_get_callback_1x_state (MMCallbackInfo *info);
void mm_generic_cdma_query_reg_state_set_callback_1x_state (MMCallbackInfo *info, void mm_generic_cdma_query_reg_state_set_callback_1x_state (MMCallbackInfo *info,
MMModemCdmaRegistrationState new_state); MMModemCdmaRegistrationState new_state);
MMModemCdmaRegistrationState mm_generic_cdma_query_reg_state_get_callback_evdo_state (MMCallbackInfo *info);
void mm_generic_cdma_query_reg_state_set_callback_evdo_state (MMCallbackInfo *info, void mm_generic_cdma_query_reg_state_set_callback_evdo_state (MMCallbackInfo *info,
MMModemCdmaRegistrationState new_state); MMModemCdmaRegistrationState new_state);