Commit Graph

124 Commits

Author SHA1 Message Date
Pau Espin 8a3b1acf35 osmux: assert no batch factor greater than 8 is used
Change-Id: Ie17a8174bc220d091cb7ff880363d22179b4f621
2022-09-27 18:26:48 +02:00
Pau Espin a50895f7eb osmux: Early return on error or batch full during osmux_replay_lost_packets()
If there's an error while replaying lost packets, return the error to
the caller.
If the batch is found full, early return indicating so, there's no need
to continue flow calling osmux_batch_enqueue() in osmux_batch_add()
again.

Change-Id: I62f494d2b2e7903a6683f6dea00781bb721a3d41
2022-09-27 18:24:11 +02:00
Pau Espin d6e8765faf osmux: Unify return codes of osmux_batch_add() and osmux_batch_enqueue()
This way it's way easier to return the error to the caller, and the code
is easier to read.

Change-Id: Ib78c9b82b85c74be2c5e94dae7c212175244d5fa
2022-09-27 18:21:45 +02:00
Pau Espin 845a386dcd cosmetic: osmux: Fix typo in comment
Change-Id: Ieeaa5543e56a824752413dadf161329f5ea0e4e7
2022-09-27 17:37:28 +02:00
Pau Espin fe78dc46ed osmux: Change order of lines to follow packet fill order
The osmux header goes before in the packet, so let's move the line
checking is size before the content.

Change-Id: I33feac834700d22ed06472d8971abd0567ce623b
2022-09-27 17:31:51 +02:00
Pau Espin 414b34e713 osmux: Avoid duplicated RTP msg trigger Tx of osmux frame
The RTP msg will be dropped, so it makes no sense to signal the caller
to deliver the batchbeing built, since it may still have space for next
non-duplicated message.

The exception is the case where the new packet has the M marker bit set,
since the sequence numbers can be reset or jump in those scenarios.

Change-Id: Idc457bc3b26bed68796d714bc3f37a2d016ba5c3
2022-09-27 17:31:22 +02:00
Pau Espin 3de07cf481 osmux: osmux_xfrm_input(): Propagate error code to inform caller
This way the caller can log or make statistics based on the return code.
All known implementations simply check the return code to be >0, so we
are fine here.

Change-Id: I981cc7e560cd9c792a8a2a219b3612f9834296ce
2022-09-23 18:31:03 +02:00
Pau Espin 2f58903376 osmux: Improve logging non-usual conditions
Change-Id: I854b0ae78e7e701ec3cb0525063f7292185d05a3
2022-09-23 17:39:53 +02:00
Pau Espin 98cc81bc98 osmux: osmux_xfrm_input_close_circuit(): Log circuit not found
Change-Id: I486b81d15b4d9d6abd08fbd73ca460bae22586a9
2022-09-12 12:04:25 +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 75ae80da03 osmux: Move osmux_xfrm_output_set_tx_cb() further down to the xfrm_output section
Change-Id: I46628d1f712e9c5c56c306e27c34ff45731c0172
2022-09-02 11:20:04 +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 238c844593 osmux: squash LOGP message to one line
It seems different compiler versions (jenkins and my workstation) are
generating different line number for that message, and it makes osmux_test
fail when improving logging on next commit.

Change-Id: Ie2bb0ecf4cc165b9a1080e2558b33ba37014278c
2019-10-04 16:00:31 +02:00
Pau Espin 69e04689bf osmux: osmux_snprintf(): Remove dangling whitespace at the end of dummy frames
Change-Id: I1ef73807c3300cbcc332f32e6bb905d9b30557be
2019-10-04 12:43:43 +02:00
Pau Espin b4486278b9 osmux: osmux_snprintf(): Append comma between osmux frames in msg
Change-Id: I7acaba9429466db6cb5700b206d6b42da5e4627a
2019-10-04 12:32:13 +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
Pau Espin 7839556ca9 osmux: change log lvl of batch full to debug
This message is expected as all code filling batches call
osmux_batch_enqueue() and checks for error to know if it must tell the
user of the lib to call osmux_xfrm_input_deliver.

Change-Id: I3d8227f2281f6ca92fd2502d3e328765dc7ecfe9
2018-05-15 17:09:19 +02:00
Harald Welte ef19001517 osmux: Fix use of uninitialized memory in osmux_out_handle
In Change-Id: I2efed6d726a1b8e77e686c7a5fe1940d3f4901a7 we're adding a
new member to 'struct osmux_out_handle' which is not initialized.

Rather than initializing this single new member, let's do a memset()
over the entire osmux_out_handle at the beginnign of
osmux_xfrm_output_init().

Change-Id: I751e9414c6de2413a9f977e5ae5655ebfd114f45
Closes: OS#3219
2018-04-28 13:36:40 +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 23148b069f osmux: osmux_xfrm_output_pull: Improve checks and log of malformed packets
Change-Id: I143805bb5ee9f5e3ada46114e380a03ede80df9f
Related: SYS#4182
2018-04-12 19:33:53 +00:00
Pau Espin ce439fc945 osmux: Use correct log category DLMUX
Change-Id: I77f4593941207689f714d15304dcce40b21d4bd8
2018-03-07 13:13:28 +01:00
Harald Welte bea215a565 Add SPDX-License-Identifier + Copyright statements
Change-Id: I43bb1c4a889421907a1a08eb29c96f2330ab00ec
2017-11-13 01:21:03 +09:00
Harald Welte 61b5b65deb some more Doxygen header text for datagram, osmux and stream module
Change-Id: Ied83e6b117a420d734a88e3aff925a874c3dd520
2017-10-27 19:57:37 +02:00
Pau Espin d8f2b38eb9 osmux_snprintf: Add doxygen doc
Change-Id: Idb3fcf25be9558bfc2f822352c07ebc2cb7d5caa
2017-10-24 12:37:44 +02:00
Pau Espin 77d08a67b5 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
2017-10-24 12:36:00 +02:00
Pau Espin 05bb1c2b2e osmux_snprintf: Split logic parsing osmux header and AMR payload
The current code still expects to parse only AMR osmux frames, but that
will be fixed in following patches.

Change-Id: Ic2f4d1d3cc88af912bb43c8ecd90eacc6ff7190f
2017-10-23 17:16:01 +02:00
Pablo Neira Ayuso 5994198208 src: _snprintf() helper functions nul-terminate buffers, if possible
This patch inconditionally initializes the buffer we get to
nul-terminate it, whenever possible. It's a very simple solution to
catch three overly corner cases:

1) snprintf() returns -1, very much unlikely in practise.

2) msg->len == 0: In such case, I would expect this function is never
   called with an empty message, but let's be safe in this case too.

3) If your buffer is empty, it doesn't nul-terminate the buffer.

Change-Id: I97e517f2d98e83894ea707c63489559302ff6bd2
2017-09-12 13:28:41 +02:00
Pablo Neira Ayuso 14af167a55 osmux: fix buffer management mess in snprintf() calls
SNPRINTF_BUFFER_SIZE() looks too complex, previous version maintains two
different variables to account for the remaining space in the buffer,
one of them is always decremented based on what snprintf() returns,
which may result in underflow. These variables are swapped - not used
consistently - all over this code.

Replace this macro by a simplified version, with one single parameter to
account for remaining space. This macro also deals with two corner
cases:

1) snprintf() fails, actually never happens in practise, but
   documentation indicates it may return -1, so let's catch this case
   from here to stick to specs.

2) There is not enough space in the buffer, in that case, keep
   increasing offset, so we know how much would have been printed, just
   like snprintf() does.

Thanks to Pau Espin for reporting, and Holger for clues on this.
I have run osmux_test and, at quick glance, it looks good.

Change-Id: I5b5d6ec57a02f57c23b1ae86dbd894bad28ea797
2017-09-11 18:06:37 +00:00
Pau Espin e786055567 osmux: Slightly improve output format of osmux_snprintf
The buffer for osmux_test is increased as the former doesn't seem to be
able to cope with the whole output.

Change-Id: Ic838dd9d7ad89b4510ccfa58c0390c69a075b616
2017-08-14 17:24:11 +02:00
Pau Espin 7cca0da1cc osmux: Fix buffer overflow in osmux_snprintf
When running osmux_test on my PC, the process was aborted with a "stack
smashing detected" error.

Change-Id: I8a7cc422c181c0c5712ac8976a5be5f0ad44a9c0
2017-08-14 17:24:11 +02:00
Pablo Neira Ayuso 57b5f82491 src: use osmo_timer_setup()
Use new function available in libosmocore to set up timers. Compile
tested only.

Change-Id: Id3dd32102c7362f3b280d2c058c2decebccb357a
2017-06-07 18:40:35 +02:00
Pau Espin a18caad5fd osmux: Fix delay between RTP packets
AMR frame contains 160 samples at 8000Hz -> 20 ms long

Change-Id: I36dc69f9caf591dd1b578bc914a2ce426c7f2813
2017-04-28 08:15:52 +00:00
Pau Espin 3460ad7f31 osmux: Use osmo_gettimeofday for testing puroposes
This way we can use fake time and osmux_test take 700ms instead of
>2sec to run.

Change-Id: Ic39cab74400aca8262a00c0d06884230b1a15ca3
2017-04-27 08:50:01 +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
Pau Espin a67c47cab4 osmux: Check batch_factor overflow in osmux_batch_enqueue
This commit should fix a bug present if for instance batch_factor < 8
and osmux_batch_enqueue is called from osmux_replay_lost_packets and
enough packets were lost from last received packet.

Change-Id: I5d643810949aeca4762f0cad05eed534d35087f7
2017-04-27 08:50:01 +00:00
Pau Espin a15d00ca57 osmux: use uint8_t everywhere for batch_factor
Change-Id: I9fcc8e94b2fcd843b10cb3f8f009f2348eb3a4af
2017-04-27 08:50:01 +00:00
Harald Welte edad98b4a0 doc: Add Doxygen group for OSMUX related functions
Change-Id: I87e08bd84236ae5d5c057bca96d122e568a6b52a
2017-04-08 20:13:14 +02:00
Max 5fd93e02f8 Fix potential NULL dereference
Change-Id: I5baf369dbf3948565614476980a32be59abaf42a
2017-02-07 11:46:41 +01:00
Daniel Willmann 2904f82f99 osmux: Add function to delete all msgs pending for a circuit
Use this function in osmux_batch_del_circuit() since msgs are stored in a list
per circuit. After the circuit is free()d the msgs are lost.
Before this patch any messages enqueued inside a batch when the circiut is
deleted were leaking.

Change-Id: Ib0311652183332d0475bf7347023d518d38487ef
Ticket: OS#1733
Reviewed-on: https://gerrit.osmocom.org/120
Tested-by: Jenkins Builder
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-26 12:05:42 +00:00
Daniel Willmann d5235e5e51 osmux: Pass circuit to _batch_del_circuit() and use it from _xfrm_input_fini()
Change-Id: If224980123d4a369133499ab7b577d02511f4055
Ticket: OS#1733
Reviewed-on: https://gerrit.osmocom.org/119
Tested-by: Jenkins Builder
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-25 20:42:41 +00:00
Pablo Neira Ayuso e479f25a9b osmux: rename batch->dummy field to batch->ndummy
This is basically a counter that tells us how many circuits need the padding,
so better rename this to ndummy.

Suggested by Holger.
2015-08-19 00:21:43 +02:00
Pablo Neira Ayuso e1aefad278 osmux: kill osmux_get_hdr()
Never used, so let's get rid of this function. We can recover it later on in
case we need it.
2015-07-21 11:05:41 +02:00
Pablo Neira Ayuso ea549806c9 osmux: introduce osmux_xfrm_input_open_circuit()
This new function allows you to create a circuit on an existing input handle.

We don't create the circuit anymore from the first packet seen, instead the
client application is in full control of opening and closing the circuit.

This change includes a new feature to pad a circuit until we see the first
packet that contains voice data. This is useful to preallocate bandwidth on
satellite links such as Iridium/OpenPort.
2015-07-21 09:59:49 +02:00
Pablo Neira Ayuso b3fc27423a osmux: introduce osmux_xfrm_input_close_circuit()
Add this new function to explicitly remove an existing circuit. Thus, the
client application (openbsc) is in full control to release circuits.

Before this patch, the circuit object was added when the first RTP messages was
seen, and it was removed when transforming the list of pending RTP messages to
the Osmux message (once the timer expired).

Moreover, check circuit->nmsgs to account bytes that are consumed by the osmux
header, given that !circuit doesn't mean "this is the first packet" anymore.
2015-07-21 09:59:49 +02:00
Pablo Neira Ayuso ab898deea3 osmux: count pending messages to be transformed in the batch
Add a new field to count the number of messages in the batch that are pending
to be transformed to osmux. Use this new field to check when to enable the
osmux timer.

The follow up patch keeps circuit objects in the batch until they are closed,
so we won't be able to rely on this to know when to enable the timer anymore.
2015-07-21 09:59:49 +02:00
Pablo Neira Ayuso d886bd0503 osmux: pass up struct osmux_batch
Instead of struct osmux_in_handle. This object contains the internal batching
state information.
2015-07-21 09:59:49 +02:00
Pablo Neira Ayuso f3016f29dd osmux: rename circuit->list to circuit->rtp_list
A circuit object contains a list of pending RTP messages to be converted to the
osmux format.
2015-07-21 09:59:49 +02:00
Pablo Neira Ayuso 22026a4b9b osmux: rename struct batch_list_node to osmux_circuit
I think this is a better name for this object. Basically, an input handle
represents a batch that is composed of one or more circuit objects.

Each circuit object contains a list of RTP messages that are pending to be
converted to the osmux format in one single batch.
2015-07-21 09:59:48 +02:00