aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib/mm-bearer-properties.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-11-30 21:51:32 +0100
committerAleksander Morgado <aleksander@aleksander.es>2020-12-21 12:05:57 +0000
commit5629f47a59b48f2604fd8e9e4af7209b138aef21 (patch)
treebf3d42242e591cb70fe3dcbf0b7bb7851cd7ebc4 /libmm-glib/mm-bearer-properties.c
parentc99cc9210e7a93be1b572d686f5acdeb0160dd3f (diff)
libmm-glib,bearer-properties: allow loose comparisons
When comparing bearer properties provided by the user versus loaded from the modem, we shouldn't be very strict, e.g.: * Password or other fields may not be readable from the device. * Some fields may not apply at all (e.g. RM protocol for EPS bearers) * NULL strings could be assumed equal to empty strings. * If no explicit IP type specified, an IPv4 default may be assumed. * If no explicit allowed auth specified, 'none' default may be assumed. These loose comparisons are applied when managing the initial EPS bearer settings and status, and we keep the strict comparison only during the connection attempt lookup of a bearer with certain settings, as those bearer objects are all created in the same place with the same rules.
Diffstat (limited to 'libmm-glib/mm-bearer-properties.c')
-rw-r--r--libmm-glib/mm-bearer-properties.c101
1 files changed, 91 insertions, 10 deletions
diff --git a/libmm-glib/mm-bearer-properties.c b/libmm-glib/mm-bearer-properties.c
index 5ed4438e..904d1248 100644
--- a/libmm-glib/mm-bearer-properties.c
+++ b/libmm-glib/mm-bearer-properties.c
@@ -667,21 +667,102 @@ mm_bearer_properties_new_from_dictionary (GVariant *dictionary,
/*****************************************************************************/
+static gboolean
+cmp_str (const gchar *a,
+ const gchar *b,
+ MMBearerPropertiesCmpFlags flags)
+{
+ /* Strict match */
+ if ((!a && !b) || (a && b && g_strcmp0 (a, b) == 0))
+ return TRUE;
+ /* Additional loose match, consider NULL and EMPTY string equal */
+ if (flags & MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE) {
+ if ((!a && !b[0]) || (!b && !a[0]))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static gboolean
+cmp_ip_type (MMBearerIpFamily a,
+ MMBearerIpFamily b,
+ MMBearerPropertiesCmpFlags flags)
+{
+ /* Strict match */
+ if (a == b)
+ return TRUE;
+ /* Additional loose match NONE == IPV4 */
+ if (flags & MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE) {
+ if ((a == MM_BEARER_IP_FAMILY_NONE && b == MM_BEARER_IP_FAMILY_IPV4) ||
+ (b == MM_BEARER_IP_FAMILY_NONE && a == MM_BEARER_IP_FAMILY_IPV4))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static gboolean
+cmp_allowed_auth (MMBearerAllowedAuth a,
+ MMBearerAllowedAuth b,
+ MMBearerPropertiesCmpFlags flags)
+{
+ /* Strict match */
+ if (a == b)
+ return TRUE;
+ /* Additional loose match UNKNOWN == NONE */
+ if (flags & MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE) {
+ if ((a == MM_BEARER_ALLOWED_AUTH_UNKNOWN && b == MM_BEARER_ALLOWED_AUTH_NONE) ||
+ (b == MM_BEARER_ALLOWED_AUTH_UNKNOWN && a == MM_BEARER_ALLOWED_AUTH_NONE))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static gboolean
+cmp_allow_roaming (gboolean a,
+ gboolean a_set,
+ gboolean b,
+ gboolean b_set,
+ MMBearerPropertiesCmpFlags flags)
+{
+ /* Strict match */
+ if (a == b && a_set == b_set)
+ return TRUE;
+ /* Additional loose match UNSET == */
+ if (flags & MM_BEARER_PROPERTIES_CMP_FLAGS_LOOSE) {
+ if ((a == MM_BEARER_ALLOWED_AUTH_UNKNOWN && b == MM_BEARER_ALLOWED_AUTH_NONE) ||
+ (b == MM_BEARER_ALLOWED_AUTH_UNKNOWN && a == MM_BEARER_ALLOWED_AUTH_NONE))
+ return TRUE;
+ }
+ return FALSE;
+}
+
/**
* mm_bearer_properties_cmp: (skip)
*/
gboolean
-mm_bearer_properties_cmp (MMBearerProperties *a,
- MMBearerProperties *b)
+mm_bearer_properties_cmp (MMBearerProperties *a,
+ MMBearerProperties *b,
+ MMBearerPropertiesCmpFlags flags)
{
- return ((!g_strcmp0 (a->priv->apn, b->priv->apn)) &&
- (a->priv->ip_type == b->priv->ip_type) &&
- (a->priv->allowed_auth == b->priv->allowed_auth) &&
- (!g_strcmp0 (a->priv->user, b->priv->user)) &&
- (!g_strcmp0 (a->priv->password, b->priv->password)) &&
- (a->priv->allow_roaming == b->priv->allow_roaming) &&
- (a->priv->allow_roaming_set == b->priv->allow_roaming_set) &&
- (a->priv->rm_protocol == b->priv->rm_protocol));
+ if (!cmp_str (a->priv->apn, b->priv->apn, flags))
+ return FALSE;
+ if (!cmp_ip_type (a->priv->ip_type, b->priv->ip_type, flags))
+ return FALSE;
+ if (!cmp_allowed_auth (a->priv->allowed_auth, a->priv->allowed_auth, flags))
+ return FALSE;
+ if (!cmp_str (a->priv->user, b->priv->user, flags))
+ return FALSE;
+ if (!(flags & MM_BEARER_PROPERTIES_CMP_FLAGS_NO_PASSWORD) && !cmp_str (a->priv->password, b->priv->password, flags))
+ return FALSE;
+ if (!(flags & MM_BEARER_PROPERTIES_CMP_FLAGS_NO_ALLOW_ROAMING)) {
+ if (a->priv->allow_roaming != b->priv->allow_roaming)
+ return FALSE;
+ if (a->priv->allow_roaming_set != b->priv->allow_roaming)
+ return FALSE;
+ }
+ if (a->priv->rm_protocol != b->priv->rm_protocol)
+ return FALSE;
+ return TRUE;
}
/*****************************************************************************/