aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-01-04 22:42:47 +0100
committerAleksander Morgado <aleksander@lanedo.com>2012-03-15 14:14:45 +0100
commit9efabb8fcb9aa0c8e7d8afb3e313082fc9773e64 (patch)
tree304588d3d564ea47fa6078532942790904832235 /src/mm-modem-helpers.c
parent44289da5316d8a90d6016d181d828d754a4e2096 (diff)
modem-helpers: new CDMA helper parsers
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r--src/mm-modem-helpers.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 780c8ded..53aebb82 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -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)
{