api,libmm-glib: new `allowed-auth' configuration for bearers

For bearers using STATIC or DHCP IP method, the modem itself is the one
negotiating authentication with the network. The new `allowed-auth' property
allows users to specify which authentication method(s) are allowed to be used.

See the following NetworkManager commit for more reference:
    commit 34aef8aaaa09b7473b9496aa49e550bd2def03f8
    Author: Andrew Bird <ajb@spheresystems.co.uk>
    Date:   Thu Mar 15 16:19:43 2012 -0500
This commit is contained in:
Aleksander Morgado
2012-10-07 20:19:13 +02:00
parent 7ae18eecdd
commit ebd792d2aa
11 changed files with 233 additions and 31 deletions

View File

@@ -3,6 +3,7 @@
<TITLE>Flags and Enumerations</TITLE>
MMBearerIpFamily
MMBearerIpMethod
MMBearerAllowedAuth
MMFirmwareImageType
MMModem3gppFacility
MMModem3gppNetworkAvailability

View File

@@ -604,8 +604,10 @@ mm_simple_connect_properties_get_allowed_modes
mm_simple_connect_properties_set_allowed_modes
mm_simple_connect_properties_get_apn
mm_simple_connect_properties_set_apn
mm_simple_connect_properties_set_user
mm_simple_connect_properties_get_allowed_auth
mm_simple_connect_properties_set_allowed_auth
mm_simple_connect_properties_get_user
mm_simple_connect_properties_set_user
mm_simple_connect_properties_get_password
mm_simple_connect_properties_set_password
mm_simple_connect_properties_get_ip_type
@@ -752,8 +754,10 @@ mm_bearer_properties_new
<SUBSECTION GettersSetters>
mm_bearer_properties_get_apn
mm_bearer_properties_set_apn
mm_bearer_properties_set_user
mm_bearer_properties_get_allowed_auth
mm_bearer_properties_set_allowed_auth
mm_bearer_properties_get_user
mm_bearer_properties_set_user
mm_bearer_properties_get_password
mm_bearer_properties_set_password
mm_bearer_properties_get_ip_type
@@ -917,6 +921,7 @@ mm_sms_properties_get_type
<TITLE>Flags and Enumerations</TITLE>
mm_bearer_ip_method_get_string
mm_bearer_ip_family_get_string
mm_bearer_allowed_auth_build_string_from_mask
mm_modem_capability_build_string_from_mask
mm_modem_state_get_string
mm_modem_state_change_reason_get_string
@@ -954,6 +959,7 @@ mm_modem_location_source_get_string
mm_modem_contacts_storage_build_string_from_mask
mm_bearer_ip_family_build_string_from_mask
mm_bearer_ip_method_build_string_from_mask
mm_bearer_allowed_auth_get_string
mm_modem_cdma_registration_state_build_string_from_mask
mm_modem_cdma_activation_state_build_string_from_mask
mm_modem_cdma_rm_protocol_build_string_from_mask
@@ -965,6 +971,7 @@ mm_firmware_image_type_build_string_from_mask
<SUBSECTION Standard>
MM_TYPE_BEARER_IP_FAMILY
MM_TYPE_BEARER_IP_METHOD
MM_TYPE_BEARER_ALLOWED_AUTH
MM_TYPE_FIRMWARE_IMAGE_TYPE
MM_TYPE_MODEM_3GPP_FACILITY
MM_TYPE_MODEM_3GPP_NETWORK_AVAILABILITY
@@ -988,6 +995,7 @@ MM_TYPE_SMS_STATE
MM_TYPE_SMS_STORAGE
mm_bearer_ip_family_get_type
mm_bearer_ip_method_get_type
mm_bearer_allowed_auth_get_type
mm_firmware_image_type_get_type
mm_modem_3gpp_facility_get_type
mm_modem_3gpp_network_availability_get_type

View File

@@ -551,6 +551,29 @@ typedef enum { /*< underscore_name=mm_bearer_ip_family >*/
MM_BEARER_IP_FAMILY_IPV4V6 = 10
} MMBearerIpFamily;
/**
* MMBearerAllowedAuth:
* @MM_BEARER_ALLOWED_AUTH_UNKNOWN: Unknown.
* @MM_BEARER_ALLOWED_AUTH_NONE: None.
* @MM_BEARER_ALLOWED_AUTH_PAP: PAP.
* @MM_BEARER_ALLOWED_AUTH_CHAP: CHAP.
* @MM_BEARER_ALLOWED_AUTH_MSCHAP: MS-CHAP.
* @MM_BEARER_ALLOWED_AUTH_MSCHAPV2: MS-CHAP v2.
* @MM_BEARER_ALLOWED_AUTH_EAP: EAP.
*
* Allowed authentication methods when authenticating with the network.
*/
typedef enum { /*< underscore_name=mm_bearer_allowed_auth >*/
MM_BEARER_ALLOWED_AUTH_UNKNOWN = 0,
/* bits 0..4 order match Ericsson device bitmap */
MM_BEARER_ALLOWED_AUTH_NONE = 1 << 0,
MM_BEARER_ALLOWED_AUTH_PAP = 1 << 1,
MM_BEARER_ALLOWED_AUTH_CHAP = 1 << 2,
MM_BEARER_ALLOWED_AUTH_MSCHAP = 1 << 3,
MM_BEARER_ALLOWED_AUTH_MSCHAPV2 = 1 << 4,
MM_BEARER_ALLOWED_AUTH_EAP = 1 << 5,
} MMBearerAllowedAuth;
/**
* MMModemCdmaRegistrationState:
* @MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN: Registration status is unknown or the device is not registered.

View File

@@ -86,6 +86,13 @@
value (signature <literal>"u"</literal>).
</listitem>
</varlistentry>
<varlistentry><term><literal>"allowed-auth"</literal></term>
<listitem>
The authentication method to use, given as a
<link linkend="MMBearerAllowedAuth">MMBearerAllowedAuth</link>
value (signature <literal>"u"</literal>). Optional in 3GPP.
</listitem>
</varlistentry>
<varlistentry><term><literal>"user"</literal></term>
<listitem>
User name (if any) required by the network, given as a string

View File

@@ -63,6 +63,8 @@
<listitem><para>Access Point Name, given as a string value (signature <literal>"s"</literal>). Required in 3GPP.</para></listitem></varlistentry>
<varlistentry><term><literal>"ip-type"</literal></term>
<listitem><para>Addressing type, given as a <link linkend="MMBearerIpFamily">MMBearerIpFamily</link> value (signature <literal>"u"</literal>). Optional in 3GPP and CDMA.</para></listitem></varlistentry>
<varlistentry><term><literal>"allowed-auth"</literal></term>
<listitem><para>The authentication method to use, given as a <link linkend="MMBearerAllowedAuth">MMBearerAllowedAuth</link> value (signature <literal>"u"</literal>). Optional in 3GPP.</para></listitem></varlistentry>
<varlistentry><term><literal>"user"</literal></term>
<listitem><para>User name (if any) required by the network, given as a string value (signature <literal>"s"</literal>). Optional in 3GPP.</para></listitem></varlistentry>
<varlistentry><term><literal>"password"</literal></term>

View File

@@ -34,6 +34,7 @@
G_DEFINE_TYPE (MMBearerProperties, mm_bearer_properties, G_TYPE_OBJECT);
#define PROPERTY_APN "apn"
#define PROPERTY_ALLOWED_AUTH "allowed-auth"
#define PROPERTY_USER "user"
#define PROPERTY_PASSWORD "password"
#define PROPERTY_IP_TYPE "ip-type"
@@ -46,6 +47,8 @@ struct _MMBearerPropertiesPrivate {
gchar *apn;
/* IP type */
MMBearerIpFamily ip_type;
/* Allowed auth */
MMBearerAllowedAuth allowed_auth;
/* Number */
gchar *number;
/* User */
@@ -96,6 +99,40 @@ mm_bearer_properties_get_apn (MMBearerProperties *self)
/*****************************************************************************/
/**
* mm_bearer_properties_set_allowed_auth:
* @self: a #MMBearerProperties.
* @allowed_auth: a bitmask of #MMBearerAllowedAuth values. %MM_BEARER_ALLOWED_AUTH_UNKNOWN may be given to request the modem-default method.
*
* Sets the authentication method to use.
*/
void
mm_bearer_properties_set_allowed_auth (MMBearerProperties *self,
MMBearerAllowedAuth allowed_auth)
{
g_return_if_fail (MM_IS_BEARER_PROPERTIES (self));
self->priv->allowed_auth = allowed_auth;
}
/**
* mm_bearer_properties_get_allowed_auth:
* @self: a #MMBearerProperties.
*
* Gets the authentication methods allowed in the connection.
*
* Returns: a bitmask of #MMBearerAllowedAuth values, or %MM_BEARER_ALLOWED_AUTH_UNKNOWN to request the modem-default method.
*/
MMBearerAllowedAuth
mm_bearer_properties_get_allowed_auth (MMBearerProperties *self)
{
g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), MM_BEARER_ALLOWED_AUTH_UNKNOWN);
return self->priv->allowed_auth;
}
/*****************************************************************************/
/**
* mm_bearer_properties_set_user:
* @self: a #MMBearerProperties.
@@ -324,6 +361,12 @@ mm_bearer_properties_get_dictionary (MMBearerProperties *self)
PROPERTY_APN,
g_variant_new_string (self->priv->apn));
if (self->priv->allowed_auth != MM_BEARER_ALLOWED_AUTH_UNKNOWN)
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_ALLOWED_AUTH,
g_variant_new_uint32 (self->priv->allowed_auth));
if (self->priv->user)
g_variant_builder_add (&builder,
"{sv}",
@@ -375,7 +418,17 @@ mm_bearer_properties_consume_string (MMBearerProperties *self,
if (g_str_equal (key, PROPERTY_APN))
mm_bearer_properties_set_apn (self, value);
else if (g_str_equal (key, PROPERTY_USER))
else if (g_str_equal (key, PROPERTY_ALLOWED_AUTH)) {
GError *inner_error = NULL;
MMBearerAllowedAuth allowed_auth;
allowed_auth = mm_common_get_allowed_auth_from_string (value, &inner_error);
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
}
mm_bearer_properties_set_allowed_auth (self, allowed_auth);
} else if (g_str_equal (key, PROPERTY_USER))
mm_bearer_properties_set_user (self, value);
else if (g_str_equal (key, PROPERTY_PASSWORD))
mm_bearer_properties_set_password (self, value);
@@ -476,6 +529,10 @@ mm_bearer_properties_consume_variant (MMBearerProperties *properties,
mm_bearer_properties_set_apn (
properties,
g_variant_get_string (value, NULL));
else if (g_str_equal (key, PROPERTY_ALLOWED_AUTH))
mm_bearer_properties_set_allowed_auth (
properties,
g_variant_get_uint32 (value));
else if (g_str_equal (key, PROPERTY_USER))
mm_bearer_properties_set_user (
properties,
@@ -582,6 +639,7 @@ mm_bearer_properties_cmp (MMBearerProperties *a,
return ((!g_strcmp0 (a->priv->apn, b->priv->apn)) &&
(a->priv->ip_type == b->priv->ip_type) &&
(!g_strcmp0 (a->priv->number, b->priv->number)) &&
(a->priv->allowed_auth == b->priv->allowed_auth) &&
(!g_strcmp0 (a->priv->user, b->priv->user)) &&
(!g_strcmp0 (a->priv->password, b->priv->password)) &&
(a->priv->allow_roaming == b->priv->allow_roaming) &&
@@ -615,6 +673,7 @@ mm_bearer_properties_init (MMBearerProperties *self)
/* Some defaults */
self->priv->allow_roaming = TRUE;
self->priv->rm_protocol = MM_MODEM_CDMA_RM_PROTOCOL_UNKNOWN;
self->priv->allowed_auth = MM_BEARER_ALLOWED_AUTH_UNKNOWN;
/* At some point in the future, this default should probably be changed
* to IPV4V6. However, presently support for this PDP type is rare. An

View File

@@ -59,6 +59,8 @@ MMBearerProperties *mm_bearer_properties_new (void);
void mm_bearer_properties_set_apn (MMBearerProperties *self,
const gchar *apn);
void mm_bearer_properties_set_allowed_auth (MMBearerProperties *self,
MMBearerAllowedAuth allowed_auth);
void mm_bearer_properties_set_user (MMBearerProperties *self,
const gchar *user);
void mm_bearer_properties_set_password (MMBearerProperties *self,
@@ -73,6 +75,7 @@ void mm_bearer_properties_set_rm_protocol (MMBearerProperties *self,
MMModemCdmaRmProtocol protocol);
const gchar *mm_bearer_properties_get_apn (MMBearerProperties *self);
MMBearerAllowedAuth mm_bearer_properties_get_allowed_auth (MMBearerProperties *self);
const gchar *mm_bearer_properties_get_user (MMBearerProperties *self);
const gchar *mm_bearer_properties_get_password (MMBearerProperties *self);
MMBearerIpFamily mm_bearer_properties_get_ip_type (MMBearerProperties *self);

View File

@@ -417,6 +417,66 @@ mm_common_get_ip_type_from_string (const gchar *str,
return MM_BEARER_IP_FAMILY_UNKNOWN;
}
MMBearerAllowedAuth
mm_common_get_allowed_auth_from_string (const gchar *str,
GError **error)
{
GError *inner_error = NULL;
MMBearerAllowedAuth allowed_auth;
gchar **strings;
GFlagsClass *flags_class;
allowed_auth = MM_BEARER_ALLOWED_AUTH_UNKNOWN;
flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_BEARER_ALLOWED_AUTH));
strings = g_strsplit (str, "|", -1);
if (strings) {
guint i;
for (i = 0; strings[i]; i++) {
guint j;
gboolean found = FALSE;
for (j = 0; flags_class->values[j].value_nick; j++) {
if (!g_ascii_strcasecmp (strings[i], flags_class->values[j].value_nick)) {
allowed_auth |= flags_class->values[j].value;
found = TRUE;
break;
}
}
if (!found) {
inner_error = g_error_new (
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Couldn't match '%s' with a valid MMBearerAllowedAuth value",
strings[i]);
break;
}
}
}
if (inner_error) {
g_propagate_error (error, inner_error);
allowed_auth = MM_BEARER_ALLOWED_AUTH_UNKNOWN;
}
/* 'none' is a special value which, if given, must be given alone */
if (allowed_auth & MM_BEARER_ALLOWED_AUTH_NONE &&
allowed_auth != MM_BEARER_ALLOWED_AUTH_NONE) {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Allowed auth 'none' cannot be given along with other values");
allowed_auth = MM_BEARER_ALLOWED_AUTH_UNKNOWN;
}
g_type_class_unref (flags_class);
g_strfreev (strings);
return allowed_auth;
}
MMSmsStorage
mm_common_get_sms_storage_from_string (const gchar *str,
GError **error)

View File

@@ -43,6 +43,8 @@ MMModemCdmaRmProtocol mm_common_get_rm_protocol_from_string (const gchar *str,
GError **error);
MMBearerIpFamily mm_common_get_ip_type_from_string (const gchar *str,
GError **error);
MMBearerAllowedAuth mm_common_get_allowed_auth_from_string (const gchar *str,
GError **error);
MMSmsStorage mm_common_get_sms_storage_from_string (const gchar *str,
GError **error);

View File

@@ -267,6 +267,40 @@ mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *self)
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_allowed_auth:
* @self: a #MMSimpleConnectProperties.
* @allowed_auth: a bitmask of #MMBearerAllowedAuth values. %MM_BEARER_ALLOWED_AUTH_UNKNOWN may be given to request the modem-default method.
*
* Sets the authentication method to use.
*/
void
mm_simple_connect_properties_set_allowed_auth (MMSimpleConnectProperties *self,
MMBearerAllowedAuth allowed_auth)
{
g_return_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self));
mm_bearer_properties_set_allowed_auth (self->priv->bearer_properties, allowed_auth);
}
/**
* mm_simple_connect_properties_get_allowed_auth:
* @self: a #MMSimpleConnectProperties.
*
* Gets the authentication methods allowed in the connection.
*
* Returns: a bitmask of #MMBearerAllowedAuth values, or %MM_BEARER_ALLOWED_AUTH_UNKNOWN to request the modem-default method.
*/
MMBearerAllowedAuth
mm_simple_connect_properties_get_allowed_auth (MMSimpleConnectProperties *self)
{
g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), MM_BEARER_ALLOWED_AUTH_UNKNOWN);
return mm_bearer_properties_get_allowed_auth (self->priv->bearer_properties);
}
/*****************************************************************************/
/**
* mm_simple_connect_properties_set_user:
* @self: a #MMSimpleConnectProperties.

View File

@@ -71,6 +71,8 @@ void mm_simple_connect_properties_set_allowed_modes (MMSimpleConnectProperties *
MMModemMode preferred);
void mm_simple_connect_properties_set_apn (MMSimpleConnectProperties *self,
const gchar *apn);
void mm_simple_connect_properties_set_allowed_auth (MMSimpleConnectProperties *self,
MMBearerAllowedAuth allowed_auth);
void mm_simple_connect_properties_set_user (MMSimpleConnectProperties *self,
const gchar *user);
void mm_simple_connect_properties_set_password (MMSimpleConnectProperties *self,
@@ -91,6 +93,7 @@ gboolean mm_simple_connect_properties_get_allowed_modes (MMSimpleConnec
MMModemMode *allowed,
MMModemMode *preferred);
const gchar *mm_simple_connect_properties_get_apn (MMSimpleConnectProperties *self);
MMBearerAllowedAuth mm_simple_connect_properties_get_allowed_auth (MMSimpleConnectProperties *self);
const gchar *mm_simple_connect_properties_get_user (MMSimpleConnectProperties *self);
const gchar *mm_simple_connect_properties_get_password (MMSimpleConnectProperties *self);
MMBearerIpFamily mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *self);