[PATCH] libosmo-sccp[master]: migrate some generic XUA helpers from sua.c to xua_msg.c

Harald Welte gerrit-no-reply at lists.osmocom.org
Mon Feb 13 14:03:46 UTC 2017


Hello Jenkins Builder, Holger Freyther,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1803

to look at the new patch set (#2).

migrate some generic XUA helpers from sua.c to xua_msg.c

Change-Id: I59e55d21a05b5d770c120da4c17220d5f21d44bd
---
M include/osmocom/sigtran/xua_msg.h
M src/sua.c
M src/xua_msg.c
3 files changed, 60 insertions(+), 50 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/03/1803/2

diff --git a/include/osmocom/sigtran/xua_msg.h b/include/osmocom/sigtran/xua_msg.h
index 9cc8632..bb9486a 100644
--- a/include/osmocom/sigtran/xua_msg.h
+++ b/include/osmocom/sigtran/xua_msg.h
@@ -21,6 +21,8 @@
 
 #include <osmocom/core/linuxlist.h>
 
+#define XUA_HDR(class, type)	((struct xua_common_hdr) { .spare = 0, .msg_class = (class), .msg_type = (type) })
+
 struct msgb;
 
 struct xua_msg {
@@ -51,3 +53,8 @@
 struct msgb *xua_to_msg(const int version, struct xua_msg *msg);
 
 void xua_set_log_area(int log_area);
+
+int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data);
+int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val);
+int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val);
+uint32_t xua_msg_get_u32(struct xua_msg *xua, uint16_t iei);
diff --git a/src/sua.c b/src/sua.c
index 39afef0..8bbaa58 100644
--- a/src/sua.c
+++ b/src/sua.c
@@ -120,56 +120,6 @@
  * Message encoding helper functions
  ***********************************************************************/
 
-#define XUA_HDR(class, type)	((struct xua_common_hdr) { .spare = 0, .msg_class = (class), .msg_type = (type) })
-
-static int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data)
-{
-	uint8_t *cur;
-	unsigned int rest;
-	unsigned int tlv_len = 4 + len + (4 - (len % 4));
-
-	if (msgb_tailroom(msg) < tlv_len)
-		return -ENOMEM;
-
-	/* tag */
-	msgb_put_u16(msg, tag);
-	/* length */
-	msgb_put_u16(msg, len + 4);
-	/* value */
-	cur = msgb_put(msg, len);
-	memcpy(cur, data, len);
-	/* padding */
-	rest = (4 - (len % 4)) & 0x3;
-	if (rest > 0) {
-		cur = msgb_put(msg, rest);
-		memset(cur, 0, rest);
-	}
-
-	return 0;
-}
-
-static int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val)
-{
-	uint32_t val_n = htonl(val);
-
-	return msgb_t16l16vp_put(msg, tag, sizeof(val_n), (uint8_t *)&val_n);
-}
-
-static int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val)
-{
-	uint32_t val_n = htonl(val);
-	return xua_msg_add_data(xua, iei, sizeof(val_n), (uint8_t *) &val_n);
-}
-
-static uint32_t xua_msg_get_u32(struct xua_msg *xua, uint16_t iei)
-{
-	struct xua_msg_part *part = xua_msg_find_tag(xua, iei);
-	uint32_t rc = 0;
-	if (part)
-		rc = ntohl(*(uint32_t *)part->dat);
-	return rc;
-}
-
 static int xua_msg_add_sccp_addr(struct xua_msg *xua, uint16_t iei, const struct osmo_sccp_addr *addr)
 {
 	struct msgb *tmp = msgb_alloc(128, "SCCP Address");
diff --git a/src/xua_msg.c b/src/xua_msg.c
index 0ced1f9..67dd6e2 100644
--- a/src/xua_msg.c
+++ b/src/xua_msg.c
@@ -182,3 +182,56 @@
 {
 	DXUA = log_area;
 }
+
+
+/***********************************************************************
+ * Message encoding helper functions
+ ***********************************************************************/
+
+int msgb_t16l16vp_put(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *data)
+{
+	uint8_t *cur;
+	unsigned int rest;
+	unsigned int tlv_len = 4 + len + (4 - (len % 4));
+
+	if (msgb_tailroom(msg) < tlv_len)
+		return -ENOMEM;
+
+	/* tag */
+	msgb_put_u16(msg, tag);
+	/* length */
+	msgb_put_u16(msg, len + 4);
+	/* value */
+	cur = msgb_put(msg, len);
+	memcpy(cur, data, len);
+	/* padding */
+	rest = (4 - (len % 4)) & 0x3;
+	if (rest > 0) {
+		cur = msgb_put(msg, rest);
+		memset(cur, 0, rest);
+	}
+
+	return 0;
+}
+
+int msgb_t16l16vp_put_u32(struct msgb *msg, uint16_t tag, uint32_t val)
+{
+	uint32_t val_n = htonl(val);
+
+	return msgb_t16l16vp_put(msg, tag, sizeof(val_n), (uint8_t *)&val_n);
+}
+
+int xua_msg_add_u32(struct xua_msg *xua, uint16_t iei, uint32_t val)
+{
+	uint32_t val_n = htonl(val);
+	return xua_msg_add_data(xua, iei, sizeof(val_n), (uint8_t *) &val_n);
+}
+
+uint32_t xua_msg_get_u32(struct xua_msg *xua, uint16_t iei)
+{
+	struct xua_msg_part *part = xua_msg_find_tag(xua, iei);
+	uint32_t rc = 0;
+	if (part)
+		rc = ntohl(*(uint32_t *)part->dat);
+	return rc;
+}

-- 
To view, visit https://gerrit.osmocom.org/1803
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I59e55d21a05b5d770c120da4c17220d5f21d44bd
Gerrit-PatchSet: 2
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder


More information about the gerrit-log mailing list