aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mm-modem-helpers.c57
-rw-r--r--src/mm-modem-helpers.h5
2 files changed, 62 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 0b4cc348..823ef514 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -294,6 +294,63 @@ mm_3gpp_parse_scan_response (const gchar *reply,
/*************************************************************************/
+#define CMGF_TAG "+CMGF:"
+
+gboolean
+mm_3gpp_parse_cmgf_format_response (const gchar *reply,
+ gboolean *sms_pdu_supported,
+ gboolean *sms_text_supported,
+ GError **error)
+{
+ GRegex *r;
+ GMatchInfo *match_info;
+ char *s;
+ guint32 min = -1, max = -1;
+
+ /* Strip whitespace and response tag */
+ if (g_str_has_prefix (reply, CMGF_TAG))
+ reply += strlen (CMGF_TAG);
+ while (isspace (*reply))
+ reply++;
+
+ r = g_regex_new ("\\(?\\s*(\\d+)\\s*[-,]?\\s*(\\d+)?\\s*\\)?", 0, 0, error);
+ if (!r)
+ return FALSE;
+
+ if (!g_regex_match_full (r, reply, strlen (reply), 0, 0, &match_info, NULL)) {
+ g_set_error (error,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_FAILED,
+ "Failed to parse CMGF query result '%s'",
+ reply);
+ g_match_info_free (match_info);
+ g_regex_unref (r);
+ return FALSE;
+ }
+
+ s = g_match_info_fetch (match_info, 1);
+ if (s)
+ min = atoi (s);
+ g_free (s);
+
+ s = g_match_info_fetch (match_info, 2);
+ if (s)
+ max = atoi (s);
+ g_free (s);
+
+ /* CMGF=0 for PDU mode */
+ *sms_pdu_supported = (min == 0);
+
+ /* CMGF=1 for Text mode */
+ *sms_text_supported = (max >= 1);
+
+ g_match_info_free (match_info);
+ g_regex_unref (r);
+ return TRUE;
+}
+
+/*************************************************************************/
+
static void
mm_3gpp_pdp_context_free (MM3gppPdpContext *pdp)
{
diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h
index 44442658..203c33be 100644
--- a/src/mm-modem-helpers.h
+++ b/src/mm-modem-helpers.h
@@ -64,6 +64,11 @@ gboolean mm_3gpp_parse_creg_response (GMatchInfo *info,
gboolean *out_cgreg,
GError **error);
+gboolean mm_3gpp_parse_cmgf_format_response (const gchar *reply,
+ gboolean *sms_pdu_supported,
+ gboolean *sms_text_supported,
+ GError **error);
+
GRegex *mm_3gpp_ciev_regex_get (void);
GRegex *mm_3gpp_cusd_regex_get (void);