aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-01-05 00:38:54 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2019-01-08 14:07:07 +0000
commit02fd83d79991665d59362f24d7a0ed263c6d91c0 (patch)
treecd31ee90c77959890075acfea33547e76ec5e527 /src
parent45f89c938dcd5fce0bcaeee2e88c3ad7247277a0 (diff)
add osmo_mi_name(), for MI-to-string like "IMSI-123456"
We have gsm48_mi_to_string() and osmo_bcd2str(), but still lack a function that conveniently prints both MI type and value in one function call. Related: http://people.osmocom.org/neels/mi_mi_mi.jpg Change-Id: I7798c3ef983c2e333b2b9cbffef6f366f370bd81
Diffstat (limited to 'src')
-rw-r--r--src/gsm/gsm48.c36
-rw-r--r--src/gsm/libosmogsm.map1
2 files changed, 37 insertions, 0 deletions
diff --git a/src/gsm/gsm48.c b/src/gsm/gsm48.c
index 190622ff..853ea513 100644
--- a/src/gsm/gsm48.c
+++ b/src/gsm/gsm48.c
@@ -433,6 +433,42 @@ const char *gsm48_mi_type_name(uint8_t mi)
return get_value_string(mi_type_names, mi);
}
+/*! Return a human readable representation of a Mobile Identity in static buffer.
+ * \param[in] mi Mobile Identity buffer containing 3GPP TS 04.08 style MI type and data.
+ * \param[in] mi_len Length of mi.
+ * \return A string like "IMSI-1234567", "TMSI-0x1234ABCD" or "unknown", "TMSI-invalid"...
+ */
+const char *osmo_mi_name(const uint8_t *mi, uint8_t mi_len)
+{
+ static char mi_name[10 + GSM48_MI_SIZE + 1];
+ uint8_t mi_type;
+ uint32_t tmsi;
+ char mi_string[GSM48_MI_SIZE];
+
+ mi_type = (mi && mi_len) ? (mi[0] & GSM_MI_TYPE_MASK) : GSM_MI_TYPE_NONE;
+
+ switch (mi_type) {
+ case GSM_MI_TYPE_TMSI:
+ /* Table 10.5.4.3, reverse generate_mid_from_tmsi */
+ if (mi_len == GSM48_TMSI_LEN && mi[0] == (0xf0 | GSM_MI_TYPE_TMSI)) {
+ tmsi = osmo_load32be(&mi[1]);
+ snprintf(mi_name, sizeof(mi_name), "TMSI-0x%08" PRIX32, tmsi);
+ return mi_name;
+ }
+ return "TMSI-invalid";
+
+ case GSM_MI_TYPE_IMSI:
+ case GSM_MI_TYPE_IMEI:
+ case GSM_MI_TYPE_IMEISV:
+ osmo_bcd2str(mi_string, sizeof(mi_string), mi, 1, (mi_len * 2) - (mi[0] & GSM_MI_ODD ? 0 : 1), true);
+ snprintf(mi_name, sizeof(mi_name), "%s-%s", gsm48_mi_type_name(mi_type), mi_string);
+ return mi_name;
+
+ default:
+ return "unknown";
+ }
+}
+
/*! Checks is particular message is cipherable in A/Gb mode according to
* 3GPP TS 24.008 ยง 4.7.1.2
* \param[in] hdr Message header
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index bb978786..8b7a1641 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -325,6 +325,7 @@ gsm48_rr_att_tlvdef;
gsm48_set_dtx;
gsm48_dtx_mode;
gsm48_mi_type_name;
+osmo_mi_name;
gsm48_mcc_mnc_to_bcd;
gsm48_mcc_mnc_from_bcd;
gsm48_generate_lai2;