Commit Graph

128 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
Pau Espin 668c804197 stream: Provide caller with SCTP flags during osmo_stream_*_recv()
The user may want to check the flags in order to know if the content
pointed at by msgb is an sctp_notification structure, and not in-band
data.
This is useful for the user in order to gain connection state such as
SCTP RESET notification, which means the client reconnected reusing the
same socket, loosing all higher layers state.

The MSG_NOTIFICATION from netinet/sctp.h is not reused, and instead an
osmocom specific flag (and bitmask) is used. This is done in order to
fit the flags in one byte, since for instance MSG_NOTIFICATION requires
2 bytes in my system (0x8000).

Related: SYS#6113
Change-Id: I0ee94846a15a23950b9d70eaaef1251267296bdd
2022-09-19 14:50:34 +02:00
Pau Espin 95d57c1803 osmux: Allow the user to alloc msgbs used to provide generated RTP packets
This is useful for users of the API which need to keep forwarding the
msgb to lower layers which may need prepending a new header to the msgb,
like osmo-bts with l1sap.

Related: SYS#5987
Change-Id: I632654221826340423e1e97b0f8ed9a2baf6c6c3
2022-09-12 12:04:20 +02:00
Pau Espin 3b0991e80f osmux: Allocate struct osmux_out_handle through API
Until now, the osmux_out_handle was allocated by the client, and passed
to the API to initialize it. This makes it really hard to improve the
implementation without breaking the ABI.

Let's break the ABI now one last time (hopefully) by allocating the
struct through an API. With only this change, the already built users
(osmo-mgw, openbsc) can still work fine, since there's no change on the
struct osmux_out_handle. However, they will somehow break next time the
struct is changed until they are ported to the same API (easy to do).

Related: OS#5987
Change-Id: Ie8df581f375c9a183a7af60b431561bda82f6e34
2022-09-02 11:29:05 +02:00
Pau Espin 51fa5ad16e osmux: Drop long time deprecated APIs
Those APIs where deprecated 4 years ago (end of Aug 2018), and they have
not been used since around that time. Hence it can be considered safe to
drop them, since they only make the whole code more complex to
understand.

API osmux_xfrm_output_init() is left since openbsc.git is still using
it.

Related: OS#5987
Change-Id: Icbdd364a8161a8113dbf1406716946f684d0a853
2022-09-02 11:19:55 +02:00
Pau Espin e95ad0e66e osmux.h: Define default Osmux port
This has been the port being used historically in most osmux setups,
and projects using osmux.h have it defined locally. Let's define it here
so that there's no need to define it on each client.

Change-Id: Ibfd058bceeeaa1384a00d8fcd6d6268b445e19bd
2022-08-10 17:46:30 +02:00
Pau Espin 91cedcbdad osmux.h: Add missing msgb.h header
Change-Id: I2002ed2352ef4db2fe0717389f1f6e24a88a973f
2022-08-10 17:44:50 +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
Pau Espin 82a52f6a7d prim: Add internal CTL SAPI to negotiate SAP versions
This commits adds a generic mechanism for applications to validate
support for SAPs and specific versions of them.

A new special SAPI is introduced to manage inbound control messages for
the protocol.
In that SAPI a new primitive HELLO.req/.cnf is added to negotiate
support for versions of any given SAP.
The idea is that the client upon connecting submits a HELLO.req(SAP,
VER) for each SAP it plans to use, including the version of the special
CTL SAPI itself (preferrably to be checked first).
Upon receiving such a message, osmo_prim_srv handles it using a special
path, which ends up calling the user provided rx_sapi_version_cb(SAP,
VER). In there, the user can either:
* Accept the version (return same VER value)
* Reject the requested version but propose another candidate version
  (return some positive VER value other than received VER). In this
  case, the client can decide whether to request another VER or close the
  connection.
* Reject the proposed version and close the connection.

Change-Id: I0c2d92cfdb5433e3caab51d712fd947d51eeef23
2021-12-09 20:21:33 +01:00
Pau Espin 4b6ce34083 Introduce osmo_prim_srv APIs
This new module allows easy exchange of osmo_prim based data types over
IPC communication (UD socket supported only so far), by replacing the
osmo_prim_hdr struct with a serialized header when submitting/receiving
it from the IPC socket.

This patch introduces the server side of the UD socket, but the client
side can easily be introduced in the same file whenever needed.

Related: SYS#5516
Change-Id: I7cab15ac092e45a256c4f0bab11b3962df861044
2021-12-09 16:59:29 +01:00
Pau Espin b2b5f1c6bf stream: Add support for AF_UNIX sockets
Change-Id: I5237a8121be05a9a31a39ca38a6a139062f258c4
2021-12-09 13:47:41 +01:00
Pau Espin d4a1107586 Introduce sctp.h to provide SCTP related functionalities
These value_strings are taken from existing private ones in
libosmo-sccp.git osmo_ss7.c, and are moved here in order to be
reused by other projects, such as osmo-hnodeb.

Change-Id: Ica6f01851fb94e31f4ef097494bb1b8a95597ba6
2021-11-23 14:18:40 +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
Pau Espin c3a6c75cea stream: osmo_stream_cli: Support setting multiple addr
This API will be later used to set multiple addresses for SCTP sockets.

Depends: libosmocore.git Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Related: OS#3608

Change-Id: I09f0d989f2309abdeb304fe570355abed2cd107b
2019-10-15 13:11:54 +02:00
Pau Espin f254ef80f2 stream: osmo_stream_srv_link: Support setting multiple addr
This API will be later used to set multiple addresses for SCTP sockets.

Depends: libosmocore.git Ic8681d9e093216c99c6bca4be81c31ef83688ed1
Related: OS#3608
Change-Id: I0fe62f518e195db4e34f3b0ad1762bb57ba9d92a
2019-10-15 13:11:51 +02:00
Pau Espin 962bf9a48e stream: Introduce API osmo_stream_cli_is_connected
Can be used by users to fetch current status of the stream.

Change-Id: I5402430e5f39eef22dfa18f33807ab6b1e771f1b
2019-09-04 17:04:18 +02:00
Pau Espin f0f1ebf70e osmux: Extend osmux_out_handle and add new API to set rtp payload_type
Previously payload_type was always hardcoded to 98 for generated rtp
packets from incoming osmux frame.

Change-Id: I5cbeb494a8932953d9fd2dc24dacf8cd97fd84e4
2019-05-17 17:12:56 +02:00
Max b3e34435b3 Deprecate osmo_stream_cli_open2()
This supposed to be variant of osmo_stream_cli_open() with explicit
control over reconnection logic but it's plain broken: doxygen docs
contradict the code, actual reconnection logic is affected by timeout
parameter directly which is set in different function.

It seems like we haven't been affected by this so far because we always
use it in auto-reconnection mode which is triggered by default due to
positive reconnection timeout value (5 sec) automatically used in the
absense of explicitly set timeout.

Looking at commit history, this function already been source of
confusion in the past. Instead of trying to fix this mess, let's just
deprecate it entirely and properly document use of
osmo_stream_cli_set_reconnect_timeout() to control reconnection logic.

The only known user is libosmo-sccp which won't use it as of
0a93a683f3cb8e5977eb4a666ab207db6e7d7af9 commit.

Change-Id: Id988ed0274b363db049f59cbf6a193727c8c3c8a
2019-03-19 13:40:55 +00: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
Max af63d87a76 Stream client: add disconnect callback
It's similar to connect_cb() but called once client has been
disconnected.

Change-Id: I905adb2d6191216551a3bcdcd1aec1f96f01612a
2019-02-20 17:33:32 +01:00
Max 732652b5b7 Add socket name functions to stream client/server
Add functions to get the description of a server link or client
connection which examine data on corresponding socket.

Those functions use static buffers and intended for single use in
log/printf statements as illustarted by corresponding example changes.

Change-Id: If9a8e211da85956781479862a63c4fc6e53ed6be
2019-02-05 16:25:20 +00:00
Max a720365c02 Cosmetic: use #pragma once as include guard
Change-Id: I2c1a13252730294597a7a9fb5726aae928f41bfd
2019-01-31 16:21:07 +01:00
Max de81cedffe Add missing include
stream.h uses msgb from libosmocore without corresponding #include
It's odd that we haven't hit this issue earlier.

Change-Id: Ib8b4f4965af0fefa7dac3f2a56a5a4b76a03fd57
2019-01-31 16:19:23 +01:00
Harald Welte da5f41cdad Migrate from osmo_ipa_idtag_parse() to ipa_ccm_id_resp_parse()
In libosmocore Change-ID I1834d90fbcdbfcb05f5b8cfe39bfe9543737ef8f
we have introduced ipa_ccm_id_resp_parse() as a bugfixed replacement
of ipa_ccm_idtag_parse().

The main difference is that the returned "value" parts now have
a correct reported "length", whereas before this commit they all
reported a one-byte too-long "length" for each IE.

Let's use this opportunity to remove the copy+pasted
osmo_ipa_idtag_parse() function from the libosmo-netif codebase.

Change-Id: I4626d247626543e032593bf226b6c233f6678562
2018-08-01 17:36:21 +02:00
Harald Welte e2fbd3dee4 remove "channel" layer
The "channel" layer on top of IPA client + server was introduced in
2011 but never used in any osmocom program/project so far.  Contrary
to the several other IPA multiplex related implementations in libosmo*,
it did not deal properly with segmented IPA messages, i.e. where a
single TCP segment (and hence recv/read call) does not contain a full
IPA message.

So rather than fixing it up and having yet another IPA related API in
our libraries, let's remove it.

Change-Id: I97c378750acb1637ee032fa88a968edf68d8979f
2018-06-29 10:57:24 +02:00
Pau Espin e259c8ab18 osmux: Set Marker bit on osmux frame loss detected
Until this patch, we didn't notify in any way to the RTP reader when an
Osmux frame was lost. Instead, we updated the seq&timestamp as if there
was no lost, and as a result the RTP reader would only see a steady
increase of delay every time an osmux frame was lost.

As the batch_factor for the lost packet is unknown, we cannot assume any
number of amr payloads lost, and thus we cannot simply increment seq and
timestamp for a specific amount. Instead, the only viable solution seems
to set the M marker bit in the first rtp packet generated after a
non-consecutive osmux frame is received.

The implementation may act differently with the first generated RTP
packet based on the first osmux seq number used for the stream. In case
0 it's used as first osmux seq number, M will be set depending on
request from original RTP packet having the M bit set. If it's not 0,
the first RTP packer will unconditionally have the M bit. That's not an
issue because it's anyway expect for receiver to sync on the first
packet.

Related: OS#3185

Change-Id: I2efed6d726a1b8e77e686c7a5fe1940d3f4901a7
2018-04-19 18:24:25 +02:00
Pau Espin dbf8e53192 osmux: Add new API osmux_xfrm_output_sched to fix rtp generation issues
With old implementation, in conditions with jitter we could end up
scheduling RTP generated packets from two consecutive osmux frames in an
interleaved way (from seq field point of view).

This new implementation should make it easier for any RTP
reader/playback to have better results in those conditions.

Old APIs osmux_xfm_output and osmux_tx_sched are marked as deprecated in
favour of the new one, which has a better control of generated RTP
packets. However, they are still usable despite the implementation changes
done to support the new API.

Related: OS#3180

Change-Id: I4e05ff141eb4041128ae77812bbcfe84ed4c02de
2018-04-19 18:24:25 +02:00
Pau Espin e9e6200d84 jibuf: Estimate src clock skew
Change-Id: Ifae633d53107417a8e2f9b0f200d2711db72d199
2018-04-13 16:13:17 +02:00
Pau Espin ce820763c1 jibuf: Add initial implementation of Jitter Buffer
Change-Id: I9688ba9c4d5b733b9f29d0f15f73750f9271ef55
2018-04-13 15:51:43 +02:00
Stefan Sperling f27fdf89dc add support for flushing and destroying a server-side stream
Introduce osmo_stream_srv_set_flush_and_destroy() which marks a
stream to be 'flushed and destroyed'. No new messages will be
received on this stream, and no new messages can be queued.
Once the Tx queue has been drained, the connection is destroyed.

The API user is given a chance to perform cleanup operations
in the closed_cb() callback for the connection.

The same mechanism will be added for client-side connections
in a follow-up patch.

Change-Id: I8ed78fe39c463e9018756700d13ee5ebe003b57f
Related: OS#2789
Suggested-by: Harald Welte
2018-02-22 19:48:36 +01:00
Pau Espin 56add1e780 stream.h: Add missing stdint.h include
This header uses uint16_t, which is provided by stdint.h.

Change-Id: I399e2986c9d8cb5b3dd31673a6b4bf63070a4770
2017-05-02 07:26:30 +00:00
Holger Hans Peter Freyther 4e93766a4b misc: Call the variable ctx like in all other places
We couldn't figure out what "crx" as supposed to mean and assume
it is a typo. Fix the code and call it ctx, this is fixing the
API documentation as well.

Change-Id: I27ed1178fdbbcf3fc0e1070dc19b4ecf9a327a04
2017-04-29 11:56:14 +00:00
Pau Espin e98afe5808 osmux: Add RTP marker bit support
According to RFC4867 (RTP payload format for AMR):
"The RTP header marker bit (M) SHALL be set to 1 if the first frameblock
carried in the packet contains a speech frame which is the first in a
talkspurt.  For all other packets the marker bit SHALL be set to zero (M=0)."

This information bit provides a way for the receiver to better
synchronize the delay with ther sender.

This is specially useful if AMR DTX features are supported and
enabled on the sender.

Change-Id: I0315658159429603f1d80a168718b026015060e9
2017-04-27 08:50:01 +00:00
Harald Welte d8348ddafc netif/ipa.h: Don't redefine 'struct ipaccess_unit' from libosmocore
'struct ipaccess_unit' is defined in libosmocore/gsm/ipa.h, we shouldn't
re-define it here.  This entire IPA code duplication accross multiple
libraries and programs is a big mess.

Change-Id: If378a088c741df540befb928a5557fc62dea954a
2017-04-15 16:06:56 +02:00
Harald Welte a7d7dd220c ipa.h: Don't redefine what libosmocore already defines
Change-Id: Ibd81efc1dc61b8c2019d55a8fa6e3bb99b5acb20
2017-04-14 10:55:55 +02:00
Harald Welte 73a44d2348 stream.h: Add missing stdbool.h include
Functions introduced in 9ec26583cd are
using the bool type without referencing stdbool.h as include file.

Change-Id: I736cb04629d516c10c7d5f42f792ed3d5ae6658f
2017-04-12 15:06:37 +02:00
Harald Welte 9ec26583cd Add osmo_stream_{cli,srv_link}_set_nodelay() function
Using this function, the user can configure if sockets related to the
respective stream client or server should have the NODELAY socket
option set in order to avoid Nagle algorithm or related algorithms
that may introduce packet delay on the transmitter side.

Change-Id: Ibeb9ba227bab18f7f4f16518c0022c4f003cc8e9
2017-04-11 19:54:07 +02:00
Harald Welte a2c2b59165 stream+datagram: Allow local bind + connect for client sockets
This uses the new osmo_sock_init2() features introduced in libosmocore
Change-Id Idab124bcca47872f55311a82d6818aed590965e6 to bind *and*
connect a given socket during creation.

Change-Id: I013f4cc10b26d332d52d231f252bb0f03df8c54b
2017-04-10 06:40:14 +00:00
Harald Welte edad98b4a0 doc: Add Doxygen group for OSMUX related functions
Change-Id: I87e08bd84236ae5d5c057bca96d122e568a6b52a
2017-04-08 20:13:14 +02:00
Harald Welte d0f9bd600c Add minimal doxygen documentation for stream + datagram modules
We should have doxygen documentation for all libosmo-* APIs.

libosmo-netif is currently devoid of any API docs. Let's start with the
stream and datagram socket related functions.

Change-Id: I589a5e60d9df2b8a65fbaf68f80e3ae0039d8c2a
2017-04-08 20:13:14 +02:00
Harald Welte d8c820570b stream: Export osmo_stream_cli_reconnect()
In case the application is using the read-callback and a read returns 0,
then the application itself would want to trigger the reconnect.  This
is different from the osmo_stream_cli_recv() case where the reconnect
can be handled internally to the library.

Change-Id: I41314bad4a9f44e8a61b9d2ba33d1a76b25bd145
2017-03-17 12:07:19 +01:00
Harald Welte cc4ce39fc6 fix/complete stream client re-connect logic
So far, when the first connection attempt failed in
osmo_stream_cli_open(), we returned a terminal errro without any
re-connection attempts.  While this may be useful in some cases, our
general idea of the stream client logic is to handle the reconnection
attempts insid the library.  We introduce a new osmo_stream_cli_open2()
function while keping the old behavior for backwards compatibility.
2015-12-22 23:54:21 +01:00
Harald Welte fb3e20b4b2 SCTP support for osmo_stream_{cli,srv} code
Wih this change, osmo_stream_ client and server API can be used not only
for TCP but also for SCTP.  The latter is needed in SIGTRAN ad Iuh
applications, for example.
2015-12-21 20:54:19 +01:00