Blame plugins/sierra/mm-modem-helpers-sierra.c

Packit d14447
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
Packit d14447
/*
Packit d14447
 * This program is free software; you can redistribute it and/or modify
Packit d14447
 * it under the terms of the GNU General Public License as published by
Packit d14447
 * the Free Software Foundation; either version 2 of the License, or
Packit d14447
 * (at your option) any later version.
Packit d14447
 *
Packit d14447
 * This program is distributed in the hope that it will be useful,
Packit d14447
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit d14447
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit d14447
 * GNU General Public License for more details:
Packit d14447
 *
Packit d14447
 * Copyright (C) 2018 Aleksander Morgado <aleksander@aleksander.es>
Packit d14447
 */
Packit d14447
Packit d14447
#include <glib.h>
Packit d14447
#include <string.h>
Packit d14447
Packit d14447
#include "mm-log.h"
Packit d14447
#include "mm-modem-helpers.h"
Packit d14447
#include "mm-modem-helpers-sierra.h"
Packit d14447
Packit d14447
GList *
Packit d14447
mm_sierra_parse_scact_read_response (const gchar  *reply,
Packit d14447
                                     GError      **error)
Packit d14447
{
Packit d14447
    GError     *inner_error = NULL;
Packit d14447
    GRegex     *r;
Packit d14447
    GMatchInfo *match_info;
Packit d14447
    GList      *list;
Packit d14447
Packit d14447
    if (!reply || !reply[0])
Packit d14447
        /* Nothing configured, all done */
Packit d14447
        return NULL;
Packit d14447
Packit d14447
    list = NULL;
Packit d14447
    r = g_regex_new ("!SCACT:\\s*(\\d+),(\\d+)",
Packit d14447
                     G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, &inner_error);
Packit d14447
    g_assert (r);
Packit d14447
Packit d14447
    g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, &inner_error);
Packit d14447
    while (!inner_error && g_match_info_matches (match_info)) {
Packit d14447
        MM3gppPdpContextActive *pdp_active;
Packit d14447
        guint cid = 0;
Packit d14447
        guint aux = 0;
Packit d14447
Packit d14447
        if (!mm_get_uint_from_match_info (match_info, 1, &cid)) {
Packit d14447
            inner_error = g_error_new (MM_CORE_ERROR,
Packit d14447
                                       MM_CORE_ERROR_FAILED,
Packit d14447
                                       "Couldn't parse CID from reply: '%s'",
Packit d14447
                                       reply);
Packit d14447
            break;
Packit d14447
        }
Packit d14447
        if (!mm_get_uint_from_match_info (match_info, 2, &aux) || (aux != 0 && aux != 1)) {
Packit d14447
            inner_error = g_error_new (MM_CORE_ERROR,
Packit d14447
                                       MM_CORE_ERROR_FAILED,
Packit d14447
                                       "Couldn't parse context status from reply: '%s'",
Packit d14447
                                       reply);
Packit d14447
            break;
Packit d14447
        }
Packit d14447
Packit d14447
        pdp_active = g_slice_new0 (MM3gppPdpContextActive);
Packit d14447
        pdp_active->cid = cid;
Packit d14447
        pdp_active->active = (gboolean) aux;
Packit d14447
        list = g_list_prepend (list, pdp_active);
Packit d14447
Packit d14447
        g_match_info_next (match_info, &inner_error);
Packit d14447
    }
Packit d14447
Packit d14447
    g_match_info_free (match_info);
Packit d14447
    g_regex_unref (r);
Packit d14447
Packit d14447
    if (inner_error) {
Packit d14447
        mm_3gpp_pdp_context_active_list_free (list);
Packit d14447
        g_propagate_error (error, inner_error);
Packit d14447
        g_prefix_error (error, "Couldn't properly parse list of active/inactive PDP contexts. ");
Packit d14447
        return NULL;
Packit d14447
    }
Packit d14447
Packit d14447
    list = g_list_sort (list, (GCompareFunc) mm_3gpp_pdp_context_active_cmp);
Packit d14447
Packit d14447
    return list;
Packit d14447
}