diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-10-23 17:29:13 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-10-24 12:36:00 +0200 |
commit | 77d08a67b53fe92856cdec9b3da91a980381d0cc (patch) | |
tree | 8dfc0f5394c662c383b9a1220a12021aab969629 | |
parent | 05bb1c2b2ef02c340d098be50546a0fafaecdb4e (diff) |
osmux_snprintf: Support different types of Osmux frames
Previous implementation handled all types as if they were Osmux AMR
frames. For Dummy frames, we account the padding but we don't care about
the padding content. For Signalling ones, as they are not in the
specification yet, it is better avoid using unespecified fields and
return an error because it's still not known how extra data will be
handled in the input msgb.
Change-Id: I48565472b47c2a0e5db50881fbb005537af8c70d
-rw-r--r-- | src/osmux.c | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/src/osmux.c b/src/osmux.c index cad4c5d..0027a51 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -921,30 +921,44 @@ int osmux_snprintf(char *buf, size_t size, struct msgb *msg) 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); + switch (osmuxh->ft) { + case OSMUX_FT_SIGNAL: + ret = snprintf(buf + offset, remain, "[signal]"); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); return -1; - } + case OSMUX_FT_DUMMY: + case OSMUX_FT_VOICE_AMR: + if (!osmo_amr_ft_valid(osmuxh->amr_ft)) { + LOGP(DLMIB, LOGL_ERROR, "Bad AMR FT %d, skipping\n", + osmuxh->amr_ft); + return -1; + } - payload_len = osmux_get_payload_len(osmuxh); + payload_len = osmux_get_payload_len(osmuxh); - if (msg_len < payload_len) { - LOGP(DLMIB, LOGL_ERROR, - "No room for OSMUX payload: only %d bytes\n", - msg_len); - return -1; - } + if (msg_len < payload_len) { + LOGP(DLMIB, LOGL_ERROR, + "No room for OSMUX payload: only %d bytes\n", + msg_len); + return -1; + } - ret = osmux_snprintf_payload(buf + offset, remain, - osmux_get_payload(osmuxh), - payload_len); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); + if (osmuxh->ft == OSMUX_FT_VOICE_AMR) { + ret = osmux_snprintf_payload(buf + offset, remain, + osmux_get_payload(osmuxh), + payload_len); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); + } - msg_off += payload_len; - msg_len -= payload_len; + msg_off += payload_len; + msg_len -= payload_len; + break; + default: + LOGP(DLMIB, LOGL_ERROR, "Unknown OSMUX ft value %d\n", + osmuxh->ft); + return -1; + } } - return offset; } |