laforge submitted this change.

View Change



3 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.

Approvals: pespin: Looks good to me, but someone else must approve fixeria: Looks good to me, approved Jenkins Builder: Verified
CSD RTP: verify alignment of V.110 frames

Since the beginning of CSD implementation, OsmoBTS has operated
with an implicit (unstated) policy that V.110 frames must be
perfectly aligned within received clearmode RTP packets - a requirement
which is NOT set anywhere in TS 48.103 or any of the other specs
it references. This design policy is sensible from the standpoint
of implementation complexity (both OsmoBTS and osmo_trau2rtp emit
such perfectly aligned packets; if someone is building a gateway
between an Osmocom GSM network and ISDN-style external networks,
that gateway can act as the aligner), but it should be explicit
rather than implicit.

Check V.110 frame alignment in received clearmode RTP packets,
and reject packets that fail this alignment check.

Change-Id: Icd704dc7fa02e60074efc8a29ad7e42ebdf63783
---
M src/common/csd_v110.c
1 file changed, 20 insertions(+), 0 deletions(-)

diff --git a/src/common/csd_v110.c b/src/common/csd_v110.c
index cbbb83b..b2d2b42 100644
--- a/src/common/csd_v110.c
+++ b/src/common/csd_v110.c
@@ -20,6 +20,7 @@
*/

#include <stdint.h>
+#include <stdbool.h>
#include <errno.h>

#include <osmocom/core/bits.h>
@@ -150,6 +151,20 @@
return RFC4040_RTP_PLEN;
}

+static bool check_v110_align(const ubit_t *ra_bits)
+{
+ int i;
+ ubit_t bit0 = 0, bit1 = 1;
+
+ /* The weird code structure is for performance optimization,
+ * to avoid conditionals inside loops. */
+ for (i = 0; i < 8; i++)
+ bit0 |= ra_bits[i];
+ for (i = 1; i < 10; i++)
+ bit1 &= ra_bits[i * 8];
+ return (bit0 == 0) && (bit1 == 1);
+}
+
int csd_v110_rtp_decode(const struct gsm_lchan *lchan, uint8_t *data,
const uint8_t *rtp, size_t rtp_len)
{
@@ -181,6 +196,11 @@
for (unsigned int i = 0; i < desc->num_blocks; i++) {
struct osmo_v110_decoded_frame df;

+ /* We require our RTP input to consist of aligned V.110
+ * frames. If we get misaligned input, let's catch it
+ * explicitly, rather than send garbage downstream. */
+ if (!check_v110_align(&ra_bits[i * 80]))
+ return -EINVAL;
/* convert a V.110 80-bit frame to a V.110 36-/60-bit frame */
osmo_v110_decode_frame(&df, &ra_bits[i * 80], 80);
if (desc->num_bits == 60)

To view, visit change 38555. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: Icd704dc7fa02e60074efc8a29ad7e42ebdf63783
Gerrit-Change-Number: 38555
Gerrit-PatchSet: 4
Gerrit-Owner: falconia <falcon@freecalypso.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: laforge <laforge@osmocom.org>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>