diff options
author | Carlo Lobrano <c.lobrano@gmail.com> | 2015-12-16 15:38:58 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2015-12-19 11:39:48 +0100 |
commit | c4ffe572aeeefac240f16822ca1d2d258f78ad8d (patch) | |
tree | 7cd1ad57085f137195c75cb2e79c3b5535c8648d /plugins/telit/mm-modem-helpers-telit.c | |
parent | 7978225934dc87bc74fac4d79a1080bc0501e581 (diff) |
telit: add load_unlock_retries interface
Diffstat (limited to 'plugins/telit/mm-modem-helpers-telit.c')
-rw-r--r-- | plugins/telit/mm-modem-helpers-telit.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/plugins/telit/mm-modem-helpers-telit.c b/plugins/telit/mm-modem-helpers-telit.c new file mode 100644 index 00000000..1ee046f0 --- /dev/null +++ b/plugins/telit/mm-modem-helpers-telit.c @@ -0,0 +1,75 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details: + * + * Copyright (C) 2015 Telit. + * + */ + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +#include <ModemManager.h> +#define _LIBMM_INSIDE_MMCLI +#include <libmm-glib.h> + +#include "mm-log.h" +#include "mm-modem-helpers.h" +#include "mm-modem-helpers-telit.h" + +/*****************************************************************************/ +/* +CSIM response parser */ + +gint parse_csim_response (const guint step, const gchar* response, GError** error) +{ + GRegex *r = NULL; + GMatchInfo *match_info = NULL; + gchar* retries_hex_str; + guint retries; + + r = g_regex_new ("\\+CSIM:\\s*[0-9]+,\\s*.*63C(.*)\"", G_REGEX_RAW, 0, NULL); + + if (!g_regex_match (r, response, 0, &match_info)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Could not parse reponse '%s'", response); + g_match_info_free (match_info); + g_regex_unref (r); + return -1; + } + + if (!g_match_info_matches (match_info)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Could not find matches in response '%s'", response); + g_match_info_free (match_info); + g_regex_unref (r); + return -1; + } + + retries_hex_str = mm_get_string_unquoted_from_match_info (match_info, 1); + g_assert (NULL != retries_hex_str); + + /* convert hex value to uint */ + if (sscanf (retries_hex_str, "%x", &retries) != 1) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Could not get retry value from match '%s'", + retries_hex_str); + g_match_info_free (match_info); + g_regex_unref (r); + return -1; + } + + g_free (retries_hex_str); + g_match_info_free (match_info); + g_regex_unref (r); + + return retries; +} |