diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-10-07 20:52:16 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-10-07 21:12:00 +0200 |
commit | 8ddee24cc9b1a11eadd895bd928660fc7b8f0b6a (patch) | |
tree | a0e277577dceb2a659171efd655d2c0f831fd4bf | |
parent | de96243cd4fa588f22c078b838d5f8bb3529baee (diff) |
hso: use user-specified allowed authentication methods
If none of the specified methods is supported, an error is returned.
Also quote user and password using `mm_at_serial_port_quote_string()'.
-rw-r--r-- | plugins/option/mm-broadband-bearer-hso.c | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/plugins/option/mm-broadband-bearer-hso.c b/plugins/option/mm-broadband-bearer-hso.c index 999964ae..8a12f645 100644 --- a/plugins/option/mm-broadband-bearer-hso.c +++ b/plugins/option/mm-broadband-bearer-hso.c @@ -275,7 +275,7 @@ dial_3gpp_context_new (MMBroadbandBearerHso *self, static void dial_3gpp_context_complete_and_free (Dial3gppContext *ctx) { - g_simple_async_result_complete (ctx->result); + g_simple_async_result_complete_in_idle (ctx->result); g_object_unref (ctx->cancellable); g_object_unref (ctx->result); g_object_unref (ctx->primary); @@ -562,6 +562,7 @@ authenticate (Dial3gppContext *ctx) gchar *command; const gchar *user; const gchar *password; + MMBearerAllowedAuth allowed_auth; if (!auth_commands[ctx->auth_idx]) { g_simple_async_result_set_error (ctx->result, @@ -574,18 +575,54 @@ authenticate (Dial3gppContext *ctx) user = mm_bearer_properties_get_user (mm_bearer_peek_config (MM_BEARER (ctx->self))); password = mm_bearer_properties_get_password (mm_bearer_peek_config (MM_BEARER (ctx->self))); + allowed_auth = mm_bearer_properties_get_allowed_auth (mm_bearer_peek_config (MM_BEARER (ctx->self))); /* Both user and password are required; otherwise firmware returns an error */ - if (!user || !password) + if (!user || !password || allowed_auth == MM_BEARER_ALLOWED_AUTH_NONE) { + mm_dbg ("Not using authentication"); command = g_strdup_printf ("%s=%d,0", auth_commands[ctx->auth_idx], ctx->cid); - else - command = g_strdup_printf ("%s=%d,1,\"%s\",\"%s\"", + } else { + gchar *quoted_user; + gchar *quoted_password; + guint hso_auth; + + if (allowed_auth == MM_BEARER_ALLOWED_AUTH_UNKNOWN) { + mm_dbg ("Using default (PAP) authentication method"); + hso_auth = 1; + } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_PAP) { + mm_dbg ("Using PAP authentication method"); + hso_auth = 1; + } else if (allowed_auth & MM_BEARER_ALLOWED_AUTH_CHAP) { + mm_dbg ("Using CHAP authentication method"); + hso_auth = 2; + } else { + gchar *str; + + str = mm_bearer_allowed_auth_build_string_from_mask (allowed_auth); + g_simple_async_result_set_error ( + ctx->result, + MM_CORE_ERROR, + MM_CORE_ERROR_UNSUPPORTED, + "Cannot use any of the specified authentication methods (%s)", + str); + g_free (str); + dial_3gpp_context_complete_and_free (ctx); + return; + } + + quoted_user = mm_at_serial_port_quote_string (user); + quoted_password = mm_at_serial_port_quote_string (password); + command = g_strdup_printf ("%s=%d,%u,%s,%s", auth_commands[ctx->auth_idx], ctx->cid, - password, - user); + hso_auth, + quoted_password, + quoted_user); + g_free (quoted_user); + g_free (quoted_password); + } mm_base_modem_at_command_full (ctx->modem, ctx->primary, |