neels has submitted this change. (
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36891?usp=email )
Change subject: umts_cell_id: add umts_cell_id_to_str_buf()
......................................................................
umts_cell_id: add umts_cell_id_to_str_buf()
Prepare for umts_cell_id_test.c: allow testing the to_str conversion
without using talloc.
Change-Id: I3cc0169593c73c2e658637e4116ddd578f83df6d
---
M include/osmocom/hnbgw/hnbgw.h
M src/osmo-hnbgw/hnbgw.c
2 files changed, 26 insertions(+), 3 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
osmith: Looks good to me, but someone else must approve
diff --git a/include/osmocom/hnbgw/hnbgw.h b/include/osmocom/hnbgw/hnbgw.h
index 2c7e014..87844f4 100644
--- a/include/osmocom/hnbgw/hnbgw.h
+++ b/include/osmocom/hnbgw/hnbgw.h
@@ -173,6 +173,8 @@
uint16_t sac; /*!< Service Area Code */
uint32_t cid; /*!< Cell ID */
};
+int umts_cell_id_to_str_buf(char *buf, size_t buflen, const struct umts_cell_id *ucid);
+char *umts_cell_id_to_str_c(void *ctx, const struct umts_cell_id *ucid);
const char *umts_cell_id_to_str(const struct umts_cell_id *ucid);
int umts_cell_id_from_str(struct umts_cell_id *ucid, const char *instr);
uint32_t umts_cell_id_hash(const struct umts_cell_id *ucid);
diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c
index c41fb54..4f3fafa 100644
--- a/src/osmo-hnbgw/hnbgw.c
+++ b/src/osmo-hnbgw/hnbgw.c
@@ -232,15 +232,24 @@
return ctx;
}
-const char *umts_cell_id_to_str(const struct umts_cell_id *ucid)
+int umts_cell_id_to_str_buf(char *buf, size_t buflen, const struct umts_cell_id *ucid)
{
const char *fmtstr = "%03u-%02u-L%u-R%u-S%u-C%u";
if (g_hnbgw->config.plmn.mnc_3_digits)
fmtstr = "%03u-%03u-L%u-R%u-S%u-C%u";
+ return snprintf(buf, buflen, fmtstr, ucid->mcc, ucid->mnc, ucid->lac,
ucid->rac,
+ ucid->sac, ucid->cid);
+}
- return talloc_asprintf(OTC_SELECT, fmtstr, ucid->mcc, ucid->mnc, ucid->lac,
ucid->rac,
- ucid->sac, ucid->cid);
+char *umts_cell_id_to_str_c(void *ctx, const struct umts_cell_id *ucid)
+{
+ OSMO_NAME_C_IMPL(ctx, 64, "ERROR", umts_cell_id_to_str_buf, ucid)
+}
+
+const char *umts_cell_id_to_str(const struct umts_cell_id *ucid)
+{
+ return umts_cell_id_to_str_c(OTC_SELECT, ucid);
}
/* Useful to index a hash table by struct umts_cell_id. */
--
To view, visit
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36891?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: I3cc0169593c73c2e658637e4116ddd578f83df6d
Gerrit-Change-Number: 36891
Gerrit-PatchSet: 4
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-MessageType: merged