diff options
Diffstat (limited to 'plugins/cinterion/mm-modem-helpers-cinterion.c')
-rw-r--r-- | plugins/cinterion/mm-modem-helpers-cinterion.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/plugins/cinterion/mm-modem-helpers-cinterion.c b/plugins/cinterion/mm-modem-helpers-cinterion.c index bff03a90..bb449505 100644 --- a/plugins/cinterion/mm-modem-helpers-cinterion.c +++ b/plugins/cinterion/mm-modem-helpers-cinterion.c @@ -29,6 +29,7 @@ #include "mm-errors-types.h" #include "mm-modem-helpers-cinterion.h" #include "mm-modem-helpers.h" +#include "mm-port-serial-at.h" /* Setup relationship between the 3G band bitmask in the modem and the bitmask * in ModemManager. */ @@ -1450,3 +1451,113 @@ mm_cinterion_provcfg_response_to_cid (const gchar *response, /* in all other cases no change to the preset value */ } } + +/*****************************************************************************/ +/* Auth related helpers */ + +typedef enum { + BEARER_CINTERION_AUTH_UNKNOWN = -1, + BEARER_CINTERION_AUTH_NONE = 0, + BEARER_CINTERION_AUTH_PAP = 1, + BEARER_CINTERION_AUTH_CHAP = 2, + BEARER_CINTERION_AUTH_MSCHAPV2 = 3, +} BearerCinterionAuthType; + +static BearerCinterionAuthType +parse_auth_type (MMBearerAllowedAuth mm_auth) +{ + switch (mm_auth) { + case MM_BEARER_ALLOWED_AUTH_NONE: + return BEARER_CINTERION_AUTH_NONE; + case MM_BEARER_ALLOWED_AUTH_PAP: + return BEARER_CINTERION_AUTH_PAP; + case MM_BEARER_ALLOWED_AUTH_CHAP: + return BEARER_CINTERION_AUTH_CHAP; + case MM_BEARER_ALLOWED_AUTH_MSCHAPV2: + return BEARER_CINTERION_AUTH_MSCHAPV2; + case MM_BEARER_ALLOWED_AUTH_UNKNOWN: + case MM_BEARER_ALLOWED_AUTH_MSCHAP: + case MM_BEARER_ALLOWED_AUTH_EAP: + default: + return BEARER_CINTERION_AUTH_UNKNOWN; + } +} + +MMBearerAllowedAuth +mm_auth_type_from_cinterion_auth_type (guint cinterion_auth) +{ + switch (cinterion_auth) { + case BEARER_CINTERION_AUTH_NONE: + return MM_BEARER_ALLOWED_AUTH_NONE; + case BEARER_CINTERION_AUTH_PAP: + return MM_BEARER_ALLOWED_AUTH_PAP; + case BEARER_CINTERION_AUTH_CHAP: + return MM_BEARER_ALLOWED_AUTH_CHAP; + default: + return MM_BEARER_ALLOWED_AUTH_UNKNOWN; + } +} + +/* Cinterion authentication is done with the command AT^SGAUTH, + whose syntax depends on the modem family, as follow: + - AT^SGAUTH=<cid>[, <auth_type>[, <user>, <passwd>]] for the IMT family + - AT^SGAUTH=<cid>[, <auth_type>[, <passwd>, <user>]] for the rest */ +gchar * +mm_cinterion_build_auth_string (gpointer log_object, + MMCinterionModemFamily modem_family, + MMBearerProperties *config, + guint cid) +{ + MMBearerAllowedAuth auth; + BearerCinterionAuthType encoded_auth = BEARER_CINTERION_AUTH_UNKNOWN; + gboolean has_user; + gboolean has_passwd; + const gchar *user; + const gchar *passwd; + g_autofree gchar *quoted_user = NULL; + g_autofree gchar *quoted_passwd = NULL; + + user = mm_bearer_properties_get_user (config); + passwd = mm_bearer_properties_get_password (config); + auth = mm_bearer_properties_get_allowed_auth (config); + + has_user = (user && user[0]); + has_passwd = (passwd && passwd[0]); + encoded_auth = parse_auth_type (auth); + + /* When 'none' requested, we won't require user/password */ + if (encoded_auth == BEARER_CINTERION_AUTH_NONE) { + if (has_user || has_passwd) + mm_obj_warn (log_object, "APN user/password given but 'none' authentication requested"); + if (modem_family == MM_CINTERION_MODEM_FAMILY_IMT) + return g_strdup_printf ("^SGAUTH=%u,%d,\"\",\"\"", cid, encoded_auth); + return g_strdup_printf ("^SGAUTH=%u,%d", cid, encoded_auth); + } + + /* No explicit auth type requested? */ + if (encoded_auth == BEARER_CINTERION_AUTH_UNKNOWN) { + /* If no user/passwd given, do nothing */ + if (!has_user && !has_passwd) + return NULL; + + /* If user/passwd given, default to CHAP (more common than PAP) */ + mm_obj_dbg (log_object, "APN user/password given but no authentication type explicitly requested: defaulting to 'CHAP'"); + encoded_auth = BEARER_CINTERION_AUTH_CHAP; + } + + quoted_user = mm_port_serial_at_quote_string (user ? user : ""); + quoted_passwd = mm_port_serial_at_quote_string (passwd ? passwd : ""); + + if (modem_family == MM_CINTERION_MODEM_FAMILY_IMT) + return g_strdup_printf ("^SGAUTH=%u,%d,%s,%s", + cid, + encoded_auth, + quoted_user, + quoted_passwd); + + return g_strdup_printf ("^SGAUTH=%u,%d,%s,%s", + cid, + encoded_auth, + quoted_passwd, + quoted_user); +} |