summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2013-05-22 17:43:21 +0200
committerAleksander Morgado <aleksander@lanedo.com>2013-06-05 19:15:13 +0200
commit804642adc234094717158ff09857de1432565dda (patch)
treefdcf1cd2fc158e2edc6325b7b67095fa4895932d
parenta42234dd1c680e7604008fc2e66be849c7bf70de (diff)
downloadModemManager-804642adc234094717158ff09857de1432565dda.tar.gz
api: let MMBearerIpFamily be flags instead of a enumeration
We want to expose in the Modem interface the list of supported IP families, and the easiest way to do so is to have the IP family as flags, and provide in the interface a single enum. Also, a value of 0 for a MMBearerIpFamily specifies that no flags are set, so just rename it to 'NONE'. And add a new 'ANY' value which sets all flags to 1.
-rw-r--r--cli/mmcli-bearer.c8
-rw-r--r--include/ModemManager-enums.h12
-rw-r--r--libmm-glib/mm-bearer-properties.c6
-rw-r--r--libmm-glib/mm-common-helpers.c12
-rw-r--r--libmm-glib/mm-simple-connect-properties.c2
-rw-r--r--src/mm-bearer-mbim.c40
-rw-r--r--src/mm-bearer-qmi.c41
-rw-r--r--src/mm-broadband-bearer.c31
-rw-r--r--src/mm-iface-modem-simple.c6
-rw-r--r--src/mm-modem-helpers.c4
10 files changed, 104 insertions, 58 deletions
diff --git a/cli/mmcli-bearer.c b/cli/mmcli-bearer.c
index 0da8f5b23..600be1164 100644
--- a/cli/mmcli-bearer.c
+++ b/cli/mmcli-bearer.c
@@ -160,6 +160,10 @@ print_bearer_info (MMBearer *bearer)
mm_bearer_get_ip_timeout (bearer));
if (properties) {
+ gchar *ip_family_str;
+
+ ip_family_str = (mm_bearer_ip_family_build_string_from_mask (
+ mm_bearer_properties_get_ip_type (properties)));
g_print (" -------------------------\n"
" Properties | apn: '%s'\n"
" | roaming: '%s'\n"
@@ -170,13 +174,13 @@ print_bearer_info (MMBearer *bearer)
" | Rm protocol: '%s'\n",
VALIDATE_NONE (mm_bearer_properties_get_apn (properties)),
mm_bearer_properties_get_allow_roaming (properties) ? "allowed" : "forbidden",
- VALIDATE_UNKNOWN (mm_bearer_ip_family_get_string (
- mm_bearer_properties_get_ip_type (properties))),
+ VALIDATE_UNKNOWN (ip_family_str),
VALIDATE_NONE (mm_bearer_properties_get_user (properties)),
VALIDATE_NONE (mm_bearer_properties_get_password (properties)),
VALIDATE_NONE (mm_bearer_properties_get_number (properties)),
VALIDATE_UNKNOWN (mm_modem_cdma_rm_protocol_get_string (
mm_bearer_properties_get_rm_protocol (properties))));
+ g_free (ip_family_str);
}
/* IPv4 */
diff --git a/include/ModemManager-enums.h b/include/ModemManager-enums.h
index f297d1be7..a3c37e4b3 100644
--- a/include/ModemManager-enums.h
+++ b/include/ModemManager-enums.h
@@ -589,18 +589,20 @@ typedef enum { /*< underscore_name=mm_bearer_ip_method >*/
/**
* MMBearerIpFamily:
- * @MM_BEARER_IP_FAMILY_UNKNOWN: Unknown.
+ * @MM_BEARER_IP_FAMILY_NONE: None or unknown.
* @MM_BEARER_IP_FAMILY_IPV4: IPv4.
* @MM_BEARER_IP_FAMILY_IPV6: IPv6.
* @MM_BEARER_IP_FAMILY_IPV4V6: IPv4 and IPv6.
+ * @MM_BEARER_IP_FAMILY_ANY: Mask specifying all IP families.
*
* Type of IP family to be used in a given Bearer.
*/
typedef enum { /*< underscore_name=mm_bearer_ip_family >*/
- MM_BEARER_IP_FAMILY_UNKNOWN = 0,
- MM_BEARER_IP_FAMILY_IPV4 = 4,
- MM_BEARER_IP_FAMILY_IPV6 = 6,
- MM_BEARER_IP_FAMILY_IPV4V6 = 10
+ MM_BEARER_IP_FAMILY_NONE = 0,
+ MM_BEARER_IP_FAMILY_IPV4 = 1 << 0,
+ MM_BEARER_IP_FAMILY_IPV6 = 1 << 1,
+ MM_BEARER_IP_FAMILY_IPV4V6 = 1 << 2,
+ MM_BEARER_IP_FAMILY_ANY = 0xFFFFFFFF
} MMBearerIpFamily;
/**
diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c
index 2f59feed6..c4f4ba2f1 100644
--- a/libmm-glib/mm-bearer-properties.c
+++ b/libmm-glib/mm-bearer-properties.c
@@ -230,7 +230,7 @@ mm_bearer_properties_set_ip_type (MMBearerProperties *self,
MMBearerIpFamily
mm_bearer_properties_get_ip_type (MMBearerProperties *self)
{
- g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), MM_BEARER_IP_FAMILY_UNKNOWN);
+ g_return_val_if_fail (MM_IS_BEARER_PROPERTIES (self), MM_BEARER_IP_FAMILY_NONE);
return self->priv->ip_type;
}
@@ -379,7 +379,7 @@ mm_bearer_properties_get_dictionary (MMBearerProperties *self)
PROPERTY_PASSWORD,
g_variant_new_string (self->priv->password));
- if (self->priv->ip_type != MM_BEARER_IP_FAMILY_UNKNOWN)
+ if (self->priv->ip_type != MM_BEARER_IP_FAMILY_NONE)
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_IP_TYPE,
@@ -674,7 +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;
- self->priv->ip_type = MM_BEARER_IP_FAMILY_UNKNOWN;
+ self->priv->ip_type = MM_BEARER_IP_FAMILY_NONE;
}
static void
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c
index 4694be8d5..aabc070c0 100644
--- a/libmm-glib/mm-common-helpers.c
+++ b/libmm-glib/mm-common-helpers.c
@@ -399,14 +399,14 @@ MMBearerIpFamily
mm_common_get_ip_type_from_string (const gchar *str,
GError **error)
{
- GEnumClass *enum_class;
+ GFlagsClass *flags_class;
guint i;
- enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_BEARER_IP_FAMILY));
+ flags_class = G_FLAGS_CLASS (g_type_class_ref (MM_TYPE_BEARER_IP_FAMILY));
- for (i = 0; enum_class->values[i].value_nick; i++) {
- if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick))
- return enum_class->values[i].value;
+ for (i = 0; flags_class->values[i].value_nick; i++) {
+ if (!g_ascii_strcasecmp (str, flags_class->values[i].value_nick))
+ return flags_class->values[i].value;
}
g_set_error (error,
@@ -414,7 +414,7 @@ mm_common_get_ip_type_from_string (const gchar *str,
MM_CORE_ERROR_INVALID_ARGS,
"Couldn't match '%s' with a valid MMBearerIpFamily value",
str);
- return MM_BEARER_IP_FAMILY_UNKNOWN;
+ return MM_BEARER_IP_FAMILY_NONE;
}
MMBearerAllowedAuth
diff --git a/libmm-glib/mm-simple-connect-properties.c b/libmm-glib/mm-simple-connect-properties.c
index 7052234a8..5222e01cd 100644
--- a/libmm-glib/mm-simple-connect-properties.c
+++ b/libmm-glib/mm-simple-connect-properties.c
@@ -399,7 +399,7 @@ mm_simple_connect_properties_set_ip_type (MMSimpleConnectProperties *self,
MMBearerIpFamily
mm_simple_connect_properties_get_ip_type (MMSimpleConnectProperties *self)
{
- g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), MM_BEARER_IP_FAMILY_UNKNOWN);
+ g_return_val_if_fail (MM_IS_SIMPLE_CONNECT_PROPERTIES (self), MM_BEARER_IP_FAMILY_NONE);
return mm_bearer_properties_get_ip_type (self->priv->bearer_properties);
}
diff --git a/src/mm-bearer-mbim.c b/src/mm-bearer-mbim.c
index a26ef4d87..8b64a4c08 100644
--- a/src/mm-bearer-mbim.c
+++ b/src/mm-bearer-mbim.c
@@ -661,27 +661,41 @@ connect_context_step (ConnectContext *ctx)
}
ip_family = mm_bearer_properties_get_ip_type (ctx->properties);
- if (ip_family == MM_BEARER_IP_FAMILY_UNKNOWN) {
+ if (ip_family == MM_BEARER_IP_FAMILY_NONE ||
+ ip_family == MM_BEARER_IP_FAMILY_ANY) {
+ gchar * str;
+
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));
+ str = mm_bearer_ip_family_build_string_from_mask (ip_family);
+ mm_dbg ("No specific IP family requested, defaulting to %s", str);
+ g_free (str);
}
- switch (ip_family) {
- case MM_BEARER_IP_FAMILY_IPV4:
+ if (ip_family == MM_BEARER_IP_FAMILY_IPV4)
ip_type = MBIM_CONTEXT_IP_TYPE_IPV4;
- break;
- case MM_BEARER_IP_FAMILY_IPV6:
+ else if (ip_family == MM_BEARER_IP_FAMILY_IPV6)
ip_type = MBIM_CONTEXT_IP_TYPE_IPV6;
- break;
- case MM_BEARER_IP_FAMILY_IPV4V6:
+ else if (ip_family == MM_BEARER_IP_FAMILY_IPV4V6)
ip_type = MBIM_CONTEXT_IP_TYPE_IPV4V6;
- break;
- case MM_BEARER_IP_FAMILY_UNKNOWN:
- default:
+ else if (ip_family == (MM_BEARER_IP_FAMILY_IPV4 | MM_BEARER_IP_FAMILY_IPV6))
+ ip_type = MBIM_CONTEXT_IP_TYPE_IPV4_AND_IPV6;
+ else if (ip_family == MM_BEARER_IP_FAMILY_NONE ||
+ ip_family == MM_BEARER_IP_FAMILY_ANY)
/* A valid default IP family should have been specified */
g_assert_not_reached ();
- break;
+ else {
+ gchar * str;
+
+ str = mm_bearer_ip_family_build_string_from_mask (ip_family);
+ g_simple_async_result_set_error (
+ ctx->result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_UNSUPPORTED,
+ "Unsupported IP type configuration: '%s'",
+ str);
+ g_free (str);
+ connect_context_complete_and_free (ctx);
+ return;
}
mm_dbg ("Launching connection with APN '%s'...", apn);
diff --git a/src/mm-bearer-qmi.c b/src/mm-bearer-qmi.c
index bc97ec976..a72fa48e1 100644
--- a/src/mm-bearer-qmi.c
+++ b/src/mm-bearer-qmi.c
@@ -884,31 +884,40 @@ _connect (MMBearer *self,
ctx->password = g_strdup (mm_bearer_properties_get_password (properties));
ip_family = mm_bearer_properties_get_ip_type (properties);
- if (ip_family == MM_BEARER_IP_FAMILY_UNKNOWN) {
+ if (ip_family == MM_BEARER_IP_FAMILY_NONE ||
+ ip_family == MM_BEARER_IP_FAMILY_ANY) {
+ gchar *ip_family_str;
+
ip_family = mm_bearer_get_default_ip_family (self);
+ ip_family_str = mm_bearer_ip_family_build_string_from_mask (ip_family);
mm_dbg ("No specific IP family requested, defaulting to %s",
- mm_bearer_ip_family_get_string (ip_family));
+ ip_family_str);
ctx->no_ip_family_preference = TRUE;
+ g_free (ip_family_str);
}
- switch (ip_family) {
- case MM_BEARER_IP_FAMILY_IPV4:
+ if (ip_family & MM_BEARER_IP_FAMILY_IPV4)
ctx->ipv4 = TRUE;
- ctx->ipv6 = FALSE;
- break;
- case MM_BEARER_IP_FAMILY_IPV6:
- ctx->ipv4 = FALSE;
+ if (ip_family & MM_BEARER_IP_FAMILY_IPV6)
ctx->ipv6 = TRUE;
- break;
- case MM_BEARER_IP_FAMILY_IPV4V6:
+ if (ip_family & MM_BEARER_IP_FAMILY_IPV4V6) {
ctx->ipv4 = TRUE;
ctx->ipv6 = TRUE;
- break;
- case MM_BEARER_IP_FAMILY_UNKNOWN:
- default:
- /* A valid default IP family should have been specified */
- g_assert_not_reached ();
- break;
+ }
+
+ if (!ctx->ipv4 && !ctx->ipv6) {
+ gchar *str;
+
+ str = mm_bearer_ip_family_build_string_from_mask (ip_family);
+ g_simple_async_result_set_error (
+ ctx->result,
+ MM_CORE_ERROR,
+ MM_CORE_ERROR_UNSUPPORTED,
+ "Unsupported IP type requested: '%s'",
+ str);
+ g_free (str);
+ connect_context_complete_and_free (ctx);
+ return;
}
auth = mm_bearer_properties_get_allowed_auth (properties);
diff --git a/src/mm-broadband-bearer.c b/src/mm-broadband-bearer.c
index 09dd18712..9a891e74a 100644
--- a/src/mm-broadband-bearer.c
+++ b/src/mm-broadband-bearer.c
@@ -168,10 +168,14 @@ detailed_connect_context_new (MMBroadbandBearer *self,
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) {
+ if (ctx->ip_family == MM_BEARER_IP_FAMILY_NONE ||
+ ctx->ip_family == MM_BEARER_IP_FAMILY_ANY) {
+ gchar *default_family;
+
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));
+ default_family = mm_bearer_ip_family_build_string_from_mask (ctx->ip_family);
+ mm_dbg ("No specific IP family requested, defaulting to %s", default_family);
+ g_free (default_family);
}
/* NOTE:
@@ -789,10 +793,15 @@ find_cid_ready (MMBaseModem *modem,
pdp_type = mm_3gpp_get_pdp_type_from_ip_family (ctx->ip_family);
if (!pdp_type) {
+ gchar * str;
+
+ str = mm_bearer_ip_family_build_string_from_mask (ctx->ip_family);
g_simple_async_result_set_error (ctx->result,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
- "Invalid PDP type requested");
+ "Unsupported IP type requested: '%s'",
+ str);
+ g_free (str);
detailed_connect_context_complete_and_free (ctx);
return;
}
@@ -952,11 +961,14 @@ parse_pdp_list (MMBaseModem *modem,
mm_dbg ("Found '%u' PDP contexts", g_list_length (pdp_list));
for (l = pdp_list; l; l = g_list_next (l)) {
MM3gppPdpContext *pdp = l->data;
+ gchar *ip_family_str;
+ ip_family_str = mm_bearer_ip_family_build_string_from_mask (pdp->pdp_type);
mm_dbg (" PDP context [cid=%u] [type='%s'] [apn='%s']",
pdp->cid,
- mm_bearer_ip_family_get_string (pdp->pdp_type),
+ ip_family_str,
pdp->apn ? pdp->apn : "");
+ g_free (ip_family_str);
}
/* Look for the exact PDP context we want */
@@ -973,13 +985,16 @@ parse_pdp_list (MMBaseModem *modem,
const gchar *apn;
apn = mm_bearer_properties_get_apn (mm_bearer_peek_config (MM_BEARER (ctx->self)));
- if (apn &&
- g_str_equal (pdp->apn, apn)) {
+ if (apn && g_str_equal (pdp->apn, apn)) {
+ gchar *ip_family_str;
+
/* Found a PDP context with the same CID and PDP type, we'll use it. */
+ ip_family_str = mm_bearer_ip_family_build_string_from_mask (pdp->pdp_type);
mm_dbg ("Found PDP context with CID %u and PDP type %s for APN '%s'",
- pdp->cid, mm_bearer_ip_family_get_string (pdp->pdp_type), pdp->apn);
+ pdp->cid, ip_family_str, pdp->apn);
cid = pdp->cid;
ctx->use_existing_cid = TRUE;
+ g_free (ip_family_str);
/* In this case, stop searching */
break;
}
diff --git a/src/mm-iface-modem-simple.c b/src/mm-iface-modem-simple.c
index d29b9c050..773d091d0 100644
--- a/src/mm-iface-modem-simple.c
+++ b/src/mm-iface-modem-simple.c
@@ -818,8 +818,10 @@ connect_auth_ready (MMBaseModem *self,
mm_dbg (" APN: %s", VALIDATE_UNSPECIFIED (mm_simple_connect_properties_get_apn (ctx->properties)));
ip_family = mm_simple_connect_properties_get_ip_type (ctx->properties);
- if (ip_family != MM_BEARER_IP_FAMILY_UNKNOWN) {
- mm_dbg (" IP family: %s", mm_bearer_ip_family_get_string (ip_family));
+ if (ip_family != MM_BEARER_IP_FAMILY_NONE) {
+ str = mm_bearer_ip_family_build_string_from_mask (ip_family);
+ mm_dbg (" IP family: %s", str);
+ g_free (str);
} else
mm_dbg (" IP family: %s", VALIDATE_UNSPECIFIED (NULL));
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 4bffd11bf..c4640d429 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -691,7 +691,7 @@ mm_3gpp_parse_cgdcont_read_response (const gchar *reply,
str = mm_get_string_unquoted_from_match_info (match_info, 2);
ip_family = mm_3gpp_get_ip_family_from_pdp_type (str);
- if (ip_family == MM_BEARER_IP_FAMILY_UNKNOWN)
+ if (ip_family == MM_BEARER_IP_FAMILY_NONE)
mm_dbg ("Ignoring PDP context type: '%s'", str);
else {
MM3gppPdpContext *pdp;
@@ -1711,7 +1711,7 @@ mm_3gpp_get_ip_family_from_pdp_type (const gchar *pdp_type)
return MM_BEARER_IP_FAMILY_IPV6;
if (g_str_equal (pdp_type, "IPV4V6"))
return MM_BEARER_IP_FAMILY_IPV4V6;
- return MM_BEARER_IP_FAMILY_UNKNOWN;
+ return MM_BEARER_IP_FAMILY_NONE;
}
/*************************************************************************/