api,dbus: 'ip-type' property now given as a MMBearerIpFamily (u)
Instead of using a predefined set of string values for 'ip-type' in Modem.CreateBearer() and Simple.Connect(), we'll use an enumeration. The implementation will then need to convert the requested IP family type to e.g. the correct PDP type in 3GPP modems. This change also consolidates the use of enums in dictionary properties when possible to do so, as with the Rm Protocol.
This commit is contained in:
@@ -752,6 +752,7 @@ find_cid_ready (MMBaseModem *modem,
|
||||
GVariant *result;
|
||||
gchar *command;
|
||||
GError *error = NULL;
|
||||
const gchar *pdp_type;
|
||||
|
||||
result = mm_base_modem_at_sequence_full_finish (modem, res, NULL, &error);
|
||||
if (!result) {
|
||||
@@ -768,10 +769,20 @@ 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))));
|
||||
if (!pdp_type) {
|
||||
g_simple_async_result_set_error (ctx->result,
|
||||
MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_INVALID_ARGS,
|
||||
"Invalid PDP type requested");
|
||||
detailed_connect_context_complete_and_free (ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->cid = g_variant_get_uint32 (result);
|
||||
command = g_strdup_printf ("+CGDCONT=%u,\"%s\",\"%s\"",
|
||||
ctx->cid,
|
||||
mm_bearer_properties_get_ip_type (mm_bearer_peek_config (MM_BEARER (ctx->self))),
|
||||
pdp_type,
|
||||
mm_bearer_properties_get_apn (mm_bearer_peek_config (MM_BEARER (ctx->self))));
|
||||
mm_base_modem_at_command_full (ctx->modem,
|
||||
ctx->primary,
|
||||
@@ -830,7 +841,8 @@ parse_cid_range (MMBaseModem *modem,
|
||||
|
||||
pdp_type = g_match_info_fetch (match_info, 3);
|
||||
|
||||
if (g_str_equal (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) ==
|
||||
mm_bearer_properties_get_ip_type (mm_bearer_peek_config (MM_BEARER (ctx->self)))) {
|
||||
gchar *max_cid_range_str;
|
||||
guint max_cid_range;
|
||||
|
||||
@@ -914,9 +926,9 @@ parse_pdp_list (MMBaseModem *modem,
|
||||
|
||||
mm_dbg (" PDP context [cid=%u] [type='%s'] [apn='%s']",
|
||||
pdp->cid,
|
||||
pdp->pdp_type ? pdp->pdp_type : "",
|
||||
mm_bearer_ip_family_get_string (pdp->pdp_type),
|
||||
pdp->apn ? pdp->apn : "");
|
||||
if (g_str_equal (pdp->pdp_type, mm_bearer_properties_get_ip_type (mm_bearer_peek_config (MM_BEARER (ctx->self))))) {
|
||||
if (pdp->pdp_type == mm_bearer_properties_get_ip_type (mm_bearer_peek_config (MM_BEARER (ctx->self)))) {
|
||||
/* 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",
|
||||
@@ -930,7 +942,7 @@ parse_pdp_list (MMBaseModem *modem,
|
||||
g_str_equal (pdp->apn, apn)) {
|
||||
/* Found a PDP context with the same CID and PDP type, we'll use it. */
|
||||
mm_dbg ("Found PDP context with CID %u and PDP type %s for APN '%s'",
|
||||
pdp->cid, pdp->pdp_type, pdp->apn);
|
||||
pdp->cid, mm_bearer_ip_family_get_string (pdp->pdp_type), pdp->apn);
|
||||
cid = pdp->cid;
|
||||
/* In this case, stop searching */
|
||||
break;
|
||||
|
@@ -500,9 +500,8 @@ mm_3gpp_parse_cops_test_response (const gchar *reply,
|
||||
static void
|
||||
mm_3gpp_pdp_context_free (MM3gppPdpContext *pdp)
|
||||
{
|
||||
g_free (pdp->pdp_type);
|
||||
g_free (pdp->apn);
|
||||
g_free (pdp);
|
||||
g_slice_free (MM3gppPdpContext, pdp);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -540,21 +539,31 @@ mm_3gpp_parse_cgdcont_read_response (const gchar *reply,
|
||||
|
||||
while (!inner_error &&
|
||||
g_match_info_matches (match_info)) {
|
||||
MM3gppPdpContext *pdp;
|
||||
gchar *str;
|
||||
MMBearerIpFamily ip_family;
|
||||
|
||||
pdp = g_new0 (MM3gppPdpContext, 1);
|
||||
if (!mm_get_uint_from_match_info (match_info, 1, &pdp->cid)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"Couldn't parse CID from reply: '%s'",
|
||||
reply);
|
||||
break;
|
||||
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)
|
||||
mm_dbg ("Ignoring PDP context type: '%s'", str);
|
||||
else {
|
||||
MM3gppPdpContext *pdp;
|
||||
|
||||
pdp = g_slice_new0 (MM3gppPdpContext);
|
||||
if (!mm_get_uint_from_match_info (match_info, 1, &pdp->cid)) {
|
||||
inner_error = g_error_new (MM_CORE_ERROR,
|
||||
MM_CORE_ERROR_FAILED,
|
||||
"Couldn't parse CID from reply: '%s'",
|
||||
reply);
|
||||
break;
|
||||
}
|
||||
pdp->pdp_type = ip_family;
|
||||
pdp->apn = mm_get_string_unquoted_from_match_info (match_info, 3);
|
||||
|
||||
list = g_list_prepend (list, pdp);
|
||||
}
|
||||
pdp->pdp_type = mm_get_string_unquoted_from_match_info (match_info, 2);
|
||||
pdp->apn = mm_get_string_unquoted_from_match_info (match_info, 3);
|
||||
|
||||
list = g_list_prepend (list, pdp);
|
||||
|
||||
g_free (str);
|
||||
g_match_info_next (match_info, &inner_error);
|
||||
}
|
||||
|
||||
@@ -1427,6 +1436,35 @@ mm_3gpp_parse_operator (const gchar *reply,
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
const gchar *
|
||||
mm_3gpp_get_pdp_type_from_ip_family (MMBearerIpFamily family)
|
||||
{
|
||||
switch (family) {
|
||||
case MM_BEARER_IP_FAMILY_IPV4:
|
||||
return "IP";
|
||||
case MM_BEARER_IP_FAMILY_IPV6:
|
||||
return "IPV6";
|
||||
case MM_BEARER_IP_FAMILY_IPV4V6:
|
||||
return "IPV4V6";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
MMBearerIpFamily
|
||||
mm_3gpp_get_ip_family_from_pdp_type (const gchar *pdp_type)
|
||||
{
|
||||
if (g_str_equal (pdp_type, "IP"))
|
||||
return MM_BEARER_IP_FAMILY_IPV4;
|
||||
if (g_str_equal (pdp_type, "IPV6"))
|
||||
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;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
gboolean
|
||||
mm_cdma_parse_spservice_read_response (const gchar *reply,
|
||||
MMModemCdmaRegistrationState *out_cdma_1x_state,
|
||||
|
@@ -85,7 +85,7 @@ GList *mm_3gpp_parse_cops_test_response (const gchar *reply,
|
||||
/* AT+CGDCONT? (PDP context query) response parser */
|
||||
typedef struct {
|
||||
guint cid;
|
||||
gchar *pdp_type;
|
||||
MMBearerIpFamily pdp_type;
|
||||
gchar *apn;
|
||||
} MM3gppPdpContext;
|
||||
void mm_3gpp_pdp_context_list_free (GList *pdp_list);
|
||||
@@ -152,6 +152,9 @@ MMModemAccessTechnology mm_string_to_access_tech (const gchar *string);
|
||||
gchar *mm_3gpp_parse_operator (const gchar *reply,
|
||||
MMModemCharset cur_charset);
|
||||
|
||||
const gchar *mm_3gpp_get_pdp_type_from_ip_family (MMBearerIpFamily family);
|
||||
MMBearerIpFamily mm_3gpp_get_ip_family_from_pdp_type (const gchar *pdp_type);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* CDMA specific helpers and utilities */
|
||||
/*****************************************************************************/
|
||||
|
@@ -1244,7 +1244,7 @@ test_cgdcont_results (const gchar *desc,
|
||||
if (pdp->cid == expected->cid) {
|
||||
found = TRUE;
|
||||
|
||||
g_assert_cmpstr (pdp->pdp_type, ==, expected->pdp_type);
|
||||
g_assert_cmpuint (pdp->pdp_type, ==, expected->pdp_type);
|
||||
g_assert_cmpstr (pdp->apn, ==, expected->apn);
|
||||
}
|
||||
}
|
||||
@@ -1260,7 +1260,7 @@ test_cgdcont_response_nokia (void *f, gpointer d)
|
||||
{
|
||||
const gchar *reply = "+CGDCONT: 1,\"IP\",,,0,0";
|
||||
static MM3gppPdpContext expected[] = {
|
||||
{ 1, "IP", NULL }
|
||||
{ 1, MM_BEARER_IP_FAMILY_IPV4, NULL }
|
||||
};
|
||||
|
||||
test_cgdcont_results ("Nokia", reply, &expected[0], G_N_ELEMENTS (expected));
|
||||
|
Reference in New Issue
Block a user