modem-helpers: new CDMA helper parsers

This commit is contained in:
Aleksander Morgado
2012-01-04 22:42:47 +01:00
parent 44289da531
commit 9efabb8fcb
4 changed files with 78 additions and 5 deletions

View File

@@ -1174,8 +1174,8 @@ mm_iface_modem_cdma_initialize (MMIfaceModemCdma *self,
/* Set all initial property defaults */
mm_gdbus_modem_cdma_set_meid (skeleton, NULL);
mm_gdbus_modem_cdma_set_esn (skeleton, NULL);
mm_gdbus_modem_cdma_set_sid (skeleton, MM_IFACE_MODEM_CDMA_SID_UNKNOWN);
mm_gdbus_modem_cdma_set_nid (skeleton, MM_IFACE_MODEM_CDMA_NID_UNKNOWN);
mm_gdbus_modem_cdma_set_sid (skeleton, MM_MODEM_CDMA_SID_UNKNOWN);
mm_gdbus_modem_cdma_set_nid (skeleton, MM_MODEM_CDMA_NID_UNKNOWN);
/* Bind our Registration State properties */
g_object_bind_property (self, MM_IFACE_MODEM_CDMA_CDMA1X_REGISTRATION_STATE,

View File

@@ -34,9 +34,6 @@
#define MM_IFACE_MODEM_CDMA_EVDO_NETWORK_SUPPORTED "iface-modem-cdma-evdo-network-supported"
#define MM_IFACE_MODEM_CDMA_CDMA1X_NETWORK_SUPPORTED "iface-modem-cdma-cdma1x-network-supported"
#define MM_IFACE_MODEM_CDMA_SID_UNKNOWN 99999
#define MM_IFACE_MODEM_CDMA_NID_UNKNOWN 99999
typedef struct _MMIfaceModemCdma MMIfaceModemCdma;
struct _MMIfaceModemCdma {

View File

@@ -1529,6 +1529,74 @@ done:
return array;
}
gint
mm_cdma_normalize_class (const gchar *orig_class)
{
gchar class;
g_return_val_if_fail (orig_class != NULL, '0');
class = toupper (orig_class[0]);
/* Cellular (850MHz) */
if (class == '1' || class == 'C')
return 1;
/* PCS (1900MHz) */
if (class == '2' || class == 'P')
return 2;
/* Unknown/not registered */
return 0;
}
gchar
mm_cdma_normalize_band (const gchar *long_band,
gint *out_class)
{
gchar band;
g_return_val_if_fail (long_band != NULL, 'Z');
/* There are two response formats for the band; one includes the band
* class and the other doesn't. For modems that include the band class
* (ex Novatel S720) you'll see "Px" or "Cx" depending on whether the modem
* is registered on a PCS/1900 (P) or Cellular/850 (C) system.
*/
band = toupper (long_band[0]);
/* Possible band class in first position; return it */
if (band == 'C' || band == 'P') {
gchar tmp[2] = { band, '\0' };
*out_class = mm_cdma_normalize_class (tmp);
band = toupper (long_band[1]);
}
/* normalize to A - F, and Z */
if (band >= 'A' && band <= 'F')
return band;
/* Unknown/not registered */
return 'Z';
}
gint
mm_cdma_convert_sid (const gchar *sid)
{
glong tmp_sid;
g_return_val_if_fail (sid != NULL, MM_MODEM_CDMA_SID_UNKNOWN);
errno = 0;
tmp_sid = strtol (sid, NULL, 10);
if ((errno == EINVAL) || (errno == ERANGE))
return MM_MODEM_CDMA_SID_UNKNOWN;
else if (tmp_sid < G_MININT || tmp_sid > G_MAXINT)
return MM_MODEM_CDMA_SID_UNKNOWN;
return (gint) tmp_sid;
}
guint
mm_count_bits_set (gulong number)
{

View File

@@ -110,6 +110,14 @@ 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 */