diff options
author | Ben Chan <benchan@chromium.org> | 2013-04-22 14:34:44 -0700 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-04-23 15:25:48 +0200 |
commit | 4ac3a6d4f212b3fc04e004c85b89fd567e865ffa (patch) | |
tree | 50f2f6eeb7f390d0d7abf8dea430fbb8b28a4f92 | |
parent | 60845f10c9dae6c7e53022050aa8d09e1e1354ea (diff) | |
download | ModemManager-4ac3a6d4f212b3fc04e004c85b89fd567e865ffa.tar.gz |
bearer: allow specifying default IP family for bearers
This patch adds a 'bearer-default-ip-family' property to MMBearer, which
specifies the default IP family to use for a bearer when no explicit
value is given via the simple connect properties. The default IP family
is set to IPv4 in MMBearer but can be overridden by a MMBearer subclass,
which allows a modem plugin to specify an appropriate default value.
-rw-r--r-- | libmm-glib/mm-bearer-properties.c | 8 | ||||
-rw-r--r-- | src/mm-bearer-mbim.c | 14 | ||||
-rw-r--r-- | src/mm-bearer-qmi.c | 18 | ||||
-rw-r--r-- | src/mm-bearer.c | 25 | ||||
-rw-r--r-- | src/mm-bearer.h | 2 | ||||
-rw-r--r-- | src/mm-broadband-bearer.c | 16 |
6 files changed, 64 insertions, 19 deletions
diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c index 6526ed061..2f59feed6 100644 --- a/libmm-glib/mm-bearer-properties.c +++ b/libmm-glib/mm-bearer-properties.c @@ -674,13 +674,7 @@ mm_bearer_properties_init (MMBearerProperties *self) 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 - * even better approach would likely be to query which PDP types the - * modem supports (using AT+CGDCONT=?), and set the default accordingly - */ - self->priv->ip_type = MM_BEARER_IP_FAMILY_IPV4; + self->priv->ip_type = MM_BEARER_IP_FAMILY_UNKNOWN; } static void diff --git a/src/mm-bearer-mbim.c b/src/mm-bearer-mbim.c index d96a1b127..bddc9da8e 100644 --- a/src/mm-bearer-mbim.c +++ b/src/mm-bearer-mbim.c @@ -618,6 +618,7 @@ connect_context_step (ConnectContext *ctx) const gchar *password; MbimAuthProtocol auth; MbimContextIpType ip_type; + MMBearerIpFamily ip_family; GError *error = NULL; /* Setup parameters to use */ @@ -658,7 +659,14 @@ connect_context_step (ConnectContext *ctx) } } - switch (mm_bearer_properties_get_ip_type (ctx->properties)) { + ip_family = mm_bearer_properties_get_ip_type (ctx->properties); + if (ip_family == MM_BEARER_IP_FAMILY_UNKNOWN) { + ip_family = mm_bearer_get_default_ip_family (MM_BEARER (ctx->self)); + mm_dbg ("No specific IP family requested, defaulting to %s", + mm_bearer_ip_family_get_string (ip_family)); + } + + switch (ip_family) { case MM_BEARER_IP_FAMILY_IPV4: ip_type = MBIM_CONTEXT_IP_TYPE_IPV4; break; @@ -670,8 +678,8 @@ connect_context_step (ConnectContext *ctx) break; case MM_BEARER_IP_FAMILY_UNKNOWN: default: - mm_dbg ("No specific IP family requested, defaulting to IPv4"); - ip_type = MBIM_CONTEXT_IP_TYPE_IPV4; + /* A valid default IP family should have been specified */ + g_assert_not_reached (); break; } diff --git a/src/mm-bearer-qmi.c b/src/mm-bearer-qmi.c index 8f9568d7e..9e8d2bc4a 100644 --- a/src/mm-bearer-qmi.c +++ b/src/mm-bearer-qmi.c @@ -846,11 +846,21 @@ _connect (MMBearer *self, if (properties) { MMBearerAllowedAuth auth; + MMBearerIpFamily ip_family; ctx->apn = g_strdup (mm_bearer_properties_get_apn (properties)); ctx->user = g_strdup (mm_bearer_properties_get_user (properties)); ctx->password = g_strdup (mm_bearer_properties_get_password (properties)); - switch (mm_bearer_properties_get_ip_type (properties)) { + + ip_family = mm_bearer_properties_get_ip_type (properties); + if (ip_family == MM_BEARER_IP_FAMILY_UNKNOWN) { + ip_family = mm_bearer_get_default_ip_family (self); + mm_dbg ("No specific IP family requested, defaulting to %s", + mm_bearer_ip_family_get_string (ip_family)); + ctx->no_ip_family_preference = TRUE; + } + + switch (ip_family) { case MM_BEARER_IP_FAMILY_IPV4: ctx->ipv4 = TRUE; ctx->ipv6 = FALSE; @@ -865,10 +875,8 @@ _connect (MMBearer *self, break; case MM_BEARER_IP_FAMILY_UNKNOWN: default: - mm_dbg ("No specific IP family requested, defaulting to IPv4"); - ctx->no_ip_family_preference = TRUE; - ctx->ipv4 = TRUE; - ctx->ipv6 = FALSE; + /* A valid default IP family should have been specified */ + g_assert_not_reached (); break; } diff --git a/src/mm-bearer.c b/src/mm-bearer.c index 9e96bdeda..d047e11f0 100644 --- a/src/mm-bearer.c +++ b/src/mm-bearer.c @@ -57,6 +57,7 @@ enum { PROP_MODEM, PROP_STATUS, PROP_CONFIG, + PROP_DEFAULT_IP_FAMILY, PROP_LAST }; @@ -73,6 +74,8 @@ struct _MMBearerPrivate { MMBearerStatus status; /* Configuration of the bearer */ MMBearerProperties *config; + /* Default IP family of this bearer */ + MMBearerIpFamily default_ip_family; /* Cancellable for connect() */ GCancellable *connect_cancellable; @@ -844,6 +847,12 @@ mm_bearer_get_config (MMBearer *self) NULL); } +MMBearerIpFamily +mm_bearer_get_default_ip_family (MMBearer *self) +{ + return self->priv->default_ip_family; +} + /*****************************************************************************/ static void @@ -969,6 +978,9 @@ set_property (GObject *object, g_variant_unref (dictionary); break; } + case PROP_DEFAULT_IP_FAMILY: + self->priv->default_ip_family = g_value_get_enum (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -999,6 +1011,9 @@ get_property (GObject *object, case PROP_CONFIG: g_value_set_object (value, self->priv->config); break; + case PROP_DEFAULT_IP_FAMILY: + g_value_set_enum (value, self->priv->default_ip_family); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1015,6 +1030,7 @@ mm_bearer_init (MMBearer *self) self->priv->status = MM_BEARER_STATUS_DISCONNECTED; self->priv->reason_3gpp = CONNECTION_FORBIDDEN_REASON_NONE; self->priv->reason_cdma = CONNECTION_FORBIDDEN_REASON_NONE; + self->priv->default_ip_family = MM_BEARER_IP_FAMILY_IPV4; /* Set defaults */ mm_gdbus_bearer_set_interface (MM_GDBUS_BEARER (self), NULL); @@ -1111,6 +1127,15 @@ mm_bearer_class_init (MMBearerClass *klass) MM_TYPE_BEARER_PROPERTIES, G_PARAM_READWRITE); g_object_class_install_property (object_class, PROP_CONFIG, properties[PROP_CONFIG]); + + properties[PROP_DEFAULT_IP_FAMILY] = + g_param_spec_enum (MM_BEARER_DEFAULT_IP_FAMILY, + "Bearer default IP family", + "IP family to use for this bearer when no IP family is specified", + MM_TYPE_BEARER_IP_FAMILY, + MM_BEARER_IP_FAMILY_IPV4, + G_PARAM_READWRITE); + g_object_class_install_property (object_class, PROP_DEFAULT_IP_FAMILY, properties[PROP_DEFAULT_IP_FAMILY]); } /*****************************************************************************/ diff --git a/src/mm-bearer.h b/src/mm-bearer.h index c6172979c..cc71bfd14 100644 --- a/src/mm-bearer.h +++ b/src/mm-bearer.h @@ -58,6 +58,7 @@ typedef struct _MMBearerPrivate MMBearerPrivate; #define MM_BEARER_MODEM "bearer-modem" #define MM_BEARER_STATUS "bearer-status" #define MM_BEARER_CONFIG "bearer-config" +#define MM_BEARER_DEFAULT_IP_FAMILY "bearer-deafult-ip-family" typedef enum { /*< underscore_name=mm_bearer_status >*/ MM_BEARER_STATUS_DISCONNECTED, @@ -103,6 +104,7 @@ const gchar *mm_bearer_get_path (MMBearer *bearer); MMBearerStatus mm_bearer_get_status (MMBearer *bearer); MMBearerProperties *mm_bearer_peek_config (MMBearer *self); MMBearerProperties *mm_bearer_get_config (MMBearer *self); +MMBearerIpFamily mm_bearer_get_default_ip_family (MMBearer *self); void mm_bearer_connect (MMBearer *self, diff --git a/src/mm-broadband-bearer.c b/src/mm-broadband-bearer.c index f380289f4..292420c91 100644 --- a/src/mm-broadband-bearer.c +++ b/src/mm-broadband-bearer.c @@ -85,6 +85,7 @@ typedef struct { /* 3GPP-specific */ guint cid; guint max_cid; + MMBearerIpFamily ip_family; } DetailedConnectContext; static MMBearerConnectResult * @@ -164,6 +165,14 @@ detailed_connect_context_new (MMBroadbandBearer *self, callback, user_data, detailed_connect_context_new); + + ctx->ip_family = mm_bearer_properties_get_ip_type (mm_bearer_peek_config (MM_BEARER (self))); + if (ctx->ip_family == MM_BEARER_IP_FAMILY_UNKNOWN) { + ctx->ip_family = mm_bearer_get_default_ip_family (MM_BEARER (self)); + mm_dbg ("No specific IP family requested, defaulting to %s", + mm_bearer_ip_family_get_string (ctx->ip_family)); + } + /* NOTE: * We don't currently support cancelling AT commands, so we'll just check * whether the operation is to be cancelled at each step. */ @@ -772,7 +781,7 @@ find_cid_ready (MMBaseModem *modem, return; /* Initialize PDP context with our APN */ - pdp_type = mm_3gpp_get_pdp_type_from_ip_family (mm_bearer_properties_get_ip_type (mm_bearer_peek_config (MM_BEARER (ctx->self)))); + pdp_type = mm_3gpp_get_pdp_type_from_ip_family (ctx->ip_family); if (!pdp_type) { g_simple_async_result_set_error (ctx->result, MM_CORE_ERROR, @@ -847,8 +856,7 @@ parse_cid_range (MMBaseModem *modem, pdp_type = g_match_info_fetch (match_info, 3); - if (mm_3gpp_get_ip_family_from_pdp_type (pdp_type) == - mm_bearer_properties_get_ip_type (mm_bearer_peek_config (MM_BEARER (ctx->self)))) { + if (mm_3gpp_get_ip_family_from_pdp_type (pdp_type) == ctx->ip_family) { gchar *max_cid_range_str; guint max_cid_range; @@ -942,7 +950,7 @@ parse_pdp_list (MMBaseModem *modem, for (l = pdp_list; l; l = g_list_next (l)) { MM3gppPdpContext *pdp = l->data; - if (pdp->pdp_type == mm_bearer_properties_get_ip_type (mm_bearer_peek_config (MM_BEARER (ctx->self)))) { + if (pdp->pdp_type == ctx->ip_family) { /* PDP with no APN set? we may use that one if not exact match found */ if (!pdp->apn || !pdp->apn[0]) { mm_dbg ("Found PDP context with CID %u and no APN", |