Commit Graph

380 Commits

Author SHA1 Message Date
Harald Welte de3959e62c Use OSMO_FD_* instead of deprecated BSC_FD_*
Change-Id: Ib676eda521f0e89a1f4d8f9eac810598a3c813b9
2020-10-18 22:30:07 +02:00
Philipp Maier ef5b839e23 vty: add attributes to VTY commands indicating when they apply
Change-Id: Ie0182351bd8a10085563c403dfab04c4d1b4305c
Depends: libosmocore I0efc57f2cb54798ba207ae6fef9af4771d96bfa9
Related: SYS#4937, OS#1601
2020-10-08 17:40:41 +02:00
Vadim Yanitskiy 82ef2a24e3 vty: use install_lib_element() and install_lib_element_ve()
See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.

Change-Id: I22a8075852ba97edf819b368e3af4eddbf1dbae0
Depends: I8baf31ace93c536421893c2aa4e3d9d298dcbcc6
Related: SYS#4937
2020-10-04 16:45:59 +07:00
Harald Welte 072ec6f133 Merge branch '1.0.0' into master
We tagged 1.0.0 off a non-master version in the commit history in order
to keep the new TRAU frame handling out of the 1.0.0 release, but to
have all of the other fixes in a tagged release.  This merge brings
master in sync with those changes.

Change-Id: If8fc996f385f4127204ad773b991c49d853dfc5b
2020-08-13 12:14:36 +02:00
Harald Welte 2a8a34cd01 Bump version: 0.8.0.59-1f92-dirty → 1.0.0
Change-Id: Iffbb96739f53c7e005f440bc1615f158f7c661eb
2020-08-13 12:09:39 +02:00
Philipp Maier 8d15001910 trau_sync: make sync pattern configurable
When a trau sync fsm is allocated, the user must set the sync pattern,
which can not be changed during the whole fsm lifecycle. However on
codec changes it might be necessary to change the sync pattern on the
fly.

- Add function to change the sync pattern

Change-Id: I1caff93b4c8eace8ba8cd6e32e996a9e1503232b
Related: OS#2659
2020-08-07 17:18:46 +02:00
Harald Welte 2f80b93528 trau_frame: Add missing break statement in osmo_trau_frame_encode()
Change-Id: I986781218a844e043b6206124696452b3afec7fd
Closes: CID#211592
2020-08-06 11:58:14 +02:00
Harald Welte ab8e0666f4 trau_sync: Check return value of osmo_fsm_register()
Change-Id: Ieaf524423033864a8b79ea1b04b62568d10ffbd3
Closes: CID#211593
2020-08-06 11:58:14 +02:00
Harald Welte 1f310f7b03 trau_frame: Fix computation of odd parity while encoding HR frames
division modulo 1 is always 0, and hence we always returned '1'
as parity bit.  Instead, we need to check if the LSB is set in order to
know if the number of bits is odd or even.

Change-Id: I37af702ba020a90a820bae84cb603e187ebbacb5
Closes: CID#211594
2020-08-06 11:58:14 +02:00
Harald Welte dbb429cfd3 Add missing build dependency to libosmocodec-dev
Since I0190872dd282bcfe0f97bb4f8ab8d09023f9f06b we are using a header
file provided by libosmocodec, which means we need to add it to our
dependencies (and include path).  Linking against the library is
not required, as we don't use any symbols at this point.

Change-Id: Ie4524165d8873f6c801e07d9f03c94f43c66110d
2020-08-04 09:51:37 +02:00
Harald Welte cd90ed2dd5 TRAU frame RTP conversion
This adds code that converts codec frames between (decoded) TRAU format
and RTP payload format.  The FR + EFR functions have been lifted from
OsmoNITB and exended slightly.

The HR functions have been written from scratch. There is also
incomplete code for AMR that needs to be completed + tested.

Change-Id: I7f6993cce2b95318203043e2e14952e581941b79
2020-08-03 02:57:42 +02:00
Philipp Maier 8eae96fab3 trau_sync: prevent false positive synchronization on startup
The history buffer is filled with zeros on startup. Together with
incoming bits those may appear as a valid signal. (each trau frame
begins with 16 zeros). In order to prevent this lets set the history
buffer to all ones, so that it looks like the data in the history
buffer is from an unused timeslot.

Change-Id: Ie5cc7b9a1ab3d8940ef9d2147f5999e8d09ee40e
Related: OS#2547
2020-08-03 02:57:37 +02:00
Harald Welte 78861c0aef Add new TRAU frame sync code
This code is able to detect and sync against a variety of TRAU
frame sync patterns.  Focus is so far on those patterns present on
16k sub-slots, but 8k sub-slots are expected to be supported soon,
too.

A new codebase for this is required as the old OsmoNITB code had
conflated a 16k sub-slot multiplexer with TRAU frame synchronization,
so there was no way to separate those two parts and hence no way to
support 8k sub-slots.

Change-Id: Ia6fe6228b0b8b9a27999f37ce1115ed5558881ea
2020-08-03 02:29:21 +02:00
Harald Welte 95e2dfbc83 osmo_trau_frame_encode(): Check for sufficiently sized output buffer
Change-Id: Ie14399b2271aba9ff81f62d593a0ddd9d3e83d98
2020-08-03 02:29:21 +02:00
Harald Welte dd9ee98d7e trau_frame: Introduce support for Downlink Time Alignment
In the uplink direction, we provide osmo_trau_frame_dl_ta_us()
to determine the time alignment as requested by the CCU in the BTS.

In the downlink direction, the TRAU frame encoder will perform
time alignment as requested by the user in osmo_trau_frame.dl_ta_usec.

Change-Id: I3981becafc56c9a50119b9ba6bf67aa0391cc76e
2020-08-03 02:29:21 +02:00
Harald Welte 254b924536 trau_frame: New API
The old TRAU frame code in src/trau_frame.c (which is for some strange
reason part of libosmo-abis, and not libosmo-trau!) was introduced more
than a decade ago for the needs of bs11_abis AKA OpenBSC aka OsmoNITB.

It is too constrained to implement TRAU frame parsing in a generic way,
including:
* no way to add support for 8k sub-slots
* no way to handle CRC bits or UFI (i.e. no AMR)
* no real API design, it was just ripped out from OsmoNITB and moved into
  a library (even the wrong one)

For those reasons, let's introduce a new API for TRAU frame
encoding/decoding - one that supports all the relevant use cases.

Change-Id: I5cf42e6c445d9224be18503cebc7584b3beba08c
2020-08-03 02:29:21 +02:00
Harald Welte 1f9228434e e1_input_vty: Fix VTY help strings
* HSL was never fully supported, not sure why it's in the help
* E1D was neglected to add to the help string

Change-Id: I4a5e503676618171e59550774892816b61adecae
2020-08-02 11:29:46 +02:00
Harald Welte ca71296916 input/e1d: Add missing "RAW" timeslot support
Change-Id: Ia4ef5fd40ce15f824a3cbfec533dde2169464c3b
2020-08-02 11:29:46 +02:00
Harald Welte f776669df2 input/e1d: Fix support for TRAU slots
Change-Id: I2d7f85523089f4e1f2496d9836bced577eda4671
2020-08-02 11:29:46 +02:00
Harald Welte 182957bf69 dahdi: Use osmo_revbytebits_buf() instead of local flip table
We've had osmo_revbytebits_buf() in libosmocore for ages.  As it
recently turned out, the flip_bits[] lookup table approach implemented
here is faster at least on x86 systems of the last decade or so.

As of Change-Id I25029fe7e54c92979fb0119992fb8dc167e1536e in
libosmocore, it has been migrated to the lookup table approach. This
means there's no performance penalty of migrating to using it, and
hence no reason whatsoever to have a private implementation here.

Change-Id: I285a87a9fc6abae7d8b47923a46cd082f46829f8
2020-08-02 11:25:23 +02:00
Harald Welte ac290eec96 e1d: Fix compilation after I4a088f91f23aaad05c5ab84a4783c1915d85aca6
This slipped through the cracks as jenkins so far doesn't build with
--enable-e1d support (fixed in a separate patch).

Change-Id: I505331a4a9430001b049e9f5cc36abf4ce4ca19e
2020-08-02 10:48:50 +02:00
Pau Espin deb5c4f7ab ipaccess: Fix use-after-free in ipaccess_drop()
Recent commit b8ea0ff521 introduced a
heap-use-after-free while getting rid of memleaks and clearing up the
reference counting lifecycle of the line object.

In that commit, e1inp_line_put2() was added in ipaccess_drop() which may
potentially free the line object (and its children e1inp_ts objects)
under specific conditions/scenarions. However, the function still used
the child object e1i_ts which in those scenarios would access already
freed memory.

Let's keep a local reference during the life of the function to make
sure the object is non-freed during e1inp_line_put2(), so that we can
notify upper layers that the link is down.

Detected by enabling ASan and running BSC_Tests.TC_chopped_ipa_ping
TTCN3 test.

Related: OS#4688
Change-Id: I4f56af28ad8297846bcdc8ba7afe51fff0f9a00f
2020-07-31 13:03:43 +02:00
Harald Welte 8fc8ceff16 e1d: Add new osmo_e1dp_client_ts_open() argument
An additional argument was added to specify the timeslot read
buffer size.

Change-Id: I4a088f91f23aaad05c5ab84a4783c1915d85aca6
Depends: osmo-e1d I6d603778cce14c5d72fe5f54904905ea7e66d7ff
2020-07-22 09:48:59 +02:00
Pau Espin ffc92d5b23 lapd: Use lapd_dl_init2 instead of deprecated lapd_dl_init
Change-Id: If25957d10bf9e32d2fe601111a9c1311aee21094
2020-07-15 15:42:19 +02:00
Pau Espin 6ffeb9af89 cosmetic: lapd: Fix trailing whitespace
Change-Id: I7a6af2f417f6f924a3f27cfa12462158f2c2a1c6
2020-07-15 15:39:33 +02:00
Pau Espin 8a4e3d91f8 ipaccess_recvmsg: Untangle code updating line
This patch untangles the code a bit by changing the order where actions
are taken and variables are assigned.

The only real changes in behavour are the introduced assert, and that
bfd->data is set to NULL before releasing the related line.

Related: OS#4624
Change-Id: I947f64f8fa20f87fdc84538402623a6bcf35fdf9
2020-07-15 15:39:33 +02:00
Pau Espin 815117c246 ipaccess_recvmsg: Assert the new bfd from new line differs from the old one
Related: OS#4624
Change-Id: I45818e04af0da7b1109d909642a1ea378a85a636
2020-07-15 15:39:33 +02:00
Pau Espin dc55a5fa63 ipaccess_recvmsg: Clean up release steps upon error condition
Related: OS#4624
Change-Id: I47a3e477d6861620a741193d3d3d3e286836fd44
2020-07-15 15:39:33 +02:00
Pau Espin a2ff733ac0 ipaccess: Set bfd->data to NULL before releasing its reference
Since the reference is dropped, make sure no one accesses it through
that pointer anymore. It must be done before calling the put() method,
otherwise it may already be released when put() returns.

Change-Id: Ic3f261b2a995efcbc8eece9669ee3ae63af7b5c0
2020-07-15 15:39:33 +02:00
Pau Espin 8737ad4f75 ipacces: Fix e1inp_line reference put in ipaccess_close
Drop the function e1inp_close_socket since it's only used by the caller
at hand, and it's only exported through "internal.h", so no app is using
it. Remove it because there's only a caller, and furthermore because
keeping it (and putting bfd->data==line) would introduce a layer
violation because the bfd->data==line is only used for ipaccess so far.

Triggering path:
handle_ts1_read ret=0 "Sign link vanished"
  ipaccess_drop
line->ops->sign_link_down
  (osmo-bsc) ipaccess_drop_oml
e1inp_sign_link_destroy
  link->ts->line->driver->close
ipaccess_close

Related: OS#4624
Change-Id: If23cc722106a9f70c998e591369a4acafa52c519
2020-07-15 15:39:33 +02:00
Pau Espin b8ea0ff521 ipaccess: Drop e1inp_line reference in ipacess_drop()
the bfd->data handles a reference to the e1np_line (obtained through
e1inp_line_get() during bfd setup), so remember to drop it under this
condition.

Related: OS#4624
Change-Id: I418064df04872befe2e936e21768b6ea01263120
2020-07-15 15:39:33 +02:00
Pau Espin 5196cd5641 e1_input: Use osmo_use_count in e1inp_line
osmo_use_count is available since libosmocore 1.1.0 release, so bump
required libosmocore version in autotools and packages.

struct e1inp_line field refcnt is kept in order to keep ABI
compatibility accessing struct fields. The new use_count is added at the
end. Size of struct changing is fine since it is allocated through
an API and a pointer should be used by clients.

e1inp_line_clone API is changed but it's not used by anyone outside
libosmo-abis, so it's fine.

Related: OS#4624
Change-Id: I0658b2e9c452598025cc0f1d0b060076171767cc
2020-07-15 15:39:33 +02:00
Pau Espin 30e80d555c ipaccess: Fix log formatting of RESP_ID IPA attributes
Change-Id: Id5b4c39737a43c9ba68f3aacc889c10eba697920
2020-07-14 13:23:08 +02:00
Pau Espin 4ffd2a9c9b ipaccess.c: Drop repeated ipaccess_keepalive_fsm_cleanup in write error path
The function is already being called by ipaccess_drop().

Change-Id: I00d0557fe81861d4b913a4c76e4b56f93e656103
2020-07-14 12:18:24 +02:00
Harald Welte bcfd7ea184 subchan_demux: Fix out-of-bounds write
We cannot blindly append two ubits to the 320-ubit sized buffer.  In the
end, we may already fill the buffer after the first ubit, causing a
buffer overflow with the second ubit.

Lets check if the buffer is full after every bit.  Avoid copy+pasting
but move the code repeated per bit to a new function.

Change-Id: I58d946265372278051e4f29301d4f201ab98c0fc
Closes: OS#4648
2020-07-04 11:21:23 +02:00
Harald Welte 96034fcced input/dahdi.c: Don't simply read beyond end of msgb
Let's first add two bytes to the msgb before writing.  This way we
would assert in case there was no tailroom.  As we just added tailroom
in the previous patch of this series, we are fine

Change-Id: If84b31ea9a3fc7a6c8768918efed2822d1d58427
Closes: OS#4644
2020-07-03 19:26:16 +02:00
Harald Welte 47c247b940 input/lapd.c: Enlarge message buffers for DL-SAP primitives
The DL-SAP primitive msgbs are currently allocated
to only have headroom but no tailroom.  Let's change that

Change-Id: Ia476c8a2f70e6579be53230427923885a573f801
Related: OS#4644
2020-07-03 19:08:42 +02:00
Harald Welte ea7da44bdd lapd: Replace magic numbers with #defines
Related: OS#4644
Change-Id: I2971fb5bb27a7024abac7e2a4414eaf61f27ccb5
2020-07-03 19:08:37 +02:00
Harald Welte 36166d0a8d fix compilation with --enable-e1d
In Commit Ib81a749ae24013b17caaf5fd64ccd9acbbc3ce08 we introduced
a syntax error leading to compile failure sfor --enable-e1d ever since.

This hsan't been discovered as osmo-e1d support is not built
automatically anywhere.

Change-Id: If1f4bd9469a614470045716df4c35187ff2cc76b
2020-07-01 09:54:30 +02:00
Pau Espin 89c6b8a42e e1_input: refcount inc line during e1_sign_link_create, not during line update
Increase reference count when a new sign_link using the line is created.
Otherwise the line is freed too quickly during e1inp_sign_link_destroy()
with several TRX being used, since each RSL link is missing a reference.

That extra refcoutny in update() is not really needed given that we already
have a link assigned on the line when we call update.

Fixes: OS#3612
Fixes: OS#4094

Change-Id: I74405b0e87a89c17d58e87024f4aedbd30832013
2020-06-09 07:36:21 +00:00
Harald Welte b90318808b lapd: Always print context information when logging
Historically, OpenBSC has primarily been used with setups that have
a single E1 based BTS connected. This meant that an error message on
the E1 LAPD implicitly has to be related to that single BTS.

However, in more comprehensive setups, there may be many BTSs on many
E1 lines with many signaling slots.  At this point, it's important to
know which line/timeslot/tei/sapi a given log message relates to.

This patch introduces related log context.

Change-Id: Ib81a749ae24013b17caaf5fd64ccd9acbbc3ce08
Requires: libosmocore.git Change-Id Ie6742843fff809edffcac24c4dce4edf66bc71be
Related: OS#1938
2020-06-09 07:11:42 +00:00
Oliver Smith 62725d0b58 src/input/ipaccess.c: set TCP_NODELAY
Set TCP_NODELAY for all RSL/OML sockets.

Related: SYS#4906
Change-Id: Ia3d4c41bf0659e682f0b7ae5f3d58ed0f28edb58
2020-05-28 09:56:38 +00:00
Harald Welte db1bc21d73 trau_frame: Fix AMR frame decoding
Change-Id: I9b2dbca05217ee78cade2a47a02857f7cf7e0cd7
2020-05-14 15:48:09 +00:00
Harald Welte a684b84f11 subchan_demux: Use ubit_t where appropriate
the subchan_demux code predates ubit_t; let's use it to clarify
certain pointers refer to arrays of unpacked bits.

Change-Id: I944f05473954920d57e12d5514cf928fc78f2ea4
2020-05-11 08:40:01 +02:00
Harald Welte 6913b9a4e4 trau_frame: use 'ubit_t' for unpacked bits
Change-Id: I497dbb7e9e199c6276e585b977bd941a2b442b3b
2020-05-11 08:40:01 +02:00
Harald Welte 5226e5b926 subchan_demux: Use 'ubit_t' for unpacked bit buffer; use const
Change-Id: Ia082b9fddf03d02afd007825a1588a3ef0dbedae
2020-05-10 19:11:44 +02:00
Sylvain Munaut eb55e2f8d9 e1_input: Add VTY command to enable PCAP debug output
This command is also usable at run-time to dynamically
enable / disable e1 tracing on all active lines

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I0b4251702aecd6721b9d63c320351ef6cb513454
2020-05-09 10:45:20 +02:00
Sylvain Munaut 4b45e9d1a6 e1_input: Allow to change the pcap fd and/or unset it
This will update the pcap fd in all open lines and close
the previous one (if applicable).

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I5c7dd740ba0a90b40c69a53b3dcc9d6d6a98f660
2020-05-08 18:10:15 +02:00
Harald Welte 54c919ec48 ortp: disable SO_REUSEADDR + SO_REUSEPORT
ortp >= 0.24.0 doesn't differentiate between SO_REUSEADDR and
SO_REUSEPORT, and has both enabled by default.  The latter means that
we can end up with non-unique port bindings as we will not fail to
bind the same port twice.

This should have caused visible problems not only when operating multiple
osmo-bts on one machine (rare), but also with a single osmo-bts. Once the range
(default 16384-17407 ) wraps, there is a risk of new sockets (for new cals)
colliding with old ones. As two ports (RTP+RTCP) are used per call, this means
every 512 voice calls we expect the BTS to wrap. And from that point onwards
there's a risk of overlapping with previously allocated sockets.

Change-Id: I4fc9eee561c7958c70c63b4ffdc6cb700b795e28
Closes: OS#4444
2020-03-09 11:24:45 +01:00
Oliver Smith 3c51482e3d osmo_ortp: add osmo_rtp_socket_set_dscp()
Related: OS#4438
Change-Id: I41603db8c1286660ad57ac1c78a8fb393a2b080b
2020-03-07 15:07:27 +01:00