modem-helpers: refactor and reorganize sources

This commit is contained in:
Aleksander Morgado
2012-03-06 14:15:43 +01:00
parent c824ee3106
commit 1f250585dd
5 changed files with 1193 additions and 1127 deletions

View File

@@ -835,7 +835,7 @@ parse_pdp_list (MMBaseModem *self,
return FALSE;
}
pdp_list = mm_3gpp_parse_pdp_query_response (response, &inner_error);
pdp_list = mm_3gpp_parse_cgdcont_read_response (response, &inner_error);
if (!pdp_list) {
/* No predefined PDP contexts found */
mm_dbg ("No PDP contexts found");
@@ -1710,9 +1710,9 @@ crm_range_ready (MMBaseModem *modem,
MMModemCdmaRmProtocol min = MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN;
MMModemCdmaRmProtocol max = MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN;
if (mm_cdma_parse_crm_range_response (response,
&min, &max,
&error)) {
if (mm_cdma_parse_crm_test_response (response,
&min, &max,
&error)) {
/* Check if value within the range */
if (ctx->self->priv->rm_protocol >= min &&
ctx->self->priv->rm_protocol <= max) {

View File

@@ -772,7 +772,7 @@ modem_load_own_numbers_finish (MMIfaceModem *self,
if (!result)
return NULL;
return mm_3gpp_parse_cnum_response (result, error);
return mm_3gpp_parse_cnum_exec_response (result, error);
}
static void
@@ -1116,7 +1116,7 @@ signal_quality_cind_ready (MMBroadbandModem *self,
result = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (!error)
indicators = mm_parse_cind_query_response (result, &error);
indicators = mm_3gpp_parse_cind_read_response (result, &error);
if (error)
g_simple_async_result_take_error (ctx->result, error);
@@ -1301,11 +1301,11 @@ cind_format_check_ready (MMBroadbandModem *self,
GHashTable *indicators = NULL;
GError *error = NULL;
const gchar *result;
CindResponse *r;
MM3gppCindResponse *r;
result = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (error ||
!(indicators = mm_parse_cind_test_response (result, &error))) {
!(indicators = mm_3gpp_parse_cind_test_response (result, &error))) {
/* quit with error */
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
@@ -1320,9 +1320,9 @@ cind_format_check_ready (MMBroadbandModem *self,
/* Check if we support signal quality indications */
r = g_hash_table_lookup (indicators, "signal");
if (r) {
self->priv->modem_cind_indicator_signal_quality = cind_response_get_index (r);
self->priv->modem_cind_min_signal_quality = cind_response_get_min (r);
self->priv->modem_cind_max_signal_quality = cind_response_get_max (r);
self->priv->modem_cind_indicator_signal_quality = mm_3gpp_cind_response_get_index (r);
self->priv->modem_cind_min_signal_quality = mm_3gpp_cind_response_get_min (r);
self->priv->modem_cind_max_signal_quality = mm_3gpp_cind_response_get_max (r);
mm_dbg ("Modem supports signal quality indications via CIND at index '%u'"
"(min: %u, max: %u)",
@@ -1335,7 +1335,7 @@ cind_format_check_ready (MMBroadbandModem *self,
/* Check if we support roaming indications */
r = g_hash_table_lookup (indicators, "roam");
if (r) {
self->priv->modem_cind_indicator_roaming = cind_response_get_index (r);
self->priv->modem_cind_indicator_roaming = mm_3gpp_cind_response_get_index (r);
mm_dbg ("Modem supports roaming indications via CIND at index '%u'",
self->priv->modem_cind_indicator_roaming);
} else
@@ -1344,7 +1344,7 @@ cind_format_check_ready (MMBroadbandModem *self,
/* Check if we support service indications */
r = g_hash_table_lookup (indicators, "service");
if (r) {
self->priv->modem_cind_indicator_service = cind_response_get_index (r);
self->priv->modem_cind_indicator_service = mm_3gpp_cind_response_get_index (r);
mm_dbg ("Modem supports service indications via CIND at index '%u'",
self->priv->modem_cind_indicator_service);
} else
@@ -1787,7 +1787,7 @@ cscs_format_check_ready (MMBaseModem *self,
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (error)
g_simple_async_result_take_error (simple, error);
else if (!mm_gsm_parse_cscs_support_response (response, &charsets))
else if (!mm_3gpp_parse_cscs_test_response (response, &charsets))
g_simple_async_result_set_error (
simple,
MM_CORE_ERROR,
@@ -2056,7 +2056,7 @@ clck_single_query_ready (MMBaseModem *self,
response = mm_base_modem_at_command_finish (self, res, NULL);
if (response &&
mm_3gpp_parse_clck_response (response, &enabled) &&
mm_3gpp_parse_clck_write_response (response, &enabled) &&
enabled) {
ctx->locks |= (1 << ctx->current);
} else {
@@ -2086,7 +2086,7 @@ get_next_facility_lock_status (LoadEnabledFacilityLocksContext *ctx)
/* Query current */
cmd = g_strdup_printf ("+CLCK=\"%s\",2",
mm_3gpp_get_facility_acronym (facility));
mm_3gpp_facility_to_acronym (facility));
mm_base_modem_at_command (MM_BASE_MODEM (ctx->self),
cmd,
3,
@@ -2395,7 +2395,7 @@ modem_3gpp_scan_networks_finish (MMIfaceModem3gpp *self,
if (!result)
return NULL;
return mm_3gpp_parse_scan_response (result, error);
return mm_3gpp_parse_cops_test_response (result, error);
}
static void
@@ -3792,10 +3792,10 @@ cpms_format_check_ready (MMBroadbandModem *self,
result = g_new0 (SupportedStoragesResult, 1);
/* Parse reply */
if (!mm_3gpp_parse_cpms_format_response (response,
&result->mem1,
&result->mem2,
&result->mem3)) {
if (!mm_3gpp_parse_cpms_test_response (response,
&result->mem1,
&result->mem2,
&result->mem3)) {
g_simple_async_result_set_error (simple,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
@@ -3956,10 +3956,10 @@ cmgf_format_check_ready (MMBroadbandModem *self,
response = mm_base_modem_at_command_finish (MM_BASE_MODEM (self), res, &error);
if (error ||
!mm_3gpp_parse_cmgf_format_response (response,
&sms_pdu_supported,
&sms_text_supported,
&error)) {
!mm_3gpp_parse_cmgf_test_response (response,
&sms_pdu_supported,
&sms_text_supported,
&error)) {
mm_dbg ("Failed to query supported SMS modes: '%s'",
error->message);
g_error_free (error);
@@ -5241,8 +5241,8 @@ modem_cdma_get_detailed_registration_state_finish (MMIfaceModemCdma *self,
static void
speri_ready (MMIfaceModemCdma *self,
GAsyncResult *res,
DetailedRegistrationStateContext *ctx)
GAsyncResult *res,
DetailedRegistrationStateContext *ctx)
{
gboolean roaming = FALSE;
const gchar *response;
@@ -5259,7 +5259,7 @@ speri_ready (MMIfaceModemCdma *self,
/* Try to parse the results */
response = mm_strip_tag (response, "$SPERI:");
if (!response ||
!mm_cdma_parse_eri (response, &roaming, NULL, NULL)) {
!mm_cdma_parse_speri_read_response (response, &roaming, NULL, NULL)) {
mm_warn ("Couldn't parse SPERI response '%s'", response);
detailed_registration_state_context_complete_and_free (ctx);
return;
@@ -5302,9 +5302,9 @@ spservice_ready (MMIfaceModemCdma *self,
/* Try to parse the results */
cdma1x_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
evdo_state = MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN;
if (!mm_cdma_parse_spservice_response (response,
&cdma1x_state,
&evdo_state)) {
if (!mm_cdma_parse_spservice_read_response (response,
&cdma1x_state,
&evdo_state)) {
ctx->error = g_error_new (MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"Couldn't parse SPSERVICE response '%s'",

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,8 @@
* GNU General Public License for more details:
*
* Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc.
* Copyright (C) 2009 - 2012 Red Hat, Inc.
* Copyright (C) 2012 Google, Inc.
*/
#ifndef MM_MODEM_HELPERS_H
@@ -22,6 +23,19 @@
#include "glib-object.h"
#include "mm-charsets.h"
/* NOTE:
* We will use the following nomenclature for the different AT commands referred
* - AT+SOMETHING --> "Exec" command
* - AT+SOMETHING? --> "Read" command
* - AT+SOMETHING=X,X --> "Write" command
* - AT+SOMETHING=? --> "Test" command
*/
/*****************************************************************************/
/* Common utilities */
/*****************************************************************************/
#define MM_MODEM_CAPABILITY_3GPP_LTE \
(MM_MODEM_CAPABILITY_LTE | \
MM_MODEM_CAPABILITY_LTE_ADVANCED)
@@ -30,7 +44,33 @@
(MM_MODEM_CAPABILITY_GSM_UMTS | \
MM_MODEM_CAPABILITY_3GPP_LTE)
/* Network scan results expected */
const gchar *mm_strip_tag (const gchar *str,
const gchar *cmd);
guint mm_count_bits_set (gulong number);
gchar *mm_create_device_identifier (guint vid,
guint pid,
const gchar *ati,
const gchar *ati1,
const gchar *gsn,
const gchar *revision,
const gchar *model,
const gchar *manf);
/*****************************************************************************/
/* 3GPP specific helpers and utilities */
/*****************************************************************************/
/* Common Regex getters */
GPtrArray *mm_3gpp_creg_regex_get (gboolean solicited);
void mm_3gpp_creg_regex_destroy (GPtrArray *array);
GRegex *mm_3gpp_ciev_regex_get (void);
GRegex *mm_3gpp_cusd_regex_get (void);
GRegex *mm_3gpp_cmti_regex_get (void);
/* AT+COPS=? (network scan) response parser */
typedef struct {
MMModem3gppNetworkAvailability status;
gchar *operator_long;
@@ -38,24 +78,21 @@ typedef struct {
gchar *operator_code; /* mandatory */
MMModemAccessTechnology access_tech;
} MM3gppNetworkInfo;
void mm_3gpp_network_info_list_free (GList *info_list);
GList *mm_3gpp_parse_scan_response (const gchar *reply,
GError **error);
GList *mm_3gpp_parse_cops_test_response (const gchar *reply,
GError **error);
/* PDP context query results */
/* AT+CGDCONT? (PDP context query) response parser */
typedef struct {
guint cid;
gchar *pdp_type;
gchar *apn;
} MM3gppPdpContext;
void mm_3gpp_pdp_context_list_free (GList *pdp_list);
GList *mm_3gpp_parse_pdp_query_response (const gchar *reply,
GError **error);
GList *mm_3gpp_parse_cgdcont_read_response (const gchar *reply,
GError **error);
GPtrArray *mm_3gpp_creg_regex_get (gboolean solicited);
void mm_3gpp_creg_regex_destroy (GPtrArray *array);
/* CREG/CGREG response/unsolicited message parser */
gboolean mm_3gpp_parse_creg_response (GMatchInfo *info,
MMModem3gppRegistrationState *out_reg_state,
gulong *out_lac,
@@ -64,88 +101,91 @@ gboolean mm_3gpp_parse_creg_response (GMatchInfo *info,
gboolean *out_cgreg,
GError **error);
gboolean mm_3gpp_parse_cmgf_format_response (const gchar *reply,
gboolean *sms_pdu_supported,
gboolean *sms_text_supported,
GError **error);
/* AT+CMGF=? (SMS message format) response parser */
gboolean mm_3gpp_parse_cmgf_test_response (const gchar *reply,
gboolean *sms_pdu_supported,
gboolean *sms_text_supported,
GError **error);
gboolean mm_3gpp_parse_cpms_format_response (const gchar *reply,
GArray **mem1,
GArray **mem2,
GArray **mem3);
/* AT+CPMS=? (Preferred SMS storage) response parser */
gboolean mm_3gpp_parse_cpms_test_response (const gchar *reply,
GArray **mem1,
GArray **mem2,
GArray **mem3);
GRegex *mm_3gpp_ciev_regex_get (void);
/* AT+CSCS=? (Supported charsets) response parser */
gboolean mm_3gpp_parse_cscs_test_response (const gchar *reply,
MMModemCharset *out_charsets);
GRegex *mm_3gpp_cusd_regex_get (void);
/* AT+CLCK=? (Supported locks) response parser */
gboolean mm_3gpp_parse_clck_test_response (const gchar *reply,
MMModem3gppFacility *out_facilities);
GRegex *mm_3gpp_cmti_regex_get (void);
/* AT+CLCK=X,X,X... (Current locks) response parser */
gboolean mm_3gpp_parse_clck_write_response (const gchar *reply,
gboolean *enabled);
const char *mm_strip_tag (const char *str, const char *cmd);
/* AT+CNUM (Own numbers) response parser */
GStrv mm_3gpp_parse_cnum_exec_response (const gchar *reply,
GError **error);
gboolean mm_cdma_parse_spservice_response (const char *reply,
MMModemCdmaRegistrationState *out_cdma_1x_state,
MMModemCdmaRegistrationState *out_evdo_state);
/* AT+CIND=? (Supported indicators) response parser */
typedef struct MM3gppCindResponse MM3gppCindResponse;
GHashTable *mm_3gpp_parse_cind_test_response (const gchar *reply,
GError **error);
const gchar *mm_3gpp_cind_response_get_desc (MM3gppCindResponse *r);
guint mm_3gpp_cind_response_get_index (MM3gppCindResponse *r);
gint mm_3gpp_cind_response_get_min (MM3gppCindResponse *r);
gint mm_3gpp_cind_response_get_max (MM3gppCindResponse *r);
gboolean mm_cdma_parse_eri (const char *reply,
gboolean *out_roaming,
guint32 *out_ind,
const char **out_desc);
/* AT+CIND? (Current indicators) response parser */
GByteArray *mm_3gpp_parse_cind_read_response (const gchar *reply,
GError **error);
/* Additional 3GPP-specific helpers */
MMModem3gppFacility mm_3gpp_acronym_to_facility (const gchar *str);
gchar *mm_3gpp_facility_to_acronym (MMModem3gppFacility facility);
MMModemAccessTechnology mm_3gpp_string_to_access_tech (const gchar *string);
gchar *mm_3gpp_parse_operator (const gchar *reply,
MMModemCharset cur_charset);
/*****************************************************************************/
/* CDMA specific helpers and utilities */
/*****************************************************************************/
/* AT+SPSERVICE? response parser */
gboolean mm_cdma_parse_spservice_read_response (const gchar *reply,
MMModemCdmaRegistrationState *out_cdma_1x_state,
MMModemCdmaRegistrationState *out_evdo_state);
/* AT$SPERI? response parser */
gboolean mm_cdma_parse_speri_read_response (const gchar *reply,
gboolean *out_roaming,
guint32 *out_ind,
const gchar **out_desc);
/* AT+CRM=? response parser */
gboolean mm_cdma_parse_crm_test_response (const gchar *reply,
MMModemCdmaRmProtocol *min,
MMModemCdmaRmProtocol *max,
GError **error);
/* Additional CDMA-specific helpers */
#define MM_MODEM_CDMA_SID_UNKNOWN 99999
#define MM_MODEM_CDMA_NID_UNKNOWN 99999
MMModemCdmaRmProtocol mm_cdma_get_rm_protocol_from_index (guint index,
GError **error);
guint mm_cdma_get_index_from_rm_protocol (MMModemCdmaRmProtocol protocol,
GError **error);
gboolean mm_cdma_parse_crm_range_response (const gchar *reply,
MMModemCdmaRmProtocol *min,
MMModemCdmaRmProtocol *max,
GError **error);
gboolean mm_gsm_parse_cscs_support_response (const char *reply,
MMModemCharset *out_charsets);
gchar *mm_3gpp_get_facility_acronym (MMModem3gppFacility facility);
gboolean mm_3gpp_parse_clck_test_response (const gchar *reply,
MMModem3gppFacility *out_facilities);
gboolean mm_3gpp_parse_clck_response (const gchar *reply,
gboolean *enabled);
gchar *mm_3gpp_parse_operator (const gchar *reply,
MMModemCharset cur_charset);
GStrv mm_3gpp_parse_cnum_response (const gchar *reply,
GError **error);
MMModemAccessTechnology mm_3gpp_string_to_access_tech (const gchar *string);
char *mm_create_device_identifier (guint vid,
guint pid,
const char *ati,
const char *ati1,
const char *gsn,
const char *revision,
const char *model,
const char *manf);
typedef struct CindResponse CindResponse;
GHashTable *mm_parse_cind_test_response (const char *reply, GError **error);
const char *cind_response_get_desc (CindResponse *r);
guint cind_response_get_index (CindResponse *r);
gint cind_response_get_min (CindResponse *r);
gint cind_response_get_max (CindResponse *r);
GByteArray *mm_parse_cind_query_response(const char *reply, GError **error);
#define MM_MODEM_CDMA_SID_UNKNOWN 99999
#define MM_MODEM_CDMA_NID_UNKNOWN 99999
gint mm_cdma_normalize_class (const gchar *orig_class);
gchar mm_cdma_normalize_band (const gchar *long_band,
gint *out_class);
gint mm_cdma_convert_sid (const gchar *sid);
guint mm_count_bits_set (gulong number);
#endif /* MM_MODEM_HELPERS_H */

View File

@@ -35,7 +35,7 @@ test_cops_results (const gchar *desc,
g_print ("\nTesting %s +COPS response...\n", desc);
results = mm_3gpp_parse_scan_response (reply, &error);
results = mm_3gpp_parse_cops_test_response (reply, &error);
g_assert (results);
g_assert_no_error (error);
g_assert_cmpuint (g_list_length (results), ==, expected_results_len);
@@ -420,7 +420,7 @@ test_cops_response_gsm_invalid (void *f, gpointer d)
GList *results;
GError *error = NULL;
results = mm_3gpp_parse_scan_response (reply, &error);
results = mm_3gpp_parse_cops_test_response (reply, &error);
g_assert (results == NULL);
g_assert_no_error (error);
}
@@ -432,7 +432,7 @@ test_cops_response_umts_invalid (void *f, gpointer d)
GList *results;
GError *error = NULL;
results = mm_3gpp_parse_scan_response (reply, &error);
results = mm_3gpp_parse_cops_test_response (reply, &error);
g_assert (results == NULL);
g_assert_no_error (error);
}
@@ -786,7 +786,7 @@ test_cscs_icon225_support_response (void *f, gpointer d)
MMModemCharset charsets = MM_MODEM_CHARSET_UNKNOWN;
gboolean success;
success = mm_gsm_parse_cscs_support_response (reply, &charsets);
success = mm_3gpp_parse_cscs_test_response (reply, &charsets);
g_assert (success);
g_assert (charsets == (MM_MODEM_CHARSET_IRA |
@@ -801,7 +801,7 @@ test_cscs_sierra_mercury_support_response (void *f, gpointer d)
MMModemCharset charsets = MM_MODEM_CHARSET_UNKNOWN;
gboolean success;
success = mm_gsm_parse_cscs_support_response (reply, &charsets);
success = mm_3gpp_parse_cscs_test_response (reply, &charsets);
g_assert (success);
g_assert (charsets == (MM_MODEM_CHARSET_IRA |
@@ -817,7 +817,7 @@ test_cscs_buslink_support_response (void *f, gpointer d)
MMModemCharset charsets = MM_MODEM_CHARSET_UNKNOWN;
gboolean success;
success = mm_gsm_parse_cscs_support_response (reply, &charsets);
success = mm_3gpp_parse_cscs_test_response (reply, &charsets);
g_assert (success);
g_assert (charsets == (MM_MODEM_CHARSET_8859_1 |
@@ -834,7 +834,7 @@ test_cscs_blackberry_support_response (void *f, gpointer d)
MMModemCharset charsets = MM_MODEM_CHARSET_UNKNOWN;
gboolean success;
success = mm_gsm_parse_cscs_support_response (reply, &charsets);
success = mm_3gpp_parse_cscs_test_response (reply, &charsets);
g_assert (success);
g_assert (charsets == MM_MODEM_CHARSET_IRA);
@@ -1158,7 +1158,7 @@ test_cind_results (const char *desc,
g_print ("\nTesting %s +CIND response...\n", desc);
results = mm_parse_cind_test_response (reply, &error);
results = mm_3gpp_parse_cind_test_response (reply, &error);
g_assert (results);
g_assert (error == NULL);
@@ -1166,13 +1166,13 @@ test_cind_results (const char *desc,
for (i = 0; i < expected_results_len; i++) {
CindEntry *expected = &expected_results[i];
CindResponse *compare;
MM3gppCindResponse *compare;
compare = g_hash_table_lookup (results, expected->desc);
g_assert (compare);
g_assert_cmpint (i + 1, ==, cind_response_get_index (compare));
g_assert_cmpint (expected->min, ==, cind_response_get_min (compare));
g_assert_cmpint (expected->max, ==, cind_response_get_max (compare));
g_assert_cmpint (i + 1, ==, mm_3gpp_cind_response_get_index (compare));
g_assert_cmpint (expected->min, ==, mm_3gpp_cind_response_get_min (compare));
g_assert_cmpint (expected->max, ==, mm_3gpp_cind_response_get_max (compare));
}
g_hash_table_destroy (results);
@@ -1227,7 +1227,7 @@ test_cgdcont_results (const gchar *desc,
g_print ("\nTesting %s +CGDCONT response...\n", desc);
results = mm_3gpp_parse_pdp_query_response (reply, &error);
results = mm_3gpp_parse_cgdcont_read_response (reply, &error);
g_assert (results);
g_assert_no_error (error);
g_assert_cmpuint (g_list_length (results), ==, expected_results_len);
@@ -1293,7 +1293,7 @@ test_cpms_response_cinterion (void *f, gpointer d)
g_print ("\nTesting Cinterion +CPMS=? response...\n");
g_assert (mm_3gpp_parse_cpms_format_response (reply, &mem1, &mem2, &mem3));
g_assert (mm_3gpp_parse_cpms_test_response (reply, &mem1, &mem2, &mem3));
g_assert (mem1->len == 3);
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_ME));
g_assert (is_storage_supported (mem1, MM_SMS_STORAGE_SM));
@@ -1321,7 +1321,7 @@ test_cnum_results (const gchar *desc,
g_print ("\nTesting +CNUM response (%s)...\n", desc);
results = mm_3gpp_parse_cnum_response (reply, &error);
results = mm_3gpp_parse_cnum_exec_response (reply, &error);
g_assert (results);
g_assert_no_error (error);
g_assert_cmpuint (g_strv_length (results), ==, g_strv_length (expected));