diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2016-08-22 23:34:53 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2016-10-12 13:24:09 +0200 |
commit | 5a9f093839029c10791fbc67047c3b4843a53063 (patch) | |
tree | 54a235dbfdb7e7d94cba44112d6a4c43294cba00 /src/mm-modem-helpers.c | |
parent | 75ad9bf98be802bec12b0c8ba0ed9fd95ce8902f (diff) | |
download | ModemManager-5a9f093839029c10791fbc67047c3b4843a53063.tar.gz |
modem-helpers: implement less strict APN comparison
u-blox modems will append a string showing the MCC and MNC info to the access
point name listed in AT+CGDCONT? responses. We will try to detect when that
happens, and we just accept the match.
The logic doesn't just look for a string prefix; it also looks for the special
MCC + MNC suffix, which is much more restrictive, to try to avoid false
positives.
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index eecdc5e53..d51f7782a 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -1031,6 +1031,50 @@ out: } /*************************************************************************/ +/* Logic to compare two APN names */ + +gboolean +mm_3gpp_cmp_apn_name (const gchar *requested, + const gchar *existing) +{ + size_t requested_len; + size_t existing_len; + + /* Both must be given to compare properly */ + if (!existing || !existing[0] || !requested || !requested[0]) + return FALSE; + + requested_len = strlen (requested); + + /* + * 1) The requested APN should be at least the prefix of the existing one. + */ + if (g_ascii_strncasecmp (existing, requested, requested_len) != 0) + return FALSE; + + /* + * 2) If the existing one is actually the same as the requested one (i.e. + * there are no more different chars in the existing one), we're done. + */ + if (existing[requested_len] == '\0') + return TRUE; + + existing_len = strlen (existing); + + /* 3) Special handling for PDP contexts reported by u-blox modems once the + * contexts have been activated at least once: + * "ac.vodafone.es.MNC001.MCC214.GPRS" should match "ac.vodafone.es" + */ + if ((existing_len > (requested_len + 14)) && + g_ascii_strncasecmp (&existing[requested_len], ".mnc", 4) == 0 && + g_ascii_strncasecmp (&existing[requested_len + 7], ".mcc", 4) == 0) + return TRUE; + + /* No match */ + return FALSE; +} + +/*************************************************************************/ static void mm_3gpp_pdp_context_format_free (MM3gppPdpContextFormat *format) |