lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/38948?usp=email )
Change subject: gsm23.003: add RNC Id ......................................................................
gsm23.003: add RNC Id
The RNC is similar to the GUMMEI, but for 3G.
Change-Id: I0768c99b4c42b0948e7574d05b70e1b7bdb8a55a --- M include/osmocom/gsm/gsm23003.h M src/gsm/gsm23003.c M src/gsm/libosmogsm.map 3 files changed, 70 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/48/38948/1
diff --git a/include/osmocom/gsm/gsm23003.h b/include/osmocom/gsm/gsm23003.h index 8b9bcfb..3e203a8 100644 --- a/include/osmocom/gsm/gsm23003.h +++ b/include/osmocom/gsm/gsm23003.h @@ -55,6 +55,12 @@ uint16_t ci; };
+/* 12.4 */ +struct osmo_rnc_id { + struct osmo_plmn_id plmn ; + uint16_t rnc_id; +}; + /* 12.5 */ struct osmo_service_area_id { struct osmo_location_area_id lai; @@ -137,6 +143,9 @@ const char *osmo_cgi_ps_name2(const struct osmo_cell_global_id_ps *cgi_ps); char *osmo_cgi_ps_name_buf(char *buf, size_t buf_len, const struct osmo_cell_global_id_ps *cgi_ps); char *osmo_cgi_ps_name_c(const void *ctx, const struct osmo_cell_global_id_ps *cgi_ps); +const char *osmo_rnc_id_name(const struct osmo_rnc_id *rnc_id); +char *osmo_rnc_id_name_buf(char *buf, size_t buf_len, const struct osmo_rnc_id *rnc_id); +char *osmo_rnc_id_name_c(const void *ctx, const struct osmo_rnc_id *rnc_id); const char *osmo_sai_name(const struct osmo_service_area_id *sai); const char *osmo_sai_name2(const struct osmo_service_area_id *sai); char *osmo_sai_name_buf(char *buf, size_t buf_len, const struct osmo_service_area_id *sai); @@ -167,6 +176,7 @@ int osmo_rai_cmp(const struct osmo_routing_area_id *a, const struct osmo_routing_area_id *b); int osmo_cgi_cmp(const struct osmo_cell_global_id *a, const struct osmo_cell_global_id *b); int osmo_cgi_ps_cmp(const struct osmo_cell_global_id_ps *a, const struct osmo_cell_global_id_ps *b); +int osmo_rnc_id_cmp(const struct osmo_rnc_id *a, const struct osmo_rnc_id *b); int osmo_mme_id_cmp(const struct osmo_mme_id *a, const struct osmo_mme_id *b); int osmo_gummei_cmp(const struct osmo_gummei *a, const struct osmo_gummei *b);
diff --git a/src/gsm/gsm23003.c b/src/gsm/gsm23003.c index 0f4c301..b0bac93 100644 --- a/src/gsm/gsm23003.c +++ b/src/gsm/gsm23003.c @@ -357,6 +357,44 @@ return osmo_cgi_ps_name_buf(buf, sizeof(buf), cgi_ps); }
+/*! Return string representation of RNC in caller-provided output buffer. + * \param[out] buf pointer to caller-provided output buffer + * \param[in] buf_len size of buf in bytes + * \param[in] rnc RNC to be stringified + * \returns buf + */ +char *osmo_rnc_id_name_buf(char *buf, size_t buf_len, const struct osmo_rnc_id *rnc) +{ + char plmn[16]; + snprintf(buf, buf_len, "%s-%d", osmo_plmn_name_buf(plmn, sizeof(plmn), &rnc->plmn), + rnc->rnc_id); + return buf; +} + +/*! Return string representation of RNC in static output buffer. + * \param[in] rnc RNC to be stringified + * \returns pointer to static output buffer + */ +const char *osmo_rnc_id_name(const struct osmo_rnc_id *rnc) +{ + static __thread char buf[32]; + return osmo_rnc_id_name_buf(buf, sizeof(buf), rnc); +} + +/*! Return string representation of RNC in static output buffer. + * \param[out] buf pointer to caller-provided output buffer + * \param[in] buf_len size of buf in bytes + * \param[in] rnc RNC to be stringified + * \returns pointer to static output buffer + */ +char *osmo_rnc_id_name_c(const void *ctx, const struct osmo_rnc_id *rnc) +{ + char *buf = talloc_size(ctx, 32); + if (!buf) + return NULL; + return osmo_rnc_id_name_buf(buf, 32, rnc); +} + /*! Return MCC-MNC-LAC-RAC-CI as string, in a talloc-allocated output buffer. * \param[in] ctx talloc context from which to allocate output buffer * \param[in] cgi_ps CGI-PS to encode. @@ -656,6 +694,24 @@ return 0; }
+/* Compare two RNC Ids + * The order of comparison is PLMN, RNCId. + * \param a[in] "Left" side RNC Id. + * \param b[in] "Right" side RNC Id. + * \returns 0 if the RNC Ids are equal, -1 if a < b, 1 if a > b. */ +int osmo_rnc_id_cmp(const struct osmo_rnc_id *a, const struct osmo_rnc_id *b) +{ + int rc = osmo_plmn_cmp(&a->plmn, &b->plmn); + if (rc) + return rc; + + if (a->rnc_id < b->rnc_id) + return -1; + if (a->rnc_id > b->rnc_id) + return 1; + return 0; +} + /* Compare two MME Ids * The order of comparison is MME GroupId, MME Code. * \param a[in] "Left" side MME Id. diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map index 7c78347..78e0385 100644 --- a/src/gsm/libosmogsm.map +++ b/src/gsm/libosmogsm.map @@ -500,6 +500,10 @@ osmo_cgi_ps_name_buf; osmo_cgi_ps_name_c; osmo_cgi_ps_name2; +osmo_rnc_id_name; +osmo_rnc_id_name_buf; +osmo_rnc_id_name_c; +osmo_rnc_id_cmp; osmo_gummei_name; osmo_gummei_name_buf; osmo_gummei_name_c;