aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r--src/mm-modem-helpers.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index ff3aab8f..e6e158cc 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -1101,6 +1101,90 @@ mm_3gpp_parse_cgdcont_read_response (const gchar *reply,
/*************************************************************************/
+static void
+mm_3gpp_pdp_context_active_free (MM3gppPdpContextActive *pdp_active)
+{
+ g_slice_free (MM3gppPdpContextActive, pdp_active);
+}
+
+void
+mm_3gpp_pdp_context_active_list_free (GList *pdp_active_list)
+{
+ g_list_free_full (pdp_active_list, (GDestroyNotify) mm_3gpp_pdp_context_active_free);
+}
+
+static gint
+mm_3gpp_pdp_context_active_cmp (MM3gppPdpContextActive *a,
+ MM3gppPdpContextActive *b)
+{
+ return (a->cid - b->cid);
+}
+
+GList *
+mm_3gpp_parse_cgact_read_response (const gchar *reply,
+ GError **error)
+{
+ GError *inner_error = NULL;
+ GRegex *r;
+ GMatchInfo *match_info;
+ GList *list;
+
+ if (!reply || !reply[0])
+ /* Nothing configured, all done */
+ return NULL;
+
+ list = NULL;
+ r = g_regex_new ("\\+CGACT:\\s*(\\d+),(\\d+)",
+ G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, &inner_error);
+ g_assert (r);
+
+ g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, &inner_error);
+ while (!inner_error && g_match_info_matches (match_info)) {
+ MM3gppPdpContextActive *pdp_active;
+ guint cid = 0;
+ guint aux = 0;
+
+ if (!mm_get_uint_from_match_info (match_info, 1, &cid)) {
+ inner_error = g_error_new (MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Couldn't parse CID from reply: '%s'",
+ reply);
+ break;
+ }
+ if (!mm_get_uint_from_match_info (match_info, 2, &aux) || (aux != 0 && aux != 1)) {
+ inner_error = g_error_new (MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Couldn't parse context status from reply: '%s'",
+ reply);
+ break;
+ }
+
+ pdp_active = g_slice_new0 (MM3gppPdpContextActive);
+ pdp_active->cid = cid;
+ pdp_active->active = (gboolean) aux;
+ list = g_list_prepend (list, pdp_active);
+
+ g_match_info_next (match_info, &inner_error);
+ }
+
+ if (match_info)
+ g_match_info_free (match_info);
+ g_regex_unref (r);
+
+ if (inner_error) {
+ mm_3gpp_pdp_context_active_list_free (list);
+ g_propagate_error (error, inner_error);
+ g_prefix_error (error, "Couldn't properly parse list of active/inactive PDP contexts. ");
+ return NULL;
+ }
+
+ list = g_list_sort (list, (GCompareFunc) mm_3gpp_pdp_context_active_cmp);
+
+ return list;
+}
+
+/*************************************************************************/
+
static gulong
parse_uint (char *str, int base, glong nmin, glong nmax, gboolean *valid)
{