Change in libosmocore[master]: gprs_bssgp_rim: add functions to convert a RIM-RI to a string

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Wed Jan 27 11:58:53 UTC 2021


pespin has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/22438 )

Change subject: gprs_bssgp_rim: add functions to convert a RIM-RI to a string
......................................................................

gprs_bssgp_rim: add functions to convert a RIM-RI to a string

RIM routing formation structs can contain different variants of address
identifiers, so it is difficult for an API user to pick the _name()
function to generate a human readable string. Lets add
bssgp_rim_ri_name() and bssgp_rim_ri_name_buf() to make printing a
routing identifier easier.

Change-Id: Idca6bdccffe663aea71a0183ca3ea5bb5b59e702
Related: SYS#5103
---
M include/osmocom/gprs/gprs_bssgp_rim.h
M src/gb/gprs_bssgp_rim.c
M src/gb/libosmogb.map
3 files changed, 66 insertions(+), 0 deletions(-)

Approvals:
  pespin: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/gprs/gprs_bssgp_rim.h b/include/osmocom/gprs/gprs_bssgp_rim.h
index 55341de..418c1bd 100644
--- a/include/osmocom/gprs/gprs_bssgp_rim.h
+++ b/include/osmocom/gprs/gprs_bssgp_rim.h
@@ -66,6 +66,8 @@
  * address type (discr) of variable length. */
 #define BSSGP_RIM_ROUTING_INFO_MAXLEN 14
 
+char *bssgp_rim_ri_name_buf(char *buf, size_t buf_len, const struct bssgp_rim_routing_info *ri);
+const char *bssgp_rim_ri_name(const struct bssgp_rim_routing_info *ri);
 int bssgp_parse_rim_ri(struct bssgp_rim_routing_info *ri, const uint8_t *buf, unsigned int len);
 int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri);
 
diff --git a/src/gb/gprs_bssgp_rim.c b/src/gb/gprs_bssgp_rim.c
index 844268a..15d6e22 100644
--- a/src/gb/gprs_bssgp_rim.c
+++ b/src/gb/gprs_bssgp_rim.c
@@ -146,6 +146,68 @@
 	return len;
 }
 
+/*! Encode a RIM Routing information into a human readable string.
+ *  \param[buf] user provided string buffer to store the resulting string.
+ *  \param[buf_len] maximum length of string buffer.
+ *  \param[in] ri user provided input data struct.
+ *  \returns pointer to the beginning of the resulting string stored in string buffer. */
+char *bssgp_rim_ri_name_buf(char *buf, size_t buf_len, const struct bssgp_rim_routing_info *ri)
+{
+	char plmn_str[16];
+	char enb_id_str[16];
+	char g_id_ps_str[32];
+	struct osmo_plmn_id plmn;
+	struct osmo_cell_global_id_ps g_id_ps;
+
+	if (!ri)
+		return NULL;
+
+	switch (ri->discr) {
+	case BSSGP_RIM_ROUTING_INFO_GERAN:
+		g_id_ps.rai.rac = ri->geran.raid.rac;
+		g_id_ps.rai.lac.lac = ri->geran.raid.lac;
+		g_id_ps.rai.lac.plmn.mcc = ri->geran.raid.mcc;
+		g_id_ps.rai.lac.plmn.mnc_3_digits = ri->geran.raid.mnc_3_digits;
+		g_id_ps.rai.lac.plmn.mnc = ri->geran.raid.mnc;
+		g_id_ps.cell_identity = ri->geran.cid;
+		snprintf(buf, buf_len, "%s-%s", bssgp_rim_routing_info_discr_str(ri->discr),
+			 osmo_cgi_ps_name_buf(g_id_ps_str, sizeof(g_id_ps_str), &g_id_ps));
+		break;
+	case BSSGP_RIM_ROUTING_INFO_UTRAN:
+		g_id_ps.rai.rac = ri->utran.raid.rac;
+		g_id_ps.rai.lac.lac = ri->utran.raid.lac;
+		g_id_ps.rai.lac.plmn.mcc = ri->utran.raid.mcc;
+		g_id_ps.rai.lac.plmn.mnc_3_digits = ri->utran.raid.mnc_3_digits;
+		g_id_ps.rai.lac.plmn.mnc = ri->utran.raid.mnc;
+		g_id_ps.cell_identity = ri->utran.rncid;
+		snprintf(buf, buf_len, "%s-%s", bssgp_rim_routing_info_discr_str(ri->discr),
+			 osmo_cgi_ps_name_buf(g_id_ps_str, sizeof(g_id_ps_str), &g_id_ps));
+		break;
+	case BSSGP_RIM_ROUTING_INFO_EUTRAN:
+		plmn.mcc = ri->eutran.tai.mcc;
+		plmn.mnc = ri->eutran.tai.mnc;
+		plmn.mnc_3_digits = ri->eutran.tai.mnc_3_digits;
+		snprintf(buf, buf_len, "%s-%s-%u-%s", bssgp_rim_routing_info_discr_str(ri->discr),
+			 osmo_plmn_name_buf(plmn_str, sizeof(plmn_str), &plmn), ri->eutran.tai.tac,
+			 osmo_hexdump_buf(enb_id_str, sizeof(enb_id_str), ri->eutran.global_enb_id,
+					  ri->eutran.global_enb_id_len, "", false));
+		break;
+	default:
+		snprintf(buf, buf_len, "invalid");
+	}
+
+	return buf;
+}
+
+/*! Encode a RIM Routing information into a human readable string.
+ *  \param[in] ri user provided input data struct.
+ *  \returns pointer to the resulting string. */
+const char *bssgp_rim_ri_name(const struct bssgp_rim_routing_info *ri)
+{
+	static __thread char rim_ri_buf[64];
+	return bssgp_rim_ri_name_buf(rim_ri_buf, sizeof(rim_ri_buf), ri);
+}
+
 /*! Decode a RAN Information Request Application Container for NACC (3GPP TS 48.018, section 11.3.63.1.1).
  *  \param[out] user provided memory for decoded data struct.
  *  \param[in] buf user provided memory with the encoded value data of the IE.
diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map
index b4d7fdb..c6bbc78 100644
--- a/src/gb/libosmogb.map
+++ b/src/gb/libosmogb.map
@@ -35,6 +35,8 @@
 bssgp_parse_rim_ri;
 bssgp_ran_inf_app_id_strs;
 bssgp_rim_routing_info_discr_strs;
+bssgp_rim_ri_name_buf;
+bssgp_rim_ri_name;
 bssgp_set_bssgp_callback;
 bssgp_tx_bvc_block;
 bssgp_tx_bvc_reset;

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22438
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Idca6bdccffe663aea71a0183ca3ea5bb5b59e702
Gerrit-Change-Number: 22438
Gerrit-PatchSet: 3
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210127/9373fcec/attachment.htm>


More information about the gerrit-log mailing list