[PATCH v2 12/13] ublox: new +UAUTHREQ=? tester

Aleksander Morgado aleksander at aleksander.es
Fri Sep 15 05:01:08 UTC 2017


---
 plugins/ublox/mm-modem-helpers-ublox.c         | 77 ++++++++++++++++++++++++++
 plugins/ublox/mm-modem-helpers-ublox.h         | 14 +++++
 plugins/ublox/tests/test-modem-helpers-ublox.c | 46 +++++++++++++++
 3 files changed, 137 insertions(+)

diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c
index 34ec9b4e..d31b94ac 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.c
+++ b/plugins/ublox/mm-modem-helpers-ublox.c
@@ -1295,6 +1295,83 @@ mm_ublox_build_urat_set_command (MMModemMode   allowed,
     return g_string_free (command, FALSE);
 }

+/*****************************************************************************/
+/* +UAUTHREQ=? test parser */
+
+MMUbloxBearerAllowedAuth
+mm_ublox_parse_uauthreq_test (const char  *response,
+                              GError     **error)
+{
+    MMUbloxBearerAllowedAuth   mask = MM_UBLOX_BEARER_ALLOWED_AUTH_UNKNOWN;
+    GError                    *inner_error = NULL;
+    GArray                    *allowed_auths = NULL;
+    gchar                    **split;
+    guint                      split_len;
+
+    /*
+     * Response may be like:
+     *   AT+UAUTHREQ=?
+     *   +UAUTHREQ: (1-4),(0-2),,
+     */
+    response = mm_strip_tag (response, "+UAUTHREQ:");
+    split = mm_split_string_groups (response);
+    split_len = g_strv_length (split);
+    if (split_len < 2) {
+        inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+                                   "Unexpected number of groups in +UAUTHREQ=? response: %u", g_strv_length (split));
+        goto out;
+    }
+
+    allowed_auths = mm_parse_uint_list (split[1], &inner_error);
+    if (inner_error)
+        goto out;
+
+    if (allowed_auths) {
+        guint i;
+
+        for (i = 0; i < allowed_auths->len; i++) {
+            guint val;
+
+            val = g_array_index (allowed_auths, guint, i);
+            switch (val) {
+                case 0:
+                    mask |= MM_UBLOX_BEARER_ALLOWED_AUTH_NONE;
+                    break;
+                case 1:
+                    mask |= MM_UBLOX_BEARER_ALLOWED_AUTH_PAP;
+                    break;
+                case 2:
+                    mask |= MM_UBLOX_BEARER_ALLOWED_AUTH_CHAP;
+                    break;
+                case 3:
+                    mask |= MM_UBLOX_BEARER_ALLOWED_AUTH_AUTO;
+                    break;
+                default:
+                    mm_warn ("Unexpected +UAUTHREQ value: %u", val);
+                    break;
+            }
+        }
+    }
+
+    if (!mask) {
+        inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+                                   "No supported authentication methods in +UAUTHREQ=? response");
+        goto out;
+    }
+
+out:
+    g_strfreev (split);
+
+    if (inner_error) {
+        if (allowed_auths)
+            g_array_unref (allowed_auths);
+        g_propagate_error (error, inner_error);
+        return MM_UBLOX_BEARER_ALLOWED_AUTH_UNKNOWN;
+    }
+
+    return mask;
+}
+
 /*****************************************************************************/
 /* +UGCNTRD response parser */

diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h
index a4b73108..1a51df38 100644
--- a/plugins/ublox/mm-modem-helpers-ublox.h
+++ b/plugins/ublox/mm-modem-helpers-ublox.h
@@ -147,6 +147,20 @@ gchar *mm_ublox_build_urat_set_command (MMModemMode   allowed,
                                         MMModemMode   preferred,
                                         GError      **error);

+/*****************************************************************************/
+/* +UAUTHREQ=? test parser */
+
+typedef enum { /*< underscore_name=mm_ublox_bearer_allowed_auth >*/
+    MM_UBLOX_BEARER_ALLOWED_AUTH_UNKNOWN = 0,
+    MM_UBLOX_BEARER_ALLOWED_AUTH_NONE    = 1 << 0,
+    MM_UBLOX_BEARER_ALLOWED_AUTH_PAP     = 1 << 1,
+    MM_UBLOX_BEARER_ALLOWED_AUTH_CHAP    = 1 << 2,
+    MM_UBLOX_BEARER_ALLOWED_AUTH_AUTO    = 1 << 3,
+} MMUbloxBearerAllowedAuth;
+
+MMUbloxBearerAllowedAuth mm_ublox_parse_uauthreq_test (const char  *response,
+                                                       GError     **error);
+
 /*****************************************************************************/
 /* +UGCNTRD response parser */

diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c
index b50ac8f7..cfc87d81 100644
--- a/plugins/ublox/tests/test-modem-helpers-ublox.c
+++ b/plugins/ublox/tests/test-modem-helpers-ublox.c
@@ -950,6 +950,49 @@ test_uact_request_4g (void)
     common_validate_uact_request (bands, G_N_ELEMENTS (bands), "+UACT=,,,101,103,107,108,120");
 }

+/*****************************************************************************/
+/* Test +UAUTHREQ=? responses */
+
+static void
+common_validate_uauthreq_test (const gchar              *str,
+                               MMUbloxBearerAllowedAuth  expected_allowed_auths)
+{
+    GError                   *error = NULL;
+    MMUbloxBearerAllowedAuth  allowed_auths;
+
+    allowed_auths = mm_ublox_parse_uauthreq_test (str, &error);
+    g_assert_no_error (error);
+    g_assert_cmpuint (allowed_auths, ==, expected_allowed_auths);
+}
+
+static void
+test_uauthreq_tobyl4 (void)
+{
+    common_validate_uauthreq_test ("+UAUTHREQ: (1-4),(0-2),,",
+                                   (MM_UBLOX_BEARER_ALLOWED_AUTH_NONE |
+                                    MM_UBLOX_BEARER_ALLOWED_AUTH_PAP |
+                                    MM_UBLOX_BEARER_ALLOWED_AUTH_CHAP));
+}
+
+static void
+test_uauthreq_with_auto (void)
+{
+    common_validate_uauthreq_test ("+UAUTHREQ: (1-4),(0-3),,",
+                                   (MM_UBLOX_BEARER_ALLOWED_AUTH_NONE |
+                                    MM_UBLOX_BEARER_ALLOWED_AUTH_PAP |
+                                    MM_UBLOX_BEARER_ALLOWED_AUTH_CHAP |
+                                    MM_UBLOX_BEARER_ALLOWED_AUTH_AUTO));
+}
+
+static void
+test_uauthreq_less_fields (void)
+{
+    common_validate_uauthreq_test ("+UAUTHREQ: (1-4),(0-2)",
+                                   (MM_UBLOX_BEARER_ALLOWED_AUTH_NONE |
+                                    MM_UBLOX_BEARER_ALLOWED_AUTH_PAP |
+                                    MM_UBLOX_BEARER_ALLOWED_AUTH_CHAP));
+}
+
 /*****************************************************************************/
 /* Test +UGCNTRD responses */

@@ -1092,6 +1135,9 @@ int main (int argc, char **argv)
     g_test_add_func ("/MM/ublox/uact/request/2g",  test_uact_request_2g);
     g_test_add_func ("/MM/ublox/uact/request/3g",  test_uact_request_3g);
     g_test_add_func ("/MM/ublox/uact/request/4g",  test_uact_request_4g);
+    g_test_add_func ("/MM/ublox/uauthreq/test/tobyl4", test_uauthreq_tobyl4);
+    g_test_add_func ("/MM/ublox/uauthreq/test/with-auto", test_uauthreq_with_auto);
+    g_test_add_func ("/MM/ublox/uauthreq/test/less-fields", test_uauthreq_less_fields);
     g_test_add_func ("/MM/ublox/ugcntrd/response", test_ugcntrd_response);

     return g_test_run ();
--
2.14.1


More information about the ModemManager-devel mailing list