summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeemu Ikonen <tpikonen@mailbox.org>2021-10-21 12:46:59 +0300
committerTeemu Ikonen <tpikonen@mailbox.org>2021-11-19 07:39:12 +0000
commitdf34ae02bd616ab396246458b96bf881f6682fd1 (patch)
tree740a02e510dadb5cc221e1b6c510199780a3bbd6
parentf1dd8cc961b76249519fc600f5aebf0bb4f4a538 (diff)
Use new operator code API from ModemManager 1.18
ModemManager 1.18 deprecated mm_location_3gpp_get_mobile_country_code and mm_location_3gpp_get_mobile_network_code funtions and added mm_location_3gpp_get_operator_code as a replacement. This was made because Mobile Network Code is a string where the number of digits in the value matters, e.g. "10" != "010". Replace the Mobile Country Code (mcc) and Mobile Network Code (mnc) ints in GClue3GTower with Operator Code (opc) string. Adapt depending functions and signals accordingly and add an opc to (mcc, mnc) conversion function which is used when sending data to the MLS API.
-rw-r--r--src/gclue-3g-tower.h6
-rw-r--r--src/gclue-3g.c7
-rw-r--r--src/gclue-marshal.list2
-rw-r--r--src/gclue-modem-manager.c63
-rw-r--r--src/gclue-modem.c7
-rw-r--r--src/gclue-mozilla.c42
6 files changed, 96 insertions, 31 deletions
diff --git a/src/gclue-3g-tower.h b/src/gclue-3g-tower.h
index 6b9391e..4333245 100644
--- a/src/gclue-3g-tower.h
+++ b/src/gclue-3g-tower.h
@@ -32,9 +32,11 @@ typedef enum {
typedef struct _GClue3GTower GClue3GTower;
+#define GCLUE_3G_TOWER_OPERATOR_CODE_STR_LEN 6
+#define GCLUE_3G_TOWER_COUNTRY_CODE_STR_LEN 3
+
struct _GClue3GTower {
- guint mcc;
- guint mnc;
+ gchar opc[GCLUE_3G_TOWER_OPERATOR_CODE_STR_LEN + 1];
gulong lac;
gulong cell_id;
GClueTowerTec tec;
diff --git a/src/gclue-3g.c b/src/gclue-3g.c
index 998942e..bbcb791 100644
--- a/src/gclue-3g.c
+++ b/src/gclue-3g.c
@@ -251,8 +251,7 @@ gclue_3g_get_available_accuracy_level (GClueWebSource *web,
static void
on_fix_3g (GClueModem *modem,
- guint mcc,
- guint mnc,
+ const gchar *opc,
gulong lac,
gulong cell_id,
GClueTowerTec tec,
@@ -262,8 +261,8 @@ on_fix_3g (GClueModem *modem,
if (priv->tower == NULL)
priv->tower = g_slice_new0 (GClue3GTower);
- priv->tower->mcc = mcc;
- priv->tower->mnc = mnc;
+ g_strlcpy (priv->tower->opc, opc,
+ GCLUE_3G_TOWER_OPERATOR_CODE_STR_LEN + 1);
priv->tower->lac = lac;
priv->tower->cell_id = cell_id;
priv->tower->tec = tec;
diff --git a/src/gclue-marshal.list b/src/gclue-marshal.list
index 2311586..1fe04ca 100644
--- a/src/gclue-marshal.list
+++ b/src/gclue-marshal.list
@@ -1,3 +1,3 @@
VOID:UINT,UINT,ULONG,ULONG
-VOID:UINT,UINT,ULONG,ULONG,ENUM
+VOID:STRING,ULONG,ULONG,ENUM
VOID:DOUBLE,DOUBLE
diff --git a/src/gclue-modem-manager.c b/src/gclue-modem-manager.c
index c922c30..9a8cf57 100644
--- a/src/gclue-modem-manager.c
+++ b/src/gclue-modem-manager.c
@@ -262,22 +262,48 @@ gclue_modem_interface_init (GClueModemInterface *iface)
iface->disable_gps = gclue_modem_manager_disable_gps;
}
+#if !MM_CHECK_VERSION(1, 18, 0)
+static void
+opc_from_mccmnc (MMLocation3gpp *location_3gpp,
+ gchar *opc_buf)
+{
+ guint mcc, mnc;
+
+ mcc = mm_location_3gpp_get_mobile_country_code (location_3gpp);
+ mnc = mm_location_3gpp_get_mobile_network_code (location_3gpp);
+
+ if (mcc < 1000 && mnc < 1000) {
+ g_snprintf (opc_buf, GCLUE_3G_TOWER_OPERATOR_CODE_STR_LEN + 1,
+ "%03u%03u", mcc, mnc);
+ } else {
+ g_warning ("Invalid MCC or MNC value");
+ opc_buf[0] = '\0';
+ }
+}
+#endif
+
static gboolean
is_location_3gpp_same (GClueModemManager *manager,
- guint new_mcc,
- guint new_mnc,
- gulong new_lac,
- gulong new_cell_id)
+ const gchar *new_opc,
+ gulong new_lac,
+ gulong new_cell_id)
{
GClueModemManagerPrivate *priv = manager->priv;
- guint mcc, mnc;
+ const gchar *opc;
gulong lac, cell_id;
+#if !MM_CHECK_VERSION(1, 18, 0)
+ gchar opc_buf[GCLUE_3G_TOWER_OPERATOR_CODE_STR_LEN + 1];
+#endif
if (priv->location_3gpp == NULL)
return FALSE;
- mcc = mm_location_3gpp_get_mobile_country_code (priv->location_3gpp);
- mnc = mm_location_3gpp_get_mobile_network_code (priv->location_3gpp);
+#if MM_CHECK_VERSION(1, 18, 0)
+ opc = mm_location_3gpp_get_operator_code (priv->location_3gpp);
+#else
+ opc_from_mccmnc (priv->location_3gpp, opc_buf);
+ opc = opc_buf;
+#endif
lac = mm_location_3gpp_get_location_area_code (priv->location_3gpp);
// Most likely this is an LTE connection and with the mozilla
@@ -290,8 +316,7 @@ is_location_3gpp_same (GClueModemManager *manager,
cell_id = mm_location_3gpp_get_cell_id (priv->location_3gpp);
- return (mcc == new_mcc &&
- mnc == new_mnc &&
+ return (g_strcmp0 (opc, new_opc) == 0 &&
lac == new_lac &&
cell_id == new_cell_id);
}
@@ -306,9 +331,12 @@ on_get_3gpp_ready (GObject *source_object,
MMModemLocation *modem_location = MM_MODEM_LOCATION (source_object);
g_autoptr(MMLocation3gpp) location_3gpp = NULL;
GError *error = NULL;
- guint mcc, mnc;
+ const gchar *opc;
gulong lac, cell_id;
GClueTowerTec tec = GCLUE_TOWER_TEC_3G;
+#if !MM_CHECK_VERSION(1, 18, 0)
+ gchar opc_buf[GCLUE_3G_TOWER_OPERATOR_CODE_STR_LEN + 1];
+#endif
location_3gpp = mm_modem_location_get_3gpp_finish (modem_location,
res,
@@ -325,8 +353,15 @@ on_get_3gpp_ready (GObject *source_object,
return;
}
- mcc = mm_location_3gpp_get_mobile_country_code (location_3gpp);
- mnc = mm_location_3gpp_get_mobile_network_code (location_3gpp);
+#if MM_CHECK_VERSION(1, 18, 0)
+ opc = mm_location_3gpp_get_operator_code (location_3gpp);
+#else
+ opc_from_mccmnc (location_3gpp, opc_buf);
+ opc = opc_buf;
+#endif
+ if (!opc || !opc[0])
+ return;
+
lac = mm_location_3gpp_get_location_area_code (location_3gpp);
// Most likely this is an LTE connection and with the mozilla
@@ -340,14 +375,14 @@ on_get_3gpp_ready (GObject *source_object,
cell_id = mm_location_3gpp_get_cell_id (location_3gpp);
- if (is_location_3gpp_same (manager, mcc, mnc, lac, cell_id)) {
+ if (is_location_3gpp_same (manager, opc, lac, cell_id)) {
g_debug ("New 3GPP location is same as last one");
return;
}
g_clear_object (&priv->location_3gpp);
priv->location_3gpp = g_steal_pointer (&location_3gpp);
- g_signal_emit (manager, signals[FIX_3G], 0, mcc, mnc, lac, cell_id, tec);
+ g_signal_emit (manager, signals[FIX_3G], 0, opc, lac, cell_id, tec);
}
static void
diff --git a/src/gclue-modem.c b/src/gclue-modem.c
index f587e17..2ce0e1d 100644
--- a/src/gclue-modem.c
+++ b/src/gclue-modem.c
@@ -78,11 +78,10 @@ gclue_modem_default_init (GClueModemInterface *iface)
0,
NULL,
NULL,
- gclue_marshal_VOID__UINT_UINT_ULONG_ULONG_ENUM,
+ gclue_marshal_VOID__STRING_ULONG_ULONG_ENUM,
G_TYPE_NONE,
- 5,
- G_TYPE_UINT,
- G_TYPE_UINT,
+ 4,
+ G_TYPE_STRING,
G_TYPE_ULONG,
G_TYPE_ULONG,
G_TYPE_INT);
diff --git a/src/gclue-mozilla.c b/src/gclue-mozilla.c
index 6280b74..8e602c1 100644
--- a/src/gclue-mozilla.c
+++ b/src/gclue-mozilla.c
@@ -112,6 +112,30 @@ get_url (void)
return gclue_config_get_wifi_url (config);
}
+static gboolean
+operator_code_to_mcc_mnc (const gchar *opc,
+ gint64 *mcc_p,
+ gint64 *mnc_p)
+{
+ gchar *end;
+ gchar mcc_str[GCLUE_3G_TOWER_COUNTRY_CODE_STR_LEN + 1] = { 0 };
+
+ g_strlcpy (mcc_str, opc, GCLUE_3G_TOWER_COUNTRY_CODE_STR_LEN + 1);
+ *mcc_p = g_ascii_strtoll (mcc_str, &end, 10);
+ if (*end != '\0')
+ goto error;
+
+ *mnc_p = g_ascii_strtoll (opc + GCLUE_3G_TOWER_COUNTRY_CODE_STR_LEN,
+ &end, 10);
+ if (*end != '\0')
+ goto error;
+
+ return TRUE;
+error:
+ g_warning ("Operator code conversion failed");
+ return FALSE;
+}
+
SoupMessage *
gclue_mozilla_create_query (GList *bss_list, /* As in Access Points */
GClue3GTower *tower,
@@ -126,6 +150,7 @@ gclue_mozilla_create_query (GList *bss_list, /* As in Access Points */
const char *uri;
guint n_non_ignored_bsss;
GList *iter;
+ gint64 mcc, mnc;
builder = json_builder_new ();
json_builder_begin_object (builder);
@@ -147,7 +172,9 @@ gclue_mozilla_create_query (GList *bss_list, /* As in Access Points */
n_non_ignored_bsss++;
}
- if (tower != NULL) {
+ if (tower != NULL &&
+ operator_code_to_mcc_mnc (tower->opc, &mcc, &mnc)) {
+
json_builder_set_member_name (builder, "radioType");
json_builder_add_string_value (builder, "gsm");
@@ -159,9 +186,9 @@ gclue_mozilla_create_query (GList *bss_list, /* As in Access Points */
json_builder_set_member_name (builder, "cellId");
json_builder_add_int_value (builder, tower->cell_id);
json_builder_set_member_name (builder, "mobileCountryCode");
- json_builder_add_int_value (builder, tower->mcc);
+ json_builder_add_int_value (builder, mcc);
json_builder_set_member_name (builder, "mobileNetworkCode");
- json_builder_add_int_value (builder, tower->mnc);
+ json_builder_add_int_value (builder, mnc);
json_builder_set_member_name (builder, "locationAreaCode");
json_builder_add_int_value (builder, tower->lac);
if (tower->tec == GCLUE_TOWER_TEC_4G) {
@@ -304,6 +331,7 @@ gclue_mozilla_create_submit_query (GClueLocation *location,
GList *iter;
gdouble lat, lon, accuracy, altitude;
GDateTime *datetime;
+ gint64 mcc, mnc;
url = get_submit_config (&nick);
if (url == NULL)
@@ -382,7 +410,9 @@ gclue_mozilla_create_submit_query (GClueLocation *location,
json_builder_end_array (builder); /* wifi */
}
- if (tower != NULL) {
+ if (tower != NULL &&
+ operator_code_to_mcc_mnc (tower->opc, &mcc, &mnc)) {
+
json_builder_set_member_name (builder, "cell");
json_builder_begin_array (builder);
@@ -393,9 +423,9 @@ gclue_mozilla_create_submit_query (GClueLocation *location,
json_builder_set_member_name (builder, "cid");
json_builder_add_int_value (builder, tower->cell_id);
json_builder_set_member_name (builder, "mcc");
- json_builder_add_int_value (builder, tower->mcc);
+ json_builder_add_int_value (builder, mcc);
json_builder_set_member_name (builder, "mnc");
- json_builder_add_int_value (builder, tower->mnc);
+ json_builder_add_int_value (builder, mnc);
json_builder_set_member_name (builder, "lac");
json_builder_add_int_value (builder, tower->lac);