[PATCH] libosmo-sccp[master]: sua: Parse SUA Global Title (nested in SUA SCCP Addresses)

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

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


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

sua: Parse SUA Global Title (nested in SUA SCCP Addresses)

Change-Id: Id6201362a78f2bc183a27bbc2f19e4de724eb88f
---
M src/sua.c
1 file changed, 45 insertions(+), 1 deletion(-)


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

diff --git a/src/sua.c b/src/sua.c
index 71c7b46..7fe74cb 100644
--- a/src/sua.c
+++ b/src/sua.c
@@ -639,6 +639,48 @@
  * Receiving SUA messsages from SCTP
  ***********************************************************************/
 
+
+/*! \brief Decode SUA Global Title according to RFC3868 3.10.2.3
+ *  \param[out] gt User-allocated structure for decoded output
+ *  \param[in] data binary-encoded data
+ *  \param[in] datalen length of \ref data in octets
+ */
+static int sua_parse_gt(struct osmo_sccp_gt *gt, const uint8_t *data,
+			unsigned int datalen)
+{
+	uint8_t num_digits;
+	uint8_t *out_digits;
+	unsigned int i;
+
+	/* 8 byte header at minimum, plus digits */
+	if (datalen < 8)
+		return -EINVAL;
+
+	/* parse header */
+	gt->gti = data[3];
+	num_digits = data[4];
+	gt->tt = data[5];
+	gt->npi = data[6];
+	gt->nai = data[7];
+
+	/* parse digits */
+	out_digits = gt->digits;
+	for (i = 0; i < datalen-8; i++) {
+		uint8_t byte = data[8+i];
+		*out_digits++ = osmo_bcd2char(byte & 0x0F);
+		if (out_digits - gt->digits >= num_digits)
+			break;
+		*out_digits++ = osmo_bcd2char(byte >> 4);
+		if (out_digits - gt->digits >= num_digits)
+			break;
+	}
+	*out_digits++ = '\0';
+
+	gt->nr_digits = strlen((const char *)gt->digits);
+
+	return 0;
+}
+
 int sua_addr_parse_part(struct osmo_sccp_addr *out,
 			const struct xua_msg_part *param)
 {
@@ -721,7 +763,9 @@
 			out->presence |= OSMO_SCCP_ADDR_T_SSN;
 			break;
 		case SUA_IEI_GT:
-			/* TODO */
+			if (par_datalen < 8)
+				goto subpar_fail;
+			sua_parse_gt(&out->gt, par->data, par_datalen);
 			out->presence |= OSMO_SCCP_ADDR_T_GT;
 			break;
 		case SUA_IEI_IPv4:

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id6201362a78f2bc183a27bbc2f19e4de724eb88f
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