modem-helpers: add 3 digit MNC output to mm_3gpp_parse_operator_id()
MNC digit count information is lost on conversion to integers. Make it possible for the caller to get this information through a separate boolean.
This commit is contained in:
@@ -2738,7 +2738,7 @@ modem_3gpp_load_operator_name (MMIfaceModem3gpp *_self,
|
||||
}
|
||||
|
||||
/* Parse input MCC/MNC */
|
||||
if (!mm_3gpp_parse_operator_id (self->priv->current_operator_id, &mcc, &mnc, &error)) {
|
||||
if (!mm_3gpp_parse_operator_id (self->priv->current_operator_id, &mcc, &mnc, NULL, &error)) {
|
||||
g_task_return_error (task, g_steal_pointer (&error));
|
||||
g_object_unref (task);
|
||||
return;
|
||||
|
@@ -417,7 +417,7 @@ mm_iface_modem_3gpp_register_in_network (MMIfaceModem3gpp *self,
|
||||
}
|
||||
|
||||
/* Validate input MCC/MNC */
|
||||
if (ctx->operator_id && !mm_3gpp_parse_operator_id (ctx->operator_id, NULL, NULL, &error)) {
|
||||
if (ctx->operator_id && !mm_3gpp_parse_operator_id (ctx->operator_id, NULL, NULL, NULL, &error)) {
|
||||
g_assert (error != NULL);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
@@ -1432,7 +1432,7 @@ load_operator_code_ready (MMIfaceModem3gpp *self,
|
||||
str = MM_IFACE_MODEM_3GPP_GET_INTERFACE (self)->load_operator_code_finish (self, res, &error);
|
||||
if (error) {
|
||||
mm_obj_warn (self, "couldn't load operator code: %s", error->message);
|
||||
} else if (!mm_3gpp_parse_operator_id (str, &mcc, &mnc, &error)) {
|
||||
} else if (!mm_3gpp_parse_operator_id (str, &mcc, &mnc, NULL, &error)) {
|
||||
mm_obj_dbg (self, "unexpected operator code string '%s': %s", str, error->message);
|
||||
g_clear_pointer (&str, g_free);
|
||||
}
|
||||
|
@@ -4322,6 +4322,7 @@ gboolean
|
||||
mm_3gpp_parse_operator_id (const gchar *operator_id,
|
||||
guint16 *mcc,
|
||||
guint16 *mnc,
|
||||
gboolean *three_digit_mnc,
|
||||
GError **error)
|
||||
{
|
||||
guint len;
|
||||
@@ -4373,6 +4374,9 @@ mm_3gpp_parse_operator_id (const gchar *operator_id,
|
||||
*mnc = atoi (aux);
|
||||
}
|
||||
|
||||
if (three_digit_mnc)
|
||||
*three_digit_mnc = len == 6;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@@ -431,6 +431,7 @@ void mm_3gpp_normalize_operator (gchar **operator,
|
||||
gboolean mm_3gpp_parse_operator_id (const gchar *operator_id,
|
||||
guint16 *mcc,
|
||||
guint16 *mnc,
|
||||
gboolean *three_digit_mnc,
|
||||
GError **error);
|
||||
|
||||
const gchar *mm_3gpp_get_pdp_type_from_ip_family (MMBearerIpFamily family);
|
||||
|
@@ -474,7 +474,7 @@ mm_shared_qmi_3gpp_register_in_network (MMIfaceModem3gpp *self,
|
||||
g_task_set_task_data (task, ctx, (GDestroyNotify)register_in_network_context_free);
|
||||
|
||||
/* Parse input MCC/MNC */
|
||||
if (operator_id && !mm_3gpp_parse_operator_id (operator_id, &mcc, &mnc, &error)) {
|
||||
if (operator_id && !mm_3gpp_parse_operator_id (operator_id, &mcc, &mnc, NULL, &error)) {
|
||||
g_assert (error != NULL);
|
||||
g_task_return_error (task, error);
|
||||
g_object_unref (task);
|
||||
|
@@ -1011,7 +1011,7 @@ set_preferred_networks (MMBaseSim *self,
|
||||
|
||||
operator_code = mm_sim_preferred_network_get_operator_code (preferred_network_list->data);
|
||||
act = mm_sim_preferred_network_get_access_technology (preferred_network_list->data);
|
||||
if (mm_3gpp_parse_operator_id (operator_code, &preferred_nets_element.mcc, &preferred_nets_element.mnc, NULL)) {
|
||||
if (mm_3gpp_parse_operator_id (operator_code, &preferred_nets_element.mcc, &preferred_nets_element.mnc, NULL, NULL)) {
|
||||
pcs_digit_element.mcc = preferred_nets_element.mcc;
|
||||
pcs_digit_element.mnc = preferred_nets_element.mnc;
|
||||
pcs_digit_element.includes_pcs_digit = strlen(operator_code) > 5;
|
||||
|
@@ -3254,21 +3254,23 @@ static void
|
||||
common_parse_operator_id (const gchar *operator_id,
|
||||
gboolean expected_success,
|
||||
guint16 expected_mcc,
|
||||
guint16 expected_mnc)
|
||||
guint16 expected_mnc,
|
||||
gboolean expected_three_digit_mnc)
|
||||
{
|
||||
guint16 mcc;
|
||||
guint16 mnc;
|
||||
gboolean three_digit_mnc;
|
||||
gboolean result;
|
||||
GError *error = NULL;
|
||||
|
||||
if (expected_mcc) {
|
||||
g_debug ("Parsing Operator ID '%s' "
|
||||
"(%" G_GUINT16_FORMAT ", %" G_GUINT16_FORMAT ")...",
|
||||
operator_id, expected_mcc, expected_mnc);
|
||||
result = mm_3gpp_parse_operator_id (operator_id, &mcc, &mnc, &error);
|
||||
"(%" G_GUINT16_FORMAT ", %" G_GUINT16_FORMAT ", %s)...",
|
||||
operator_id, expected_mcc, expected_mnc, expected_three_digit_mnc ? "TRUE" : "FALSE");
|
||||
result = mm_3gpp_parse_operator_id (operator_id, &mcc, &mnc, &three_digit_mnc, &error);
|
||||
} else {
|
||||
g_debug ("Validating Operator ID '%s'...", operator_id);
|
||||
result = mm_3gpp_parse_operator_id (operator_id, NULL, NULL, &error);
|
||||
result = mm_3gpp_parse_operator_id (operator_id, NULL, NULL, NULL, &error);
|
||||
}
|
||||
|
||||
if (error)
|
||||
@@ -3283,6 +3285,7 @@ common_parse_operator_id (const gchar *operator_id,
|
||||
if (expected_mcc) {
|
||||
g_assert_cmpuint (expected_mcc, ==, mcc);
|
||||
g_assert_cmpuint (expected_mnc, ==, mnc);
|
||||
g_assert_cmpint (expected_three_digit_mnc, ==, three_digit_mnc);
|
||||
}
|
||||
} else {
|
||||
g_assert (error != NULL);
|
||||
@@ -3295,26 +3298,26 @@ static void
|
||||
test_parse_operator_id (void *f, gpointer d)
|
||||
{
|
||||
/* Valid MCC+MNC(2) */
|
||||
common_parse_operator_id ("41201", TRUE, 412, 1);
|
||||
common_parse_operator_id ("41201", TRUE, 0, 0);
|
||||
common_parse_operator_id ("41201", TRUE, 412, 1, FALSE);
|
||||
common_parse_operator_id ("41201", TRUE, 0, 0, FALSE);
|
||||
/* Valid MCC+MNC(3) */
|
||||
common_parse_operator_id ("342600", TRUE, 342, 600);
|
||||
common_parse_operator_id ("342600", TRUE, 0, 0);
|
||||
common_parse_operator_id ("342600", TRUE, 342, 600, TRUE);
|
||||
common_parse_operator_id ("342600", TRUE, 0, 0, FALSE);
|
||||
/* Valid MCC+MNC(2, == 0) */
|
||||
common_parse_operator_id ("72400", TRUE, 724, 0);
|
||||
common_parse_operator_id ("72400", TRUE, 0, 0);
|
||||
common_parse_operator_id ("72400", TRUE, 724, 0, FALSE);
|
||||
common_parse_operator_id ("72400", TRUE, 0, 0, FALSE);
|
||||
/* Valid MCC+MNC(3, == 0) */
|
||||
common_parse_operator_id ("724000", TRUE, 724, 0);
|
||||
common_parse_operator_id ("724000", TRUE, 0, 0);
|
||||
common_parse_operator_id ("724000", TRUE, 724, 0, TRUE);
|
||||
common_parse_operator_id ("724000", TRUE, 0, 0, FALSE);
|
||||
|
||||
/* Invalid MCC=0 */
|
||||
common_parse_operator_id ("000600", FALSE, 0, 0);
|
||||
common_parse_operator_id ("000600", FALSE, 0, 0, FALSE);
|
||||
/* Invalid, non-digits */
|
||||
common_parse_operator_id ("000Z00", FALSE, 0, 0);
|
||||
common_parse_operator_id ("000Z00", FALSE, 0, 0, FALSE);
|
||||
/* Invalid, short */
|
||||
common_parse_operator_id ("123", FALSE, 0, 0);
|
||||
common_parse_operator_id ("123", FALSE, 0, 0, FALSE);
|
||||
/* Invalid, long */
|
||||
common_parse_operator_id ("1234567", FALSE, 0, 0);
|
||||
common_parse_operator_id ("1234567", FALSE, 0, 0, FALSE);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
Reference in New Issue
Block a user