aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-02-12 21:31:46 +0100
committerHarald Welte <laforge@gnumonks.org>2017-02-13 04:09:37 +0100
commit2f41ab10afa12ade80a4183034bdb0c92d4578c8 (patch)
tree48481d10d37cbbfac806804affee6a982bc257f0
parent59c39a480d59cd1af1256209a51fd17ac86c90a3 (diff)
sccp_helpers: Add osmo_sccp_{addr,gt}_dump() functions
They stringify a global title or SCCP address for human consumption Change-Id: I630308aa4519c6e9a260419d37a376aac6a1ce28
-rw-r--r--include/osmocom/sigtran/sccp_helpers.h3
-rw-r--r--src/sccp_helpers.c71
2 files changed, 74 insertions, 0 deletions
diff --git a/include/osmocom/sigtran/sccp_helpers.h b/include/osmocom/sigtran/sccp_helpers.h
index 3384630..968c500 100644
--- a/include/osmocom/sigtran/sccp_helpers.h
+++ b/include/osmocom/sigtran/sccp_helpers.h
@@ -37,3 +37,6 @@ int osmo_sccp_tx_data(struct osmo_sccp_link *link, uint32_t conn_id,
int osmo_sccp_tx_data_msg(struct osmo_sccp_link *link, uint32_t conn_id,
struct msgb *msg);
+
+char *osmo_sccp_gt_dump(const struct osmo_sccp_gt *gt);
+char *osmo_sccp_addr_dump(const struct osmo_sccp_addr *addr);
diff --git a/src/sccp_helpers.c b/src/sccp_helpers.c
index c6248de..1fc257c 100644
--- a/src/sccp_helpers.c
+++ b/src/sccp_helpers.c
@@ -20,6 +20,11 @@
*/
#include <string.h>
+#include <stdbool.h>
+
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
#include <osmocom/sigtran/sccp_sap.h>
#include <osmocom/sigtran/sua.h>
@@ -149,3 +154,69 @@ int osmo_sccp_tx_data_msg(struct osmo_sccp_link *link, uint32_t conn_id,
return rc;
}
+
+static void append_to_buf(char *buf, bool *comma, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ if (*comma == true) {
+ strcat(buf, ",");
+ } else
+ *comma = true;
+ vsprintf(buf+strlen(buf), fmt, ap);
+ va_end(ap);
+}
+
+char *osmo_sccp_gt_dump(const struct osmo_sccp_gt *gt)
+{
+ static char buf[256];
+ bool comma = false;
+
+ buf[0] = '\0';
+
+ if (gt->gti == OSMO_SCCP_GTI_NO_GT) {
+ strcat(buf, "NONE");
+ return buf;
+ }
+ if (gt->gti == OSMO_SCCP_GTI_NAI_ONLY) {
+ return buf;
+ }
+ if (gt->gti == OSMO_SCCP_GTI_TT_ONLY ||
+ gt->gti == OSMO_SCCP_GTI_TT_NPL_ENC ||
+ gt->gti == OSMO_SCCP_GTI_TT_NPL_ENC_NAI)
+ append_to_buf(buf, &comma, "TT=%u", gt->tt);
+
+ if (gt->gti == OSMO_SCCP_GTI_TT_NPL_ENC ||
+ gt->gti == OSMO_SCCP_GTI_TT_NPL_ENC_NAI)
+ append_to_buf(buf, &comma, "NPL=%u", gt->npi);
+
+ if (gt->gti == OSMO_SCCP_GTI_TT_NPL_ENC_NAI)
+ append_to_buf(buf, &comma, "NAI=%u", gt->nai);
+
+ append_to_buf(buf, &comma, "DIG=%s", gt->digits);
+
+ return buf;
+}
+
+char *osmo_sccp_addr_dump(const struct osmo_sccp_addr *addr)
+{
+ static char buf[256];
+ bool comma = false;
+
+ buf[0] = '\0';
+
+ append_to_buf(buf, &comma, "RI=7");
+
+ if (addr->presence & OSMO_SCCP_ADDR_T_PC)
+ append_to_buf(buf, &comma, "PC=%u", addr->pc);
+ if (addr->presence & OSMO_SCCP_ADDR_T_SSN)
+ append_to_buf(buf, &comma, "SSN=%u", addr->ssn);
+ if (addr->presence & OSMO_SCCP_ADDR_T_IPv4)
+ append_to_buf(buf, &comma, "IP=%s", inet_ntoa(addr->ip.v4));
+ append_to_buf(buf, &comma, "GTI=%u", addr->gt.gti);
+ if (addr->presence & OSMO_SCCP_ADDR_T_GT)
+ append_to_buf(buf, &comma, "GT=(%s)", osmo_sccp_gt_dump(&addr->gt));
+
+ return buf;
+}