falconia has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-abis/+/41161?usp=email )
Change subject: trau: add TW-TS-007 packing and unpacking functions
......................................................................
trau: add TW-TS-007 packing and unpacking functions
TW-TS-007 packing and unpacking functions in <osmocom/trau/twts007.h>
are symmetric, as much as feasible, with their CLEARMODE counterparts
in <osmocom/trau/csd_v110.h>, <osmocom/trau/csd_ra2.h> and
<osmocom/trau/csd_raa_prime.h>. This symmetry is intended to aid
implementation of CSD RTP endpoints (TRAU<->RTP functions and IWFs
in the CN) that support both payload formats, and it will also serve
as a building block for dedicated format conversion functions.
Change-Id: Ie81280d2b90f69fbdde9fa968f747a35ea123f79
---
M include/Makefile.am
A include/osmocom/trau/twts007.h
M src/Makefile.am
A src/trau/twts007.c
4 files changed, 150 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/61/41161/1
diff --git a/include/Makefile.am b/include/Makefile.am
index 862292e..7c00ccc 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -33,6 +33,7 @@
osmocom/trau/trau_pcu_ericsson.h \
osmocom/trau/trau_rtp.h \
osmocom/trau/trau_sync.h \
+ osmocom/trau/twts007.h \
$(NULL)
if ENABLE_ORTP
diff --git a/include/osmocom/trau/twts007.h b/include/osmocom/trau/twts007.h
new file mode 100644
index 0000000..f991379
--- /dev/null
+++ b/include/osmocom/trau/twts007.h
@@ -0,0 +1,42 @@
+/*
+ * This header file defines the public API for working with compressed-CSD
+ * RTP format of TW-TS-007:
+ *
+ * https://www.freecalypso.org/specs/tw-ts-007-v010001.txt
+ *
+ * Author: Mychaela N. Falconia <falcon(a)freecalypso.org>, 2025 - however,
+ * Mother Mychaela's contributions are NOT subject to copyright.
+ * No rights reserved, all rights relinquished.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <osmocom/core/bits.h>
+
+/* RTP payload lengths for different modes of compressed CSD */
+#define OSMO_CCSD_PL_LEN_4k8 16 /* TW-TS-007 section 7.2 */
+#define OSMO_CCSD_PL_LEN_9k6 32 /* TW-TS-007 section 7.3 */
+#define OSMO_CCSD_PL_LEN_14k4 37 /* TW-TS-007 section 7.4 */
+
+/* low-level CSD frame packing and unpacking functions */
+
+void osmo_ccsd_pack_v110_frame(uint8_t *out_bytes, const ubit_t *bits_63);
+void osmo_ccsd_pack_atrau_frame(uint8_t *out_bytes, const ubit_t *m_bits,
+ const ubit_t *d_bits, ubit_t atrau_c4,
+ ubit_t atrau_c5);
+
+int osmo_ccsd_unpack_v110_frame(ubit_t *bits_63, const uint8_t *ccsd_bytes);
+int osmo_ccsd_unpack_atrau_frame(ubit_t *m_bits, ubit_t *d_bits,
+ ubit_t *atrau_c4, ubit_t *atrau_c5,
+ const uint8_t *ccsd_bytes);
diff --git a/src/Makefile.am b/src/Makefile.am
index 6683d44..b30ebfc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -60,7 +60,8 @@
trau/trau_frame.c \
trau/trau_pcu_ericsson.c \
trau/trau_sync.c \
- trau/trau_rtp_conv.c
+ trau/trau_rtp_conv.c \
+ trau/twts007.c
if ENABLE_ORTP
libosmotrau_la_SOURCES += trau/osmo_ortp.c
diff --git a/src/trau/twts007.c b/src/trau/twts007.c
new file mode 100644
index 0000000..82614c6
--- /dev/null
+++ b/src/trau/twts007.c
@@ -0,0 +1,105 @@
+/*
+ * This C module contains the implementation of TW-TS-007 compressed CSD
+ * functions defined in <osmocom/trau/twts007.h>.
+ *
+ * Author: Mychaela N. Falconia <falcon(a)freecalypso.org>, 2025 - however,
+ * Mother Mychaela's contributions are NOT subject to copyright.
+ * No rights reserved, all rights relinquished.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+
+#include <osmocom/core/bits.h>
+#include <osmocom/trau/twts007.h>
+
+/*! Pack V.110 frame content (distilled 63-bit form) into compressed form
+ * of TW-TS-007 section 7.1.
+ * \param[out] out_bytes buffer of size 8 bytes
+ * \param[in] bits_63 63-bit distilled V.110 frame
+ */
+void osmo_ccsd_pack_v110_frame(uint8_t *out_bytes, const ubit_t *bits_63)
+{
+ ubit_t bits_64[64];
+
+ bits_64[0] = 1;
+ memcpy(bits_64 + 1, bits_63, 63);
+ osmo_ubit2pbit(out_bytes, bits_64, 64);
+}
+
+/*! Pack A-TRAU frame content (M-bits, D-bits, C4 and C5 metadata flags)
+ * into compressed form of TW-TS-007 section 7.4.
+ * \param[out] out_bytes buffer of size 37 bytes
+ * \param[in] m_bits 2 M-bits associated with this 20 ms CSD frame
+ * \param[in] d_bits 288 user data bits in this 20 ms CSD frame
+ * \param[in] atrau_c4 value to be put into A-TRAU frame bit C4
+ * \param[in] atrau_c5 value to be put into A-TRAU frame bit C5
+ */
+void osmo_ccsd_pack_atrau_frame(uint8_t *out_bytes, const ubit_t *m_bits,
+ const ubit_t *d_bits, ubit_t atrau_c4,
+ ubit_t atrau_c5)
+{
+ uint8_t head_byte;
+
+ head_byte = 0xB0;
+ head_byte |= (atrau_c4 << 3);
+ head_byte |= (atrau_c5 << 2);
+ head_byte |= (m_bits[0] << 1);
+ head_byte |= (m_bits[1] << 0);
+ out_bytes[0] = head_byte;
+ osmo_ubit2pbit(out_bytes + 1, d_bits, 288);
+}
+
+/*! Extract V.110 frame content (distilled 63-bit form) from compressed form
+ * of TW-TS-007 section 7.1.
+ * \param[out] bits_63 buffer of size 63 ubit_t
+ * \param[in] ccsd_bytes 8-octet compressed V.110 frame of TW-TS-007
+ * section 7.1
+ * \returns 0 if compressed V.110 frame is good; negative if it is invalid
+ */
+int osmo_ccsd_unpack_v110_frame(ubit_t *bits_63, const uint8_t *ccsd_bytes)
+{
+ ubit_t bits_64[64];
+
+ osmo_pbit2ubit(bits_64, ccsd_bytes, 64);
+ if (!bits_64[0])
+ return -EINVAL;
+ memcpy(bits_63, bits_64 + 1, 63);
+ return 0;
+}
+
+/*! Extract A-TRAU frame content from compressed form of TW-TS-007 section 7.4.
+ * \param[out] m_bits caller-provided buffer for 2 M-bits
+ * \param[out] d_bits caller-provided buffer for 288 user data bits
+ * \param[out] atrau_c4 return of A-TRAU frame bit C4 (NULL pointer OK)
+ * \param[out] atrau_c5 return of A-TRAU frame bit C5 (NULL pointer OK)
+ * \param[in] ccsd_bytes 37-octet compressed V.110 frame of TW-TS-007
+ * section 7.4
+ * \returns 0 if compressed A-TRAU frame is good; negative if it is invalid
+ */
+int osmo_ccsd_unpack_atrau_frame(ubit_t *m_bits, ubit_t *d_bits,
+ ubit_t *atrau_c4, ubit_t *atrau_c5,
+ const uint8_t *ccsd_bytes)
+{
+ if ((ccsd_bytes[0] & 0xF0) != 0xB0)
+ return -EINVAL;
+ if (atrau_c4)
+ *atrau_c4 = (ccsd_bytes[0] >> 3) & 1;
+ if (atrau_c5)
+ *atrau_c5 = (ccsd_bytes[0] >> 2) & 1;
+ m_bits[0] = (ccsd_bytes[0] >> 1) & 1;
+ m_bits[1] = (ccsd_bytes[0] >> 0) & 1;
+ osmo_pbit2ubit(d_bits, ccsd_bytes + 1, 288);
+ return 0;
+}
--
To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/41161?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Change-Id: Ie81280d2b90f69fbdde9fa968f747a35ea123f79
Gerrit-Change-Number: 41161
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon(a)freecalypso.org>
falconia has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-abis/+/41158?usp=email )
Change subject: trau/clearmode.h: add OSMO_CLEARMODE_20MS definition
......................................................................
trau/clearmode.h: add OSMO_CLEARMODE_20MS definition
RFC4040_RTP_PLEN was previously defined privately in OsmoBTS and
in trau_rtp_conv.c module in this library, but there was no official
definition in any of Osmocom headers. Add <osmocom/trau/clearmode.h>
header with OSMO_CLEARMODE_20MS definition.
Change-Id: I4b2e49b085574336820468dc8cfb8e32377788bf
---
M include/Makefile.am
A include/osmocom/trau/clearmode.h
M src/trau/trau_rtp_conv.c
3 files changed, 38 insertions(+), 16 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/58/41158/1
diff --git a/include/Makefile.am b/include/Makefile.am
index e9820c8..565e3cb 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -24,6 +24,7 @@
osmocom/abis/trau_frame.h \
osmocom/abis/unixsocket_proto.h \
osmocom/abis/version.h \
+ osmocom/trau/clearmode.h \
osmocom/trau/csd_ra2.h \
osmocom/trau/csd_raa_prime.h \
osmocom/trau/tfo_frame.h \
diff --git a/include/osmocom/trau/clearmode.h b/include/osmocom/trau/clearmode.h
new file mode 100644
index 0000000..60fbc5a
--- /dev/null
+++ b/include/osmocom/trau/clearmode.h
@@ -0,0 +1,23 @@
+/*
+ * This header file contains some definitions for CSD in CLEARMODE RTP
+ * representation.
+ *
+ * Author: Mychaela N. Falconia <falcon(a)freecalypso.org>, 2025 - however,
+ * Mother Mychaela's contributions are NOT subject to copyright.
+ * No rights reserved, all rights relinquished.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
+
+/* RFC4040 CLEARMODE RTP payload length for 20 ms as specified in TS 48.103 */
+#define OSMO_CLEARMODE_20MS 160
diff --git a/src/trau/trau_rtp_conv.c b/src/trau/trau_rtp_conv.c
index f2e0022..f670578 100644
--- a/src/trau/trau_rtp_conv.c
+++ b/src/trau/trau_rtp_conv.c
@@ -30,12 +30,10 @@
#include <osmocom/trau/trau_frame.h>
#include <osmocom/trau/trau_rtp.h>
+#include <osmocom/trau/clearmode.h>
#include <osmocom/trau/csd_ra2.h>
#include <osmocom/trau/csd_raa_prime.h>
-/* RFC4040 "clearmode" RTP payload length */
-#define RFC4040_RTP_PLEN 160
-
/* this corresponds to the bit-lengths of the individual codec
* parameters as indicated in Table 1.1 of TS 46.010 */
static const uint8_t gsm_fr_map[] = {
@@ -1304,7 +1302,7 @@
/* function interface preliminaries */
if (tf->type != OSMO_TRAU16_FT_DATA)
return -EINVAL;
- if (out_len < RFC4040_RTP_PLEN)
+ if (out_len < OSMO_CLEARMODE_20MS)
return -ENOSPC;
/* Is it TCH/F9.6 with 16 kbit/s IR,
@@ -1319,7 +1317,7 @@
trau2v110_ir8(out + 80, tf->d_bits + 63 * 2);
}
- return RFC4040_RTP_PLEN;
+ return OSMO_CLEARMODE_20MS;
}
static int trau2rtp_data_hr16(uint8_t *out, size_t out_len,
@@ -1328,7 +1326,7 @@
/* function interface preliminaries */
if (tf->type != OSMO_TRAU16_FT_DATA_HR)
return -EINVAL;
- if (out_len < RFC4040_RTP_PLEN)
+ if (out_len < OSMO_CLEARMODE_20MS)
return -ENOSPC;
/* Note that Osmocom trau_frame decoding and encoding API
@@ -1338,7 +1336,7 @@
trau2v110_ir8(out, tf->d_bits);
trau2v110_ir8(out + 80, tf->d_bits + 63);
- return RFC4040_RTP_PLEN;
+ return OSMO_CLEARMODE_20MS;
}
static int trau2rtp_data_hr8(uint8_t *out, size_t out_len,
@@ -1347,13 +1345,13 @@
/* function interface preliminaries */
if (tf->type != OSMO_TRAU8_DATA)
return -EINVAL;
- if (out_len < RFC4040_RTP_PLEN)
+ if (out_len < OSMO_CLEARMODE_20MS)
return -ENOSPC;
trau2v110_ir8(out, tf->d_bits);
trau2v110_ir8(out + 80, tf->d_bits + 63);
- return RFC4040_RTP_PLEN;
+ return OSMO_CLEARMODE_20MS;
}
static int trau2rtp_edata(uint8_t *out, size_t out_len,
@@ -1362,7 +1360,7 @@
/* function interface preliminaries */
if (tf->type != OSMO_TRAU16_FT_EDATA)
return -EINVAL;
- if (out_len < RFC4040_RTP_PLEN)
+ if (out_len < OSMO_CLEARMODE_20MS)
return -ENOSPC;
/* Per TS 48.020 section 11.1:
@@ -1370,7 +1368,7 @@
* A-TRAU bit C5 comes from E-TRAU bit C6 */
osmo_csd144_to_atrau_ra2(out, tf->m_bits, tf->d_bits, 1, tf->c_bits[5]);
- return RFC4040_RTP_PLEN;
+ return OSMO_CLEARMODE_20MS;
}
/*
@@ -1436,11 +1434,11 @@
{
ubit_t ra_bits[80 * 2];
- if (data_len != RFC4040_RTP_PLEN)
+ if (data_len != OSMO_CLEARMODE_20MS)
goto idle_fill;
/* reverse RA2 first */
- osmo_csd_ra2_8k_unpack(ra_bits, data, RFC4040_RTP_PLEN);
+ osmo_csd_ra2_8k_unpack(ra_bits, data, OSMO_CLEARMODE_20MS);
/* enforce two properly aligned V.110 frames */
if (!check_v110_align(ra_bits))
@@ -1464,11 +1462,11 @@
{
ubit_t ra_bits[80 * 4];
- if (data_len != RFC4040_RTP_PLEN)
+ if (data_len != OSMO_CLEARMODE_20MS)
goto idle_fill;
/* reverse RA2 first */
- osmo_csd_ra2_16k_unpack(ra_bits, data, RFC4040_RTP_PLEN);
+ osmo_csd_ra2_16k_unpack(ra_bits, data, OSMO_CLEARMODE_20MS);
/* enforce 4 properly aligned V.110 frames */
if (!check_v110_align(ra_bits))
@@ -1606,7 +1604,7 @@
/* set C6=0: indicate good reception of TRAU-UL frames */
tf->c_bits[5] = 0;
- if (data_len == RFC4040_RTP_PLEN &&
+ if (data_len == OSMO_CLEARMODE_20MS &&
osmo_csd144_from_atrau_ra2(tf->m_bits, tf->d_bits, &atrau_c4, NULL,
data) >= 0) {
/* We got good A-TRAU input. 3GPP specs define the following
--
To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/41158?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Change-Id: I4b2e49b085574336820468dc8cfb8e32377788bf
Gerrit-Change-Number: 41158
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon(a)freecalypso.org>
falconia has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-abis/+/41159?usp=email )
Change subject: trau: factor out V.110 frame conversion functions
......................................................................
trau: factor out V.110 frame conversion functions
Implementation of CSD conversion between TRAU frames and CLEARMODE
inside osmo_trau2rtp() and osmo_rtp2trau() contains lower-level
functions for conversion of individual V.110 frames and for alignment
checking. Factor these functions out into API, as they are useful
for other applications besides TRAU<->RTP conversion:
* Compression and decompression functions that convert between
standard (but inefficient) CLEARMODE and compressed-CSD RTP format
of TW-TS-007;
* Implementations of IWFs that terminate CSD RTP streams at the CN
and support both CLEARMODE and TW-TS-007.
Change-Id: I3f51254b4b985a0f8499c375b61069ca24f77ae8
---
M include/Makefile.am
A include/osmocom/trau/csd_v110.h
M src/Makefile.am
A src/trau/csd_v110.c
4 files changed, 160 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/59/41159/1
diff --git a/include/Makefile.am b/include/Makefile.am
index 565e3cb..862292e 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -27,6 +27,7 @@
osmocom/trau/clearmode.h \
osmocom/trau/csd_ra2.h \
osmocom/trau/csd_raa_prime.h \
+ osmocom/trau/csd_v110.h \
osmocom/trau/tfo_frame.h \
osmocom/trau/trau_frame.h \
osmocom/trau/trau_pcu_ericsson.h \
diff --git a/include/osmocom/trau/csd_v110.h b/include/osmocom/trau/csd_v110.h
new file mode 100644
index 0000000..05d4ed5
--- /dev/null
+++ b/include/osmocom/trau/csd_v110.h
@@ -0,0 +1,40 @@
+/*
+ * This header file defines the public API for some helper functions that
+ * work with CSD V.110 frames represented in the standard 64 kbit/s CLEARMODE
+ * format of 3GPP TS 48.103, _without_ compression per TW-TS-007, but _with_
+ * Osmocom-introduced constraint that the pair or quadruple of V.110 frames
+ * in RA2 encoding has to be naturally aligned within each 20 ms RTP packet.
+ *
+ * Author: Mychaela N. Falconia <falcon(a)freecalypso.org>, 2025 - however,
+ * Mother Mychaela's contributions are NOT subject to copyright.
+ * No rights reserved, all rights relinquished.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <osmocom/core/bits.h>
+
+/* conversion from distilled 63-bit format (as used in TRAU frames) to full
+ * 80-bit V.110 format, with or without RA2. */
+
+void osmo_csd_63bits_to_v110_bits(ubit_t *out, const ubit_t *in);
+void osmo_csd_63bits_to_v110_ir8(uint8_t *out, const ubit_t *in);
+void osmo_csd_63bits_to_v110_ir16(uint8_t *out, const ubit_t *in);
+
+/* functions to verify V.110 frame alignment after RA2 decoding, and to convert
+ * to our distilled 63-bit format. */
+
+bool osmo_csd_check_v110_align(const ubit_t *ra_bits);
+void osmo_csd_v110_to_63bits(ubit_t *out, const ubit_t *ra_bits);
diff --git a/src/Makefile.am b/src/Makefile.am
index fc5b59b..6683d44 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,6 +53,7 @@
$(NULL)
libosmotrau_la_LIBADD = $(COMMONLIBS) $(LIBOSMOCODEC_LIBS) $(ORTP_LIBS)
libosmotrau_la_SOURCES = trau/csd_ra2.c \
+ trau/csd_v110.c \
trau/raa_prime_decode.c \
trau/raa_prime_encode.c \
trau/tfo_frame.c \
diff --git a/src/trau/csd_v110.c b/src/trau/csd_v110.c
new file mode 100644
index 0000000..431073c
--- /dev/null
+++ b/src/trau/csd_v110.c
@@ -0,0 +1,118 @@
+/*
+ * This C module contains the implementation of CSD V.110 helper functions
+ * for CLEARMODE defined in <osmocom/trau/csd_v110.h>.
+ *
+ * Author: Mychaela N. Falconia <falcon(a)freecalypso.org>, 2025 - however,
+ * Mother Mychaela's contributions are NOT subject to copyright.
+ * No rights reserved, all rights relinquished.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include <osmocom/core/bits.h>
+#include <osmocom/trau/csd_ra2.h>
+#include <osmocom/trau/csd_v110.h>
+
+/*! Convert V.110 frame from distilled 63-bit form (as it appears in TRAU
+ * frames) to full 80-bit form by adding sync pattern bits.
+ * \param[out] out buffer of size 80 ubit_t
+ * \param[in] in 63-bit distilled V.110 frame
+ */
+void osmo_csd_63bits_to_v110_bits(ubit_t *out, const ubit_t *in)
+{
+ int i;
+
+ /* the first 8 bits are sync zeros */
+ memset(out, 0, 8);
+ out += 8;
+ /* for the rest, we have to expand 63 bits into 72 */
+ for (i = 0; i < 9; i++) {
+ *out++ = 1;
+ memcpy(out, in, 7);
+ in += 7;
+ out += 7;
+ }
+}
+
+/*! Convert V.110 frame from distilled 63-bit form (as it appears in TRAU
+ * frames) to external octet form (RA2 with 8 kbit/s IR) form by adding
+ * sync pattern bits and applying RA2.
+ * \param[out] out buffer of size 80 octets
+ * \param[in] in 63-bit distilled V.110 frame
+ */
+void osmo_csd_63bits_to_v110_ir8(uint8_t *out, const ubit_t *in)
+{
+ ubit_t ra_bits[80];
+
+ osmo_csd_63bits_to_v110_bits(ra_bits, in);
+ /* RA2: 1 bit per output byte */
+ osmo_csd_ra2_8k_pack(out, ra_bits, 80);
+}
+
+/*! Convert V.110 frame from distilled 63-bit form (as it appears in TRAU
+ * frames) to external octet form (RA2 with 16 kbit/s IR) form by adding
+ * sync pattern bits and applying RA2.
+ * \param[out] out buffer of size 40 octets
+ * \param[in] in 63-bit distilled V.110 frame
+ */
+void osmo_csd_63bits_to_v110_ir16(uint8_t *out, const ubit_t *in)
+{
+ ubit_t ra_bits[80];
+
+ osmo_csd_63bits_to_v110_bits(ra_bits, in);
+ /* RA2: 2 bits per output byte */
+ osmo_csd_ra2_16k_pack(out, ra_bits, 40);
+}
+
+/*! Check alignment of unpacked 80-bit V.110 frame.
+ * \param[in] ra_bits candidate V.110 frame in standard 80-bit form
+ * \returns true if V.110 alignment pattern is correct, false otherwise
+ */
+bool osmo_csd_check_v110_align(const ubit_t *ra_bits)
+{
+ int i;
+
+ for (i = 0; i < 8; i++) {
+ if (ra_bits[i])
+ return false;
+ }
+ for (i = 1; i < 10; i++) {
+ if (!ra_bits[i * 8])
+ return false;
+ }
+ return true;
+}
+
+/*! Convert V.110 frame from standard 80-bit form (unpacked) to
+ * our distilled 63-bit form (as it appears in TRAU frames).
+ * \param[out] out buffer of size 63 ubit_t
+ * \param[in] in 80-bit standard V.110 frame
+ *
+ * This function ignores all 17 sync pattern bits and assumes that the
+ * V.110 frame is correctly aligned. Therefore, this function should
+ * be called after osmo_csd_check_v110_align().
+ */
+void osmo_csd_v110_to_63bits(ubit_t *out, const ubit_t *ra_bits)
+{
+ memcpy(out, ra_bits + 9, 7);
+ memcpy(out + 7, ra_bits + 17, 7);
+ memcpy(out + 14, ra_bits + 25, 7);
+ memcpy(out + 21, ra_bits + 33, 7);
+ memcpy(out + 28, ra_bits + 41, 7);
+ memcpy(out + 35, ra_bits + 49, 7);
+ memcpy(out + 42, ra_bits + 57, 7);
+ memcpy(out + 49, ra_bits + 65, 7);
+ memcpy(out + 56, ra_bits + 73, 7);
+}
--
To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/41159?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Change-Id: I3f51254b4b985a0f8499c375b61069ca24f77ae8
Gerrit-Change-Number: 41159
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon(a)freecalypso.org>