From 0db165344c6fcd92a7a17d1844131f7faa23151a Mon Sep 17 00:00:00 2001 From: Neels Janosch Hofmeyr Date: Wed, 17 May 2023 02:05:54 +0200 Subject: [PATCH] add ranap_domain_name() As simple as it may seem, turning the RANAP CS/PS domain indicator to a string so far is cumbersome. It is usually only CS or PS, but to be accurate we should also expect invalid values. After the umpteenth switch statement breaking up otherwise trivial code, I decided that yes, after all, a value_string[] is a good idea even for just two enum values that have only two-letter names. Callers will follow in upcoming patches. Related: SYS#6412 Change-Id: Ib3c5d772ccea8c854eec007de5c996d1b6640bc0 --- include/osmocom/hnbgw/hnbgw.h | 6 ++++++ src/osmo-hnbgw/hnbgw.c | 6 ++++++ src/osmo-hnbgw/hnbgw_rua.c | 14 +------------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h index 90aee5b..3e1b6a4 100644 --- a/include/osmocom/hnbgw/hnbgw.h +++ b/include/osmocom/hnbgw/hnbgw.h @@ -36,6 +36,12 @@ extern struct vty_app_info hnbgw_vty_info; #define DOMAIN_CS RANAP_CN_DomainIndicator_cs_domain #define DOMAIN_PS RANAP_CN_DomainIndicator_ps_domain +extern const struct value_string ranap_domain_names[]; +static inline const char *ranap_domain_name(RANAP_CN_DomainIndicator_t domain) +{ + return get_value_string(ranap_domain_names, domain); +} + enum hnb_ctrl_node { CTRL_NODE_HNB = _LAST_CTRL_NODE, _LAST_CTRL_NODE_HNB diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c index fc9e698..7faf7f7 100644 --- a/src/osmo-hnbgw/hnbgw.c +++ b/src/osmo-hnbgw/hnbgw.c @@ -41,6 +41,12 @@ struct hnbgw *g_hnbgw = NULL; +const struct value_string ranap_domain_names[] = { + { DOMAIN_CS, "CS" }, + { DOMAIN_PS, "PS" }, + {} +}; + void g_hnbgw_alloc(void *ctx) { OSMO_ASSERT(!g_hnbgw); diff --git a/src/osmo-hnbgw/hnbgw_rua.c b/src/osmo-hnbgw/hnbgw_rua.c index a354e4d..073f3ce 100644 --- a/src/osmo-hnbgw/hnbgw_rua.c +++ b/src/osmo-hnbgw/hnbgw_rua.c @@ -42,18 +42,6 @@ #include #include -static const char *cn_domain_indicator_to_str(RUA_CN_DomainIndicator_t cN_DomainIndicator) -{ - switch (cN_DomainIndicator) { - case RUA_CN_DomainIndicator_cs_domain: - return "IuCS"; - case RUA_CN_DomainIndicator_ps_domain: - return "IuPS"; - default: - return "(unknown-domain)"; - } -} - static int hnbgw_rua_tx(struct hnb_context *ctx, struct msgb *msg) { if (!msg) @@ -371,7 +359,7 @@ static int rua_rx_init_connect(struct msgb *msg, ANY_t *in) context_id = asn1bitstr_to_u24(&ies.context_ID); LOGHNB(hnb, DRUA, LOGL_DEBUG, "RUA %s Connect.req(ctx=0x%x, %s)\n", - cn_domain_indicator_to_str(ies.cN_DomainIndicator), context_id, + ranap_domain_name(ies.cN_DomainIndicator), context_id, ies.establishment_Cause == RUA_Establishment_Cause_emergency_call ? "emergency" : "normal"); rc = rua_to_scu(hnb, ies.cN_DomainIndicator, RUA_ProcedureCode_id_Connect,