[PATCH] libosmo-netif[master]: osmux_snprintf: Split logic parsing osmux header and AMR pay...

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Mon Oct 23 15:43:19 UTC 2017


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

osmux_snprintf: Split logic parsing osmux header and AMR payload

The current code still expects to parse only AMR osmux frames, but that
will be fixed in following patches.

Change-Id: Ic2f4d1d3cc88af912bb43c8ecd90eacc6ff7190f
---
M src/osmux.c
1 file changed, 13 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/85/4385/1

diff --git a/src/osmux.c b/src/osmux.c
index 7290d99..cad4c5d 100644
--- a/src/osmux.c
+++ b/src/osmux.c
@@ -896,10 +896,11 @@
 int osmux_snprintf(char *buf, size_t size, struct msgb *msg)
 {
 	unsigned int remain = size;
-	int this_len, msg_off = 0;
+	unsigned int msg_off = 0;
 	struct osmux_hdr *osmuxh;
 	unsigned int offset = 0;
 	int msg_len = msg->len;
+	uint32_t payload_len;
 	int ret;
 
 	if (size)
@@ -914,20 +915,21 @@
 		}
 		osmuxh = (struct osmux_hdr *)((uint8_t *)msg->data + msg_off);
 
+		ret = osmux_snprintf_header(buf + offset, remain, osmuxh);
+		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+
+		msg_off += sizeof(struct osmux_hdr);
+		msg_len -= sizeof(struct osmux_hdr);
+
 		if (!osmo_amr_ft_valid(osmuxh->amr_ft)) {
 			LOGP(DLMIB, LOGL_ERROR, "Bad AMR FT %d, skipping\n",
 			     osmuxh->amr_ft);
 			return -1;
 		}
 
-		ret = osmux_snprintf_header(buf + offset, remain, osmuxh);
-		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+		payload_len = osmux_get_payload_len(osmuxh);
 
-		this_len = sizeof(struct osmux_hdr) +
-			   osmux_get_payload_len(osmuxh);
-		msg_off += this_len;
-
-		if (msg_len < this_len) {
+		if (msg_len < payload_len) {
 			LOGP(DLMIB, LOGL_ERROR,
 			     "No room for OSMUX payload: only %d bytes\n",
 			     msg_len);
@@ -936,10 +938,11 @@
 
 		ret = osmux_snprintf_payload(buf + offset, remain,
 					     osmux_get_payload(osmuxh),
-					     osmux_get_payload_len(osmuxh));
+					     payload_len);
 		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
-		msg_len -= this_len;
+		msg_off += payload_len;
+		msg_len -= payload_len;
 	}
 
 	return offset;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic2f4d1d3cc88af912bb43c8ecd90eacc6ff7190f
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>


More information about the gerrit-log mailing list