[PATCH] libosmo-sccp[master]: sua: make SUA address parsing available to other code within...

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Feb 15 23:05:56 UTC 2017


Review at  https://gerrit.osmocom.org/1832

sua: make SUA address parsing available to other code within library

Change-Id: Id824ce1000abbb06592e8edda9c2896ac7d0efb3
---
M src/sua.c
A src/xua_internal.h
2 files changed, 28 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/32/1832/1

diff --git a/src/sua.c b/src/sua.c
index 36e31fd..fac3de1 100644
--- a/src/sua.c
+++ b/src/sua.c
@@ -639,11 +639,9 @@
  * Receiving SUA messsages from SCTP
  ***********************************************************************/
 
-static int sua_parse_addr(struct osmo_sccp_addr *out,
-			  struct xua_msg *xua,
-			  uint16_t iei)
+int sua_addr_parse_part(struct osmo_sccp_addr *out,
+			const struct xua_msg_part *param)
 {
-	const struct xua_msg_part *param = xua_msg_find_tag(xua, iei);
 	const struct xua_parameter_hdr *par;
 	uint16_t ri;
 	uint16_t ai;
@@ -651,16 +649,13 @@
 	uint16_t par_tag, par_len, par_datalen;
 	uint32_t *p32;
 
-	if (!param)
-		return -ENODEV;
-
-	LOGP(DSUA, LOGL_DEBUG, "sua_parse_addr(IEI=%d) (%d) %s\n",
-	     iei, param->len,
+	LOGP(DSUA, LOGL_DEBUG, "%s(IEI=%d) (%d) %s\n", __func__,
+	     param->tag, param->len,
 	     osmo_hexdump(param->dat, param->len));
 
 	if (param->len < 4) {
 		LOGP(DSUA, LOGL_ERROR, "SUA IEI %d: invalid address length: %d\n",
-		     iei, param->len);
+		     param->tag, param->len);
 		return -EINVAL;
 	}
 
@@ -683,13 +678,13 @@
 	case SUA_RI_HOST:
 	default:
 		LOGP(DSUA, LOGL_ERROR, "SUA IEI %d: Routing Indicator not supported yet: %d\n",
-		     iei, ri);
+		     param->tag, ri);
 		return -ENOTSUP;
 	}
 
 	if (ai != 7) {
 		LOGP(DSUA, LOGL_ERROR, "SUA IEI %d: Address Indicator not supported yet: %x\n",
-		     iei, ai);
+		     param->tag, ai);
 		return -ENOTSUP;
 	}
 
@@ -708,7 +703,7 @@
 		par_datalen = par_len - sizeof(*par);
 
 		LOGP(DSUA, LOGL_DEBUG, "SUA IEI %hu pos %hu/%hu: subpart tag %hu, len %hu\n",
-		     iei, pos, param->len, par->tag, par->len);
+		     param->tag, pos, param->len, par->tag, par->len);
 
 		switch (par_tag) {
 		case SUA_IEI_PC:
@@ -731,7 +726,7 @@
 			break;
 		default:
 			LOGP(DSUA, LOGL_ERROR, "SUA IEI %d: Unknown subpart tag %hd\n",
-			     iei, par_tag);
+			     param->tag, par_tag);
 			goto subpar_fail;
 		}
 
@@ -742,8 +737,17 @@
 
 subpar_fail:
 	LOGP(DSUA, LOGL_ERROR, "Failed to parse subparts of address IEI=%d\n",
-	     iei);
+	     param->tag);
 	return -EINVAL;
+}
+
+int sua_addr_parse(struct osmo_sccp_addr *out, struct xua_msg *xua, uint16_t iei)
+{
+	const struct xua_msg_part *param = xua_msg_find_tag(xua, iei);
+	if (!param)
+		return -ENODEV;
+
+	return sua_addr_parse_part(out, param);
 }
 
 static int sua_rx_cldt(struct osmo_sccp_link *link, struct xua_msg *xua)
@@ -760,8 +764,8 @@
 	osmo_prim_init(&prim->oph, SCCP_SAP_USER,
 			OSMO_SCU_PRIM_N_UNITDATA,
 			PRIM_OP_INDICATION, upmsg);
-	sua_parse_addr(&param->called_addr, xua, SUA_IEI_DEST_ADDR);
-	sua_parse_addr(&param->calling_addr, xua, SUA_IEI_SRC_ADDR);
+	sua_addr_parse(&param->called_addr, xua, SUA_IEI_DEST_ADDR);
+	sua_addr_parse(&param->calling_addr, xua, SUA_IEI_SRC_ADDR);
 	param->in_sequence_control = xua_msg_get_u32(xua, SUA_IEI_SEQ_CTRL);
 	protocol_class = xua_msg_get_u32(xua, SUA_IEI_PROTO_CLASS);
 	param->return_option = protocol_class & 0x80;
@@ -810,8 +814,8 @@
 
 	/* fill conn */
 	conn = conn_create(link);
-	sua_parse_addr(&conn->called_addr, xua, SUA_IEI_DEST_ADDR);
-	sua_parse_addr(&conn->calling_addr, xua, SUA_IEI_SRC_ADDR);
+	sua_addr_parse(&conn->called_addr, xua, SUA_IEI_DEST_ADDR);
+	sua_addr_parse(&conn->calling_addr, xua, SUA_IEI_SRC_ADDR);
 	conn->remote_ref = xua_msg_get_u32(xua, SUA_IEI_SRC_REF);
 
 	/* fill primitive */
diff --git a/src/xua_internal.h b/src/xua_internal.h
new file mode 100644
index 0000000..8c9838e
--- /dev/null
+++ b/src/xua_internal.h
@@ -0,0 +1,5 @@
+#pragma once
+
+int sua_addr_parse_part(struct osmo_sccp_addr *out,
+			const struct xua_msg_part *param);
+int sua_addr_parse(struct osmo_sccp_addr *out, struct xua_msg *xua, uint16_t iei);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id824ce1000abbb06592e8edda9c2896ac7d0efb3
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>


More information about the gerrit-log mailing list