aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib
diff options
context:
space:
mode:
Diffstat (limited to 'libmm-glib')
-rw-r--r--libmm-glib/mm-common-helpers.c25
-rw-r--r--libmm-glib/mm-common-helpers.h1
2 files changed, 26 insertions, 0 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c
index 3f100b68..4694be8d 100644
--- a/libmm-glib/mm-common-helpers.c
+++ b/libmm-glib/mm-common-helpers.c
@@ -929,6 +929,31 @@ mm_utils_hexstr2bin (const gchar *hex, gsize *out_len)
/* End from hostap */
+gboolean
+mm_utils_ishexstr (const gchar *hex)
+{
+ gsize len;
+ gsize i;
+
+ /* Length not multiple of 2? */
+ len = strlen (hex);
+ if (len % 2 != 0)
+ return FALSE;
+
+ for (i = 0; i < len; i++) {
+ /* Non-hex char? */
+ if (hex[i] >= '0' && hex[i] <= '9')
+ continue;
+ if (hex[i] >= 'a' && hex[i] <= 'f')
+ continue;
+ if (hex[i] >= 'A' && hex[i] <= 'F')
+ continue;
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
gchar *
mm_utils_bin2hexstr (const guint8 *bin, gsize len)
{
diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h
index 6155b587..d23fc73e 100644
--- a/libmm-glib/mm-common-helpers.h
+++ b/libmm-glib/mm-common-helpers.h
@@ -99,6 +99,7 @@ const gchar *mm_sms_delivery_state_get_string_extended (guint delivery_state);
gint mm_utils_hex2byte (const gchar *hex);
gchar *mm_utils_hexstr2bin (const gchar *hex, gsize *out_len);
gchar *mm_utils_bin2hexstr (const guint8 *bin, gsize len);
+gboolean mm_utils_ishexstr (const gchar *hex);
gboolean mm_utils_check_for_single_value (guint32 value);