diff options
-rw-r--r-- | plugins/ublox/mm-modem-helpers-ublox.c | 77 | ||||
-rw-r--r-- | plugins/ublox/mm-modem-helpers-ublox.h | 14 | ||||
-rw-r--r-- | plugins/ublox/tests/test-modem-helpers-ublox.c | 46 |
3 files changed, 137 insertions, 0 deletions
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 @@ -1296,6 +1296,83 @@ mm_ublox_build_urat_set_command (MMModemMode allowed, } /*****************************************************************************/ +/* +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 */ gboolean 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 @@ -148,6 +148,20 @@ gchar *mm_ublox_build_urat_set_command (MMModemMode allowed, 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 */ gboolean mm_ublox_parse_ugcntrd_response_for_cid (const gchar *response, 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 @@ -951,6 +951,49 @@ test_uact_request_4g (void) } /*****************************************************************************/ +/* 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 */ typedef struct { @@ -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 (); |