Commit Graph

19 Commits

Author SHA1 Message Date
Pau Espin f136c648fb amr: Add data[0] field to amr_hdr
This allows easily accessing the AMR payload located after the TOC.

Change-Id: I72c0a001bf7ce9a63ac03beef352af177084e644
2022-09-28 19:03:52 +02:00
Alexander Couzens acce44d40f amr: Introduce APIs to convert BE to IuUP/IuFP format
These APIs allow for easy re-formatting of received AMR to forward
between regular RTP and IuUP.

Related: OS#1937
Change-Id: Id2bd32d5f2060abe581730996dc4251381bf7d4f
2022-01-04 14:50:51 +01:00
Alexander Couzens 7abaf006ae export osmo_amr_bits
Change-Id: Ic03653b2a885c5d9419c6c75a718b550fc30b86e
2022-01-02 23:37:23 +01:00
Alexander Chemeris 4752930972 amr: Fix OA<->BWE conversion.
Size of a single AMR frame doesn't always shrink by a byte when
converted from octet-aligned to bandwidth-efficient mode. It does
shrink for AMR modes 2, 3, 4, 6, and 7 but doesn't shrink for
AMR modes 0, 1, 5, and SID frames because we only remove 6 bits.
So old code generated truncated AMR packets for those AMR modes.
This patch fixes the length calculation by properly counting bits.

Proper bit counting is also bringing us one small step closer to
properly handlig multi-frame AMR packets.

Change-Id: I0462e054a0adc9080456f3eeea9cab7c229cdb70
2020-05-16 20:21:48 +00:00
Neels Hofmeyr 8b77ad940a Revert "amr: Fix OA<->BWE conversion."
This reverts commit 002a51e218.

Reason for revert: amr_test fails with sanitizer build:

Sample No.: 6
   bw-efficient:  a7bfc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03fc03f
                  1010011110111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111110000000011111111000000001111111100000000111111
../../../src/libosmo-netif/src/amr.c:63:24: runtime error: index 15 out of bounds for type 'size_t [9]'
../../../src/libosmo-netif/src/amr.c:63:24: runtime error: load of address 0x7f69498e56b8 with insufficient space for an object of type 'size_t'
0x7f69498e56b8: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  5f 00 00 00 00 00 00 00  67 00 00 00 00 00 00 00  76 00 00 00
              ^ 
=================================================================
==489935==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7f69498e56b8 at pc 0x7f69498abec7 bp 0x7ffeafb35330 sp 0x7ffeafb35328
READ of size 8 at 0x7f69498e56b8 thread T0
    #0 0x7f69498abec6 in osmo_amr_bytes ../../../src/libosmo-netif/src/amr.c:63
    #1 0x7f69498ac661 in osmo_amr_bwe_to_oa ../../../src/libosmo-netif/src/amr.c:193
    #2 0x5648b11afb96 in osmo_amr_bwe_to_oa_test ../../../src/libosmo-netif/tests/amr/amr_test.c:134
    #3 0x5648b11af31d in main ../../../src/libosmo-netif/tests/amr/amr_test.c:235
    #4 0x7f6948d5de0a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26e0a)
    #5 0x5648b11af3d9 in _start (/n/s/dev/make/libosmo-netif/tests/amr/amr_test+0x43d9)

0x7f69498e56b8 is located 8 bytes to the left of global variable 'amr_ft_to_bits' defined in '../../../src/libosmo-netif/src/amr.c:32:15' (0x7f69498e56c0) of size 72
0x7f69498e56b8 is located 48 bytes to the right of global variable 'amr_ft_to_bytes' defined in '../../../src/libosmo-netif/src/amr.c:44:15' (0x7f69498e5640) of size 72
SUMMARY: AddressSanitizer: global-buffer-overflow ../../../src/libosmo-netif/src/amr.c:63 in osmo_amr_bytes

Change-Id: I8232521c513722435e71dc90bdbfee10f8f83496
2020-05-14 23:22:54 +00:00
Alexander Chemeris 002a51e218 amr: Fix OA<->BWE conversion.
Size of a single AMR frame doesn't always shrink by a byte when
converted from octet-aligned to bandwidth-efficient mode. It does
shrink for AMR modes 2, 3, 4, 6, and 7 but doesn't shrink for
AMR modes 0, 1, 5, and SID frames because we only remove 6 bits.
So old code generated truncated AMR packets for those AMR modes.
This patch fixes the length calculation by properly counting bits.

Proper bit counting is also bringing us one small step closer to
properly handlig multi-frame AMR packets.

Change-Id: I9fc5fb92e9bada22a47a82fcfb0925e892e50ced
2020-05-14 12:03:42 +00:00
Neels Hofmeyr 63e33ab84c add/clean big-endian packed structs (struct_endianess.py)
Change-Id: If408153af472a41dcea8d6f6aedd22adb16963d5
2020-01-12 13:14:48 +00:00
Neels Hofmeyr c633f54a3c struct amr_header: copy comments to little endian part
I will soon apply struct_endianess.py to this code, and then the comments that
are now only in the big endian part would be lost. Copy them to preserve them.

Change-Id: Ie4279928bd77a5d425d0e7a3c4d58bac3cf0230a
2020-01-07 17:52:49 +01:00
Philipp Maier fa7df87260 AMR: add functions to convert between bw-efficient and octet-aligned
RFC 3267 describes two different AMR frame formats. Octet Aligned and
Bandwidth efficient mode. In Bandwith efficient mode the padding bits,
which are used to align CMR, TOC and payload on octet boundaries are
saved and the fielda are packed directly one after another.

- Add functions to convert from one mode to the other and vice versa.
- Add function to detect in which mode an AMR frame is encoded.

Change-Id: I5b5a0fa644d8dbb1f04f9d7e35312683c7b3d196
Related: SYS#4470
2019-03-07 10:22:22 +01:00
Philipp Maier 0fe9b3664a AMR: add define constants for AMR payload length
AMR uses different payload sizes, those sizes are well defined in RFC
3267. Lets add define constants and replace the magic values with the
define constants.

Also correct the value for AMR_FT_SID in amr_ft_to_bytes from 6 to 5
(39bits / 8 = 4.875 bytes ==> 5 byte, see also RFC 3267, chapter 3.6)

Change-Id: I65b5da920d58015b875d6dcf17aacdc04b58955e
2019-03-01 09:12:20 +01:00
Philipp Maier a8733cb6c7 AMR: add spec reference for AMR frame types
Change-Id: I39a602ae96570c9609680ff67e0946a696091cbe
2019-02-27 12:08:54 +01:00
Holger Hans Peter Freyther 86115434f1 endian: Use the new endian macros for portability
Use the new macros to deal with little/big endian. Im a bit
worried to make this change due the little test coverage in
this module but in case of a typo the elements would not be
defined.
2015-03-22 09:38:36 +01:00
Pablo Neira Ayuso e71cdedcfb amr: make sure the header is packed 2014-04-25 15:02:08 +02:00
Pablo Neira Ayuso 70214a15d1 osmux: further sanity checkings for AMR FT
According to RFC3267, AMR FT upper 9 should be discarded. This patch
adds extra validation to make sure that input RTP traffic encapsulating
AMR payload and OSMUX amr_ft field are OK with regards to that
restriction.
2013-05-24 12:16:49 +02:00
Pablo Neira Ayuso b1f92341c3 amr: add AMR FT SID definition
According to RFC3267, AMR FT 8 is reserved to SID and its size is
8 bytes.
2013-05-24 11:18:40 +02:00
Pablo Neira Ayuso 92601d0a20 osmux: use ft instead of the cmr
The cmr is the requested codec for the other peer, the ft actually
contains the current codec mode. cmr may contain 15 which means
"don't care".
2013-02-12 19:29:42 +01:00
Pablo Neira Ayuso 42915068af src: add function to obtain bytes depending on AMR frame code 2012-07-13 21:12:32 +02:00
Pablo Neira Ayuso c6dceb8cf7 amr: add osmo_amr_get_payload 2012-07-12 13:01:25 +02:00
Pablo Neira Ayuso a359315c8b include: add AMR definitions in amr.h header
As defined by RFC3267 in Octed-Aligned mode.
2012-07-07 17:43:14 +02:00