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.
This commit is contained in:
Aleksander Morgado
2013-06-05 19:15:13 +02:00
parent a42234dd1c
commit 804642adc2
10 changed files with 104 additions and 58 deletions
+6 -2
View File
@@ -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 */
+7 -5
View File
@@ -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;
/**
+3 -3
View File
@@ -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
+6 -6
View File
@@ -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
+1 -1
View File
@@ -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);
}
+27 -13
View File
@@ -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);
+25 -16
View File
@@ -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);
+23 -8
View File
@@ -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;
}
+4 -2
View File
@@ -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));
+2 -2
View File
@@ -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;
}
/*************************************************************************/