From 1ffcb163493edf82bc7102b028450fca40b4dddd Mon Sep 17 00:00:00 2001 From: Matthew Stanger Date: Sun, 23 Oct 2016 19:28:19 -0600 Subject: cinterion: implement support for the new SWWAN interface --- plugins/cinterion/mm-modem-helpers-cinterion.c | 81 ++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'plugins/cinterion/mm-modem-helpers-cinterion.c') diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index bffe00a9..6312e782 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -10,12 +10,15 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * + * Copyright (C) 2016 Trimble Navigation Limited * Copyright (C) 2014 Aleksander Morgado + * Contributor: Matthew Stanger */ #include #include #include +#include #include "ModemManager.h" #define _LIBMM_INSIDE_MM @@ -24,6 +27,7 @@ #include "mm-charsets.h" #include "mm-errors-types.h" #include "mm-modem-helpers-cinterion.h" +#include "mm-modem-helpers.h" /* Setup relationship between the 3G band bitmask in the modem and the bitmask * in ModemManager. */ @@ -480,5 +484,82 @@ mm_cinterion_parse_sind_response (const gchar *response, return FALSE; } + return TRUE; +} + +/*****************************************************************************/ +/* ^SWWAN read parser + * Description: Parses , [, ] or CME ERROR from SWWAN. + * Return: False if error occured while trying to parse SWWAN. + * Read Command + * AT^SWWAN? + * Response(s) + * [^SWWAN: , [, ]] + * [^SWWAN: ...] + * OK + * ERROR + * +CME ERROR: + * + * Examples: + * OK - If no WWAN connection is active, then read command just returns OK + * ^SWWAN: 3,1,1 - 3rd PDP Context, Activated, First WWAN Adaptor + * +CME ERROR: ? - +*/ + +gboolean +mm_cinterion_parse_swwan_response (const gchar *response, + GList **result, + GError **error) +{ + if (*error) + return FALSE; + + if (!response) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Recieved NULL from SWWAN response."); + return FALSE; + } + + /* Parse for [^SWWAN: , [, ]] */ + if (strcasestr (response, "SWWAN")) { + gint matched; + guint cid, state, wwan_adapter; + matched = sscanf (response, "^SWWAN: %d,%d,%d", + &cid, + &state, + &wwan_adapter); + + if (matched != 3 || + cid < 1 || cid > 16 || + state < 0 || state > 1 || + wwan_adapter < 1 || wwan_adapter > 2) { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Invalid format for SWWAN response: '%s'", + response); + return FALSE; + } + + *result = g_list_append (*result, GINT_TO_POINTER(cid)); + *result = g_list_append (*result, GINT_TO_POINTER(state)); + *result = g_list_append (*result, GINT_TO_POINTER(wwan_adapter)); + } + /* TODO: It'd be nice to get 'OK' from response so we don't have to assume that + * zero length response means 'OK' or am I doing it wrong?... */ + else if (!g_utf8_strlen (response, 100)) + *result = g_list_append (*result, GINT_TO_POINTER(0)); + else { + g_set_error (error, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Could not parse SWWAN response: '%s'", + response); + return FALSE; + } + + return TRUE; } -- cgit v1.2.3-70-g09d2