diff options
author | Teijo Kinnunen <teijo.kinnunen@uros.com> | 2021-05-06 14:48:18 +0300 |
---|---|---|
committer | Teijo Kinnunen <teijo.kinnunen@uros.com> | 2021-05-17 12:46:52 +0300 |
commit | 14c4f27ae4a0ccdfec29090b9abd77112fec1516 (patch) | |
tree | 6dd184a3c357864178b897667333102589f1c31c /src | |
parent | 98fbd5a156a09d3dc46dbc52946a80450df13abb (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-broadband-modem-qmi.c | 2 | ||||
-rw-r--r-- | src/mm-iface-modem-3gpp.c | 4 | ||||
-rw-r--r-- | src/mm-modem-helpers.c | 4 | ||||
-rw-r--r-- | src/mm-modem-helpers.h | 1 | ||||
-rw-r--r-- | src/mm-shared-qmi.c | 2 | ||||
-rw-r--r-- | src/mm-sim-qmi.c | 2 | ||||
-rw-r--r-- | src/tests/test-modem-helpers.c | 37 |
7 files changed, 30 insertions, 22 deletions
diff --git a/src/mm-broadband-modem-qmi.c b/src/mm-broadband-modem-qmi.c index 973cd954..0cee89a4 100644 --- a/src/mm-broadband-modem-qmi.c +++ b/src/mm-broadband-modem-qmi.c @@ -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; diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index 68d00936..0b07534f 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -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); } diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 405b3332..75ae00e1 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -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; } diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 9f39bcf0..d4d177a1 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -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); diff --git a/src/mm-shared-qmi.c b/src/mm-shared-qmi.c index b4c27b5e..65d69e07 100644 --- a/src/mm-shared-qmi.c +++ b/src/mm-shared-qmi.c @@ -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); diff --git a/src/mm-sim-qmi.c b/src/mm-sim-qmi.c index be58997a..165994df 100644 --- a/src/mm-sim-qmi.c +++ b/src/mm-sim-qmi.c @@ -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; diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 3a2f7b66..7fbc489a 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -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); } /*****************************************************************************/ |