From c08a3fd30e293c6f2ac5c6dc1ec1bf6513413791 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Mon, 25 Jan 2021 22:00:01 +0100 Subject: [PATCH] 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 --- include/osmocom/gprs/gprs_bssgp_rim.h | 2 + src/gb/gprs_bssgp_rim.c | 62 +++++++++++++++++++++++++++ src/gb/libosmogb.map | 2 + 3 files changed, 66 insertions(+) diff --git a/include/osmocom/gprs/gprs_bssgp_rim.h b/include/osmocom/gprs/gprs_bssgp_rim.h index 55341de23..418c1bd2d 100644 --- a/include/osmocom/gprs/gprs_bssgp_rim.h +++ b/include/osmocom/gprs/gprs_bssgp_rim.h @@ -66,6 +66,8 @@ struct bssgp_rim_routing_info { * 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 844268aa4..15d6e227a 100644 --- a/src/gb/gprs_bssgp_rim.c +++ b/src/gb/gprs_bssgp_rim.c @@ -146,6 +146,68 @@ int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri) 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 b4d7fdb6e..c6bbc7879 100644 --- a/src/gb/libosmogb.map +++ b/src/gb/libosmogb.map @@ -35,6 +35,8 @@ bssgp_parse_rim_pdu; 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;