aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmux.c
AgeCommit message (Collapse)AuthorFilesLines
2024-03-19docs: various osmux API documentation updatesHarald Welte1-8/+8
Let's make sure * only exported / user-relevant #defines appear in the manual * deprecated functions are marked in a way doxygen can mark them * descriptive comments are using doxygen syntax Change-Id: I5af0133322ddd5345a13380f1c007474c0bea117
2022-10-03osmux: Split input and output code into separate filesPau Espin Pedrol1-959/+1
The output and input paths are totally independent, they share no code or structures holding state. They can be operated totally independently. Hence, let's split the code into separate file since when someone looks at the osmux code one is really looking specifically at Tx or Rx side, but not at both sides. Moreover, the "input" and "output" concepts have always been a bit difficult to understand (would have been better calling them "src" and "sink" instead), which adds more confusion when trying to find the relevant part of code. Change-Id: Ia72995092a36ca50147611e617cb88c4dcf231d5
2022-10-03osmux: Take into account configured osmux_in_handle->osmux_seq fieldPau Espin Pedrol1-0/+1
It was not being used anywhere, yet older applications used to set it (always to 0, which was the default value applied internally). Let's make use of it and apply it as first seqnum to be used on a circuit. This value is applied upon call to osmux_xfrm_input_open_circuit(), hence it can be set independently for every new circuit. Change-Id: Ia26fcba5d7364a5744b2d64d0542a2b3880eee34
2022-10-03osmux: join osmux_xfrm_input_open_circuit() and osmux_batch_add_circuit()Pau Espin Pedrol1-33/+25
There's no real use in having it split, it just makes it more difficult to extend since extra prams must be passed over 2 functions. In fact, the duplicity of "struct osmux_in_handle" and "struct osmux_batch" as its ->internal_data should go away in the future. Change-Id: Ie4c6b55827ac27bcdfbe1b14fb238f5873243000
2022-09-29osmux: Fix unwanted RTP marker bit upon rx of osmux seqnum wrap aroundPau Espin Pedrol1-1/+1
The wrap around case was not properly considered in the condition setting the Marker bit. Let's fix it. Related: SYS#5987 Change-Id: I6e01f29a6239f930c9be2bcb2efe447e5de8fedf
2022-09-29osmux: Fix osmux seqnum incremented globally instead of per circuitPau Espin Pedrol1-7/+7
There's no real use in having a global seqnum. The seqnum, as specified by the osmux protocol specification, relates to that of the RTP seq+timestamp, hence it is per circuit. Having it per circuit allows detecting gaps and lost batches on the receiver side, applying the Marker bit on the re-assembled RTP packets. As a resut of the fix, tests/osmux/osmux_test part validating Marker bit started failing. It failed because it was wrongly written to start with, since it used only one osmux_out_handle for the 4 CIDs in use, which was wrong, since each CID must have its own osmux_out_handle as state is kept there per circuit. Related: SYS#5987 Change-Id: I562de6a871d8a35475c314ca107c2a12b55d6683
2022-09-28cosmetic: osmux: Fix typo in commentPau Espin Pedrol1-1/+1
Change-Id: I05aa1941f9cc8f3aa5ba873cf134767b56b56b69
2022-09-28cosmetic: osmux: Properly separate expressions with whitespacePau Espin Pedrol1-1/+1
Change-Id: I524899148da767516c7c1e4bc47b9d3a7b726356
2022-09-28osmux: Fix AMR F,Q,CMR fields not properly encoded in osmux headerPau Espin Pedrol1-7/+7
The value of the first RTP packet in the batch was being encoded, instead of the last one (as documented in the Osmux protocol specification). Related: SYS#5987 Change-Id: I06f3d07a05181d938c22bbd0da7172b5dad6659a
2022-09-28osmux: Proper encoding of osmux frames when when AMR FT changesPau Espin Pedrol1-29/+52
The AMR FT (and hence payload content and size) may well change over the lifetime of an RTP stream. Since all AMR payloads in an osmux batch share the same FT (its joined payload is calculated based on osmuxh->ctr*amr_bytes((osmuxh->amr_ft)), if a new RTP/AMR with a different FT arrives we cannot simply append it to the current batch. Instead, the current batch must be considered done and a new batch with anew osmuxh header must be prepared for the resulting osmux frame to send over UDP. Before this patch, when a packet with a different AMR FT was submitted for batching, it would be added in the same batch and decoding would fail since the sizes of the batches would be wrong. Related: SYS#5987 Change-Id: I25eb6ee54c898f575cc71ccfd6d190fe51d56dbe
2022-09-28osmux: Print osmux_hdr rtp_m field in osmux_snprintf()Pau Espin Pedrol1-2/+2
Change-Id: Idfe530b944ac5dfd5ce6b5150421c2d4daee8788
2022-09-27osmux: assert no batch factor greater than 8 is usedPau Espin Pedrol1-1/+2
Change-Id: Ie17a8174bc220d091cb7ff880363d22179b4f621
2022-09-27osmux: Early return on error or batch full during osmux_replay_lost_packets()Pau Espin Pedrol1-7/+13
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-27osmux: Unify return codes of osmux_batch_add() and osmux_batch_enqueue()Pau Espin Pedrol1-4/+8
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-27cosmetic: osmux: Fix typo in commentPau Espin Pedrol1-2/+2
Change-Id: Ieeaa5543e56a824752413dadf161329f5ea0e4e7
2022-09-27osmux: Change order of lines to follow packet fill orderPau Espin Pedrol1-1/+1
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-27osmux: Avoid duplicated RTP msg trigger Tx of osmux framePau Espin Pedrol1-10/+10
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-23osmux: osmux_xfrm_input(): Propagate error code to inform callerPau Espin Pedrol1-6/+8
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-23osmux: Improve logging non-usual conditionsPau Espin Pedrol1-1/+8
Change-Id: I854b0ae78e7e701ec3cb0525063f7292185d05a3
2022-09-12osmux: osmux_xfrm_input_close_circuit(): Log circuit not foundPau Espin Pedrol1-1/+4
Change-Id: I486b81d15b4d9d6abd08fbd73ca460bae22586a9
2022-09-12osmux: Allow the user to alloc msgbs used to provide generated RTP packetsPau Espin Pedrol1-4/+22
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-02osmux: Allocate struct osmux_out_handle through APIPau Espin Pedrol1-0/+53
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-02osmux: Move osmux_xfrm_output_set_tx_cb() further down to the xfrm_output ↵Pau Espin Pedrol1-16/+16
section Change-Id: I46628d1f712e9c5c56c306e27c34ff45731c0172
2022-09-02osmux: Drop long time deprecated APIsPau Espin Pedrol1-118/+0
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
2019-10-04osmux: squash LOGP message to one linePau Espin Pedrol1-2/+1
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-04osmux: osmux_snprintf(): Remove dangling whitespace at the end of dummy framesPau Espin Pedrol1-1/+3
Change-Id: I1ef73807c3300cbcc332f32e6bb905d9b30557be
2019-10-04osmux: osmux_snprintf(): Append comma between osmux frames in msgPau Espin Pedrol1-1/+4
Change-Id: I7acaba9429466db6cb5700b206d6b42da5e4627a
2019-05-17osmux: Extend osmux_out_handle and add new API to set rtp payload_typePau Espin Pedrol1-2/+9
Previously payload_type was always hardcoded to 98 for generated rtp packets from incoming osmux frame. Change-Id: I5cbeb494a8932953d9fd2dc24dacf8cd97fd84e4
2018-05-15osmux: change log lvl of batch full to debugPau Espin Pedrol1-2/+2
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-04-28osmux: Fix use of uninitialized memory in osmux_out_handleHarald Welte1-0/+1
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-19osmux: Set Marker bit on osmux frame loss detectedPau Espin Pedrol1-2/+16
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-19osmux: Add new API osmux_xfrm_output_sched to fix rtp generation issuesPau Espin Pedrol1-1/+131
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-12osmux: osmux_xfrm_output_pull: Improve checks and log of malformed packetsPau Espin Pedrol1-5/+11
Change-Id: I143805bb5ee9f5e3ada46114e380a03ede80df9f Related: SYS#4182
2018-03-07osmux: Use correct log category DLMUXPau Espin Pedrol1-27/+27
Change-Id: I77f4593941207689f714d15304dcce40b21d4bd8
2017-11-13Add SPDX-License-Identifier + Copyright statementsHarald Welte1-1/+4
Change-Id: I43bb1c4a889421907a1a08eb29c96f2330ab00ec
2017-10-27some more Doxygen header text for datagram, osmux and stream moduleHarald Welte1-0/+9
Change-Id: Ied83e6b117a420d734a88e3aff925a874c3dd520
2017-10-24osmux_snprintf: Add doxygen docPau Espin Pedrol1-1/+10
Change-Id: Idb3fcf25be9558bfc2f822352c07ebc2cb7d5caa
2017-10-24osmux_snprintf: Support different types of Osmux framesPau Espin Pedrol1-18/+32
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-23osmux_snprintf: Split logic parsing osmux header and AMR payloadPau Espin Pedrol1-10/+13
The current code still expects to parse only AMR osmux frames, but that will be fixed in following patches. Change-Id: Ic2f4d1d3cc88af912bb43c8ecd90eacc6ff7190f
2017-09-12src: _snprintf() helper functions nul-terminate buffers, if possiblePablo Neira Ayuso1-0/+3
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-11osmux: fix buffer management mess in snprintf() callsPablo Neira Ayuso1-27/+25
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-08-14osmux: Slightly improve output format of osmux_snprintfPau Espin Pedrol1-1/+4
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-14osmux: Fix buffer overflow in osmux_snprintfPau Espin Pedrol1-1/+1
When running osmux_test on my PC, the process was aborted with a "stack smashing detected" error. Change-Id: I8a7cc422c181c0c5712ac8976a5be5f0ad44a9c0
2017-06-07src: use osmo_timer_setup()Pablo Neira Ayuso1-4/+2
Use new function available in libosmocore to set up timers. Compile tested only. Change-Id: Id3dd32102c7362f3b280d2c058c2decebccb357a
2017-04-28osmux: Fix delay between RTP packetsPau Espin Pedrol1-2/+3
AMR frame contains 160 samples at 8000Hz -> 20 ms long Change-Id: I36dc69f9caf591dd1b578bc914a2ce426c7f2813
2017-04-27osmux: Use osmo_gettimeofday for testing puroposesPau Espin Pedrol1-2/+2
This way we can use fake time and osmux_test take 700ms instead of >2sec to run. Change-Id: Ic39cab74400aca8262a00c0d06884230b1a15ca3
2017-04-27osmux: Add RTP marker bit supportPau Espin Pedrol1-3/+13
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-27osmux: Check batch_factor overflow in osmux_batch_enqueuePau Espin Pedrol1-6/+7
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-27osmux: use uint8_t everywhere for batch_factorPau Espin Pedrol1-5/+5
Change-Id: I9fcc8e94b2fcd843b10cb3f8f009f2348eb3a4af
2017-04-08doc: Add Doxygen group for OSMUX related functionsHarald Welte1-0/+11
Change-Id: I87e08bd84236ae5d5c057bca96d122e568a6b52a