From 5ec0cf5475a7b31efa3b122f53e6c2a0e1908c20 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 15 Jan 2019 16:37:09 +0100 Subject: LCLS: add string dump helpers Add functions to dump LCLS (without GCR) and GCR. Dumping entire struct results in inconveniently long string hence the separate functions. Both use talloc functions so they expect caller to take care of providing proper allocation context and freeing memory. Change-Id: Ic3609224c8f3282d667e75f68bc20327e36eb9e6 --- src/gsm/gsm0808_utils.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/gsm/gsm29205.c | 3 +++ src/gsm/libosmogsm.map | 2 ++ 3 files changed, 45 insertions(+) (limited to 'src/gsm') diff --git a/src/gsm/gsm0808_utils.c b/src/gsm/gsm0808_utils.c index 54ec19c2..606899e8 100644 --- a/src/gsm/gsm0808_utils.c +++ b/src/gsm/gsm0808_utils.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #define IP_V4_ADDR_LEN 4 @@ -591,6 +592,45 @@ int gsm0808_dec_lcls(struct osmo_lcls *lcls, const struct tlv_parsed *tp) return ret; } +static char dbuf[256]; + +/*! Dump LCLS parameters (GCR excluded) into string for printing. + * \param[in] lcls pointer to the struct to print. + * \returns string representation of LCLS or NULL on error. */ +char *osmo_lcls_dump(const struct osmo_lcls *lcls) +{ + struct osmo_strbuf s = { .buf = dbuf, .len = 256 }; + + if (!lcls) + return NULL; + + OSMO_STRBUF_PRINTF(s, "LCLS Config: %s, Control: %s, Correlation-Needed: %u", + gsm0808_lcls_config_name(lcls->config), + gsm0808_lcls_control_name(lcls->control), + lcls->corr_needed); + + return dbuf; +} + +/*! Dump GCR struct into string for printing. + * \param[in] lcls pointer to the struct to print. + * \returns string representation of GCR or NULL on error. */ +char *osmo_gcr_dump(const struct osmo_lcls *lcls) +{ + struct osmo_strbuf s = { .buf = dbuf, .len = 256 }; + + if (!lcls) + return NULL; + + if (lcls->gcr_available) { + OSMO_STRBUF_PRINTF(s, "GCR NetID 0x%s, ", osmo_hexdump_nospc(lcls->gcr.net, lcls->gcr.net_len)); + /* osmo_hexdump() uses static buffers so we can't call it twice withing the same parameter list */ + OSMO_STRBUF_PRINTF(s, "Node 0x%x, CallRefID 0x%s", lcls->gcr.node, osmo_hexdump_nospc(lcls->gcr.cr, 5)); + } + + return dbuf; +} + /*! Encode TS 08.08 Encryption Information IE * \param[out] msg Message Buffer to which IE is to be appended * \param[in] ei Encryption Information to be encoded diff --git a/src/gsm/gsm29205.c b/src/gsm/gsm29205.c index 0d344688..6ceb8ee4 100644 --- a/src/gsm/gsm29205.c +++ b/src/gsm/gsm29205.c @@ -20,9 +20,12 @@ * */ +#include "config.h" + #include #include #include +#include #include #include diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map index 48757a7b..2d47d7a7 100644 --- a/src/gsm/libosmogsm.map +++ b/src/gsm/libosmogsm.map @@ -247,6 +247,8 @@ gsm29118_create_service_abort_req; osmo_enc_gcr; osmo_dec_gcr; osmo_gcr_eq; +osmo_gcr_dump; +osmo_lcls_dump; gsm0858_rsl_ul_meas_enc; -- cgit v1.2.3