diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-09-25 16:06:38 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2018-09-25 19:21:00 +0200 |
commit | 0ca95254ae507caddebe45f6ee6e230a99e82bfc (patch) | |
tree | e415340dcd598ce60bf1cabdecebcd2803a49492 | |
parent | 4d16eec5fbbe16e92dd25bea420fb8c503e520ec (diff) | |
download | ModemManager-0ca95254ae507caddebe45f6ee6e230a99e82bfc.tar.gz |
libmm-glib,location-3gpp: don't ignore location updates when MNC is 0
E.g. China Mobile (MCC 460, MNC 0).
$ mmcli -m toby --location-get
/org/freedesktop/ModemManager1/Modem/0
-------------------------
3GPP location | Mobile country code: '460'
| Mobile network code: '0'
| Location area code: '6188'
| Cell ID: '40955'
-------------------------
GPS NMEA traces | Not available
-------------------------
Raw GPS | Not available
-------------------------
CDMA BS | Not available
-rw-r--r-- | libmm-glib/mm-location-3gpp.c | 38 | ||||
-rw-r--r-- | libmm-glib/mm-location-3gpp.h | 1 | ||||
-rw-r--r-- | src/mm-iface-modem-location.c | 9 |
3 files changed, 38 insertions, 10 deletions
diff --git a/libmm-glib/mm-location-3gpp.c b/libmm-glib/mm-location-3gpp.c index a4cd77724..d525db7a9 100644 --- a/libmm-glib/mm-location-3gpp.c +++ b/libmm-glib/mm-location-3gpp.c @@ -42,6 +42,11 @@ struct _MMLocation3gppPrivate { gulong location_area_code; gulong cell_id; gulong tracking_area_code; + + /* We use 0 as default MNC when unknown, and that is a bit problematic if + * the network operator has actually a 0 MNC (e.g. China Mobile, 46000). + * We need to explicitly track whether MNC is set or not. */ + gboolean mobile_network_code_set; }; /*****************************************************************************/ @@ -84,6 +89,10 @@ mm_location_3gpp_set_mobile_country_code (MMLocation3gpp *self, * * Gets the Mobile Network Code of the 3GPP network. * + * Note that 0 may actually be a valid MNC. In general, the MNC should be + * considered valid just if the reported MCC is valid, as MCC should never + * be 0. + * * Returns: the MNC, or 0 if unknown. */ guint @@ -101,9 +110,10 @@ mm_location_3gpp_set_mobile_network_code (MMLocation3gpp *self, g_return_val_if_fail (MM_IS_LOCATION_3GPP (self), FALSE); /* If no change in the location info, don't do anything */ - if (self->priv->mobile_network_code == mobile_network_code) + if (self->priv->mobile_network_code_set && (self->priv->mobile_network_code == mobile_network_code)) return FALSE; + self->priv->mobile_network_code_set = TRUE; self->priv->mobile_network_code = mobile_network_code; return TRUE; } @@ -206,6 +216,30 @@ mm_location_3gpp_set_tracking_area_code (MMLocation3gpp *self, /*****************************************************************************/ +gboolean +mm_location_3gpp_reset (MMLocation3gpp *self) +{ + g_return_val_if_fail (MM_IS_LOCATION_3GPP (self), FALSE); + + if (self->priv->mobile_country_code == 0 && + !self->priv->mobile_network_code_set && + self->priv->mobile_network_code == 0 && + self->priv->location_area_code == 0 && + self->priv->tracking_area_code == 0 && + self->priv->cell_id == 0) + return FALSE; + + self->priv->mobile_country_code = 0; + self->priv->mobile_network_code_set = FALSE; + self->priv->mobile_network_code = 0; + self->priv->location_area_code = 0; + self->priv->tracking_area_code = 0; + self->priv->cell_id = 0; + return TRUE; +} + +/*****************************************************************************/ + GVariant * mm_location_3gpp_get_string_variant (MMLocation3gpp *self) { @@ -214,7 +248,7 @@ mm_location_3gpp_get_string_variant (MMLocation3gpp *self) g_return_val_if_fail (MM_IS_LOCATION_3GPP (self), NULL); if (self->priv->mobile_country_code && - self->priv->mobile_network_code && + self->priv->mobile_network_code_set && /* MNC 0 is actually valid! */ (self->priv->location_area_code || self->priv->tracking_area_code) && self->priv->cell_id) { gchar *str; diff --git a/libmm-glib/mm-location-3gpp.h b/libmm-glib/mm-location-3gpp.h index cde055ce5..abcb4b840 100644 --- a/libmm-glib/mm-location-3gpp.h +++ b/libmm-glib/mm-location-3gpp.h @@ -84,6 +84,7 @@ gboolean mm_location_3gpp_set_cell_id (MMLocation3gpp *self, gulong cell_id); gboolean mm_location_3gpp_set_tracking_area_code (MMLocation3gpp *self, gulong tracking_area_code); +gboolean mm_location_3gpp_reset (MMLocation3gpp *self); #endif diff --git a/src/mm-iface-modem-location.c b/src/mm-iface-modem-location.c index 88fd2bf82..2ccb64342 100644 --- a/src/mm-iface-modem-location.c +++ b/src/mm-iface-modem-location.c @@ -383,15 +383,8 @@ mm_iface_modem_location_3gpp_clear (MMIfaceModemLocation *self) return; if (mm_gdbus_modem_location_get_enabled (skeleton) & MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI) { - guint changed = 0; - g_assert (ctx->location_3gpp != NULL); - changed += mm_location_3gpp_set_location_area_code (ctx->location_3gpp, 0); - changed += mm_location_3gpp_set_tracking_area_code (ctx->location_3gpp, 0); - changed += mm_location_3gpp_set_cell_id (ctx->location_3gpp, 0); - changed += mm_location_3gpp_set_mobile_country_code (ctx->location_3gpp, 0); - changed += mm_location_3gpp_set_mobile_network_code (ctx->location_3gpp, 0); - if (changed) + if (mm_location_3gpp_reset (ctx->location_3gpp)) notify_3gpp_location_update (self, skeleton, ctx->location_3gpp); } |