summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2021-10-07 00:24:58 +0200
committerAleksander Morgado <aleksander@aleksander.es>2021-10-12 22:21:08 +0200
commit01b81154b9e272ff06e1cfa1a75c7f6b91eb97da (patch)
treec5d6bb3b6a9f40177aa03f7ed2edab6df313321c
parent0ab30982d28d2ff42e95ecde649c4e8a7e3e876e (diff)
ms-basic-connect-v3: fix MbimTai struct definition
The PLMN field is not a single 32 bit value, it's really 2 separate guint16 values. This is important because the endianness change in BE systems would be different. Also, the format of the MCC and MNC inside the PLMN fields is very specific to the implementation (BCD encoded, MNC PCS digit indicated in most significant bit of the MNC field...).
-rw-r--r--data/mbim-service-ms-basic-connect-v3.json20
-rw-r--r--src/mbimcli/mbimcli-basic-connect.c37
-rw-r--r--src/mbimcli/mbimcli-helpers.c21
-rw-r--r--src/mbimcli/mbimcli-helpers.h7
4 files changed, 66 insertions, 19 deletions
diff --git a/data/mbim-service-ms-basic-connect-v3.json b/data/mbim-service-ms-basic-connect-v3.json
index 90e276f..ed5b64e 100644
--- a/data/mbim-service-ms-basic-connect-v3.json
+++ b/data/mbim-service-ms-basic-connect-v3.json
@@ -49,11 +49,13 @@
"array-size-field" : "TelephoneNumbersCount" } ] },
// *********************************************************************************
- { "name" : "MbimTAI",
+ { "name" : "MbimTai",
"type" : "Struct",
"since" : "1.28",
- "contents" : [ { "name" : "Plmn",
- "format" : "guint32" },
+ "contents" : [ { "name" : "PlmnMcc",
+ "format" : "guint16" },
+ { "name" : "PlmnMnc",
+ "format" : "guint16" },
{ "name" : "Tac",
"format" : "guint32" } ] },
@@ -80,9 +82,9 @@
{ "name" : "DataSubclass",
"format" : "guint32",
"public-format" : "MbimDataSubclass" },
- { "name" : "TAI",
- "format" : "struct",
- "struct-type" : "MbimTAI" } ],
+ { "name" : "Tai",
+ "format" : "struct",
+ "struct-type" : "MbimTai" } ],
"notification" : [ { "name" : "NwError",
"format" : "guint32" },
{ "name" : "PacketServiceState",
@@ -101,7 +103,7 @@
{ "name" : "DataSubclass",
"format" : "guint32",
"public-format" : "MbimDataSubclass" },
- { "name" : "TAI",
- "format" : "struct",
- "struct-type" : "MbimTAI" } ] }
+ { "name" : "Tai",
+ "format" : "struct",
+ "struct-type" : "MbimTai" } ] }
]
diff --git a/src/mbimcli/mbimcli-basic-connect.c b/src/mbimcli/mbimcli-basic-connect.c
index c2206ba..b9e925e 100644
--- a/src/mbimcli/mbimcli-basic-connect.c
+++ b/src/mbimcli/mbimcli-basic-connect.c
@@ -1581,7 +1581,7 @@ packet_service_ready (MbimDevice *device,
guint64 downlink_speed;
MbimFrequencyRange frequency_range;
MbimDataSubclass data_subclass;
- MbimTAI *tai = NULL;
+ g_autoptr(MbimTai) tai = NULL;
response = mbim_device_command_finish (device, res, &error);
if (!response || !mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
@@ -1681,13 +1681,44 @@ packet_service_ready (MbimDevice *device,
if (mbim_device_check_ms_mbimex_version (device, 3, 0)) {
g_autofree gchar *data_subclass_str = NULL;
+ g_autofree gchar *tai_plmn_mcc_str = NULL;
+ g_autofree gchar *tai_plmn_mnc_str = NULL;
+
+ /* Mobile Country Code of 3 decimal digits; The
+ * least significant 12 bits contains BCD-encoded
+ * 3 decimal digits sequentially for the MCC, with
+ * the last digit of the MCC in the least significant
+ * 4 bits. The unused bits in the UINT16 integer
+ * must be zeros. */
+ tai_plmn_mcc_str = g_strdup_printf ("%03x", tai->plmn_mcc & 0x0FFF);
+
+ /* Mobile Network Code of either 3 or 2 decimal
+ * digits; The most significant bit indicates
+ * whether the MNC has 2 decimal digits or 3
+ * decimal digits. If this bit has 1, the MNC has 2
+ * decimal digits and the least significant 8 bits
+ * contains them in BCD-encoded form
+ * sequentially, with the last digit of the MNC in
+ * the least significant 4 bits. If the most
+ * significant bit has 0, the MNC has 3 decimal
+ * digits and the least significant 12 bits contains
+ * them in BCD-encoded form sequentially, with
+ * the last digit of the MNC in the least
+ * esignificant 4 bits. The unused bits in the
+ * UINT16 integer must be zeros. */
+ if (tai->plmn_mnc & 0x8000)
+ tai_plmn_mnc_str = g_strdup_printf ("%02x", tai->plmn_mnc & 0x00FF);
+ else
+ tai_plmn_mnc_str = g_strdup_printf ("%03x", tai->plmn_mnc & 0x0FFF);
data_subclass_str = mbim_data_subclass_build_string_from_mask (data_subclass);
g_print ("\t Data sub class: '%s'\n"
- "\t TAI PLMN: '%u'\n"
+ "\t TAI PLMN MCC: '%s'\n"
+ "\t TAI PLMN MNC: '%s'\n"
"\t TAI TAC: '%u'\n",
VALIDATE_UNKNOWN (data_subclass_str),
- tai->plmn,
+ tai_plmn_mcc_str,
+ tai_plmn_mnc_str,
tai->tac);
}
diff --git a/src/mbimcli/mbimcli-helpers.c b/src/mbimcli/mbimcli-helpers.c
index c997654..df9c978 100644
--- a/src/mbimcli/mbimcli-helpers.c
+++ b/src/mbimcli/mbimcli-helpers.c
@@ -37,8 +37,8 @@ mbimcli_read_uint_from_string (const gchar *str,
}
gboolean
-mbimcli_read_uint8_from_bcd_string (const gchar *str,
- guint8 *out)
+mbimcli_read_uint_from_bcd_string (const gchar *str,
+ guint *out)
{
gulong num;
@@ -55,14 +55,27 @@ mbimcli_read_uint8_from_bcd_string (const gchar *str,
* (base 16) and it will be valid bcd */
errno = 0;
num = strtoul (str, NULL, 16);
- if (!errno && num <= G_MAXUINT8) {
- *out = (guint8)num;
+ if (!errno && num <= G_MAXUINT) {
+ *out = (guint)num;
return TRUE;
}
return FALSE;
}
gboolean
+mbimcli_read_uint8_from_bcd_string (const gchar *str,
+ guint8 *out)
+{
+ guint num;
+
+ if (!mbimcli_read_uint_from_bcd_string (str, &num) || (num > G_MAXUINT8))
+ return FALSE;
+
+ *out = (guint8)num;
+ return TRUE;
+}
+
+gboolean
mbimcli_read_boolean_from_string (const gchar *value,
gboolean *out)
{
diff --git a/src/mbimcli/mbimcli-helpers.h b/src/mbimcli/mbimcli-helpers.h
index 126cf03..925d4eb 100644
--- a/src/mbimcli/mbimcli-helpers.h
+++ b/src/mbimcli/mbimcli-helpers.h
@@ -13,9 +13,10 @@
#ifndef __MBIMCLI_HELPERS_H__
#define __MBIMCLI_HELPERS_H__
-gboolean mbimcli_read_uint_from_string (const gchar *str,
- guint *out);
-
+gboolean mbimcli_read_uint_from_string (const gchar *str,
+ guint *out);
+gboolean mbimcli_read_uint_from_bcd_string (const gchar *str,
+ guint *out);
gboolean mbimcli_read_uint8_from_bcd_string (const gchar *str,
guint8 *out);