diff options
-rw-r--r-- | drivers/atmodem/atutil.c | 96 | ||||
-rw-r--r-- | drivers/atmodem/atutil.h | 6 |
2 files changed, 102 insertions, 0 deletions
diff --git a/drivers/atmodem/atutil.c b/drivers/atmodem/atutil.c index a1d97dd8..1098e1e3 100644 --- a/drivers/atmodem/atutil.c +++ b/drivers/atmodem/atutil.c @@ -147,3 +147,99 @@ GSList *at_util_parse_clcc(GAtResult *result) return l; } +gboolean at_util_parse_reg_unsolicited(GAtResult *result, const char *prefix, + int *status, + int *lac, int *ci, int *tech) +{ + GAtResultIter iter; + int s; + int l = -1, c = -1, t = -1; + const char *str; + + g_at_result_iter_init(&iter, result); + + if (g_at_result_iter_next(&iter, prefix) == FALSE) + return FALSE; + + if (g_at_result_iter_next_number(&iter, &s) == FALSE) + return FALSE; + + if (g_at_result_iter_next_string(&iter, &str) == TRUE) + l = strtol(str, NULL, 16); + else + goto out; + + if (g_at_result_iter_next_string(&iter, &str) == TRUE) + c = strtol(str, NULL, 16); + else + goto out; + + g_at_result_iter_next_number(&iter, &t); + +out: + if (status) + *status = s; + + if (lac) + *lac = l; + + if (ci) + *ci = c; + + if (tech) + *tech = t; + + return TRUE; +} + +gboolean at_util_parse_reg(GAtResult *result, const char *prefix, + int *mode, int *status, + int *lac, int *ci, int *tech) +{ + GAtResultIter iter; + int m, s; + int l = -1, c = -1, t = -1; + const char *str; + + g_at_result_iter_init(&iter, result); + + while (g_at_result_iter_next(&iter, prefix)) { + g_at_result_iter_next_number(&iter, &m); + + /* Sometimes we get an unsolicited CREG/CGREG here, skip it */ + if (g_at_result_iter_next_number(&iter, &s) == FALSE) + continue; + + if (g_at_result_iter_next_string(&iter, &str) == TRUE) + l = strtol(str, NULL, 16); + else + goto out; + + if (g_at_result_iter_next_string(&iter, &str) == TRUE) + c = strtol(str, NULL, 16); + else + goto out; + + g_at_result_iter_next_number(&iter, &t); + +out: + if (mode) + *mode = m; + + if (status) + *status = s; + + if (lac) + *lac = l; + + if (ci) + *ci = c; + + if (tech) + *tech = t; + + return TRUE; + } + + return FALSE; +} diff --git a/drivers/atmodem/atutil.h b/drivers/atmodem/atutil.h index 2848b272..9c6e9b91 100644 --- a/drivers/atmodem/atutil.h +++ b/drivers/atmodem/atutil.h @@ -25,6 +25,12 @@ gint at_util_call_compare_by_status(gconstpointer a, gconstpointer b); gint at_util_call_compare_by_phone_number(gconstpointer a, gconstpointer b); gint at_util_call_compare(gconstpointer a, gconstpointer b); GSList *at_util_parse_clcc(GAtResult *result); +gboolean at_util_parse_reg(GAtResult *result, const char *prefix, + int *mode, int *status, + int *lac, int *ci, int *tech); +gboolean at_util_parse_reg_unsolicited(GAtResult *result, const char *prefix, + int *status, int *lac, + int *ci, int *tech); struct cb_data { void *cb; |