Commit Graph

4868 Commits

Author SHA1 Message Date
Vadim Yanitskiy d0cb0d585b tests/{v110,gsm44021}: change naming: 'test_' -> '_test'
Ensure that the test binaries do not show up in `git status`:

tests/gsm44021/test_frame_csd
tests/v110/test_frame
tests/v110/test_ra1

The new naming complies to the 'tests/*/*_test' pattern in .gitignore.

Change-Id: I7bbcec2ec6887a2e6c9b37e2e5b3d9ee489654ce
2023-09-04 17:47:41 +07:00
Vadim Yanitskiy cb7d603d8b .gitignore: add include/osmocom/core/socket_compat.h
Ensure that this auto-generated file does not show up in `git status`.

Change-Id: Id7c245579f5a3288a9ea62589ca802e427e54720
2023-09-04 17:47:08 +07:00
Pau Espin c49691ff76 gsm_12_21.h: Introduce packed structs for NM_ATT_IPACC_NS_CFG values
Change-Id: Ie477b0e6d79e6d408e0004fd60307afc5feaa3b6
2023-09-02 08:51:52 +00:00
Pau Espin bbb69d3af5 gsm_12_21.h: Introduce packed structs for NM_ATT_IPACC_BSSGP_CFG values
Change-Id: Ibfd759cb8a252f801bb3a758ea7960072c96f254
2023-09-02 08:51:48 +00:00
Pau Espin 34e67c2e70 gsm_12_21.h: Introduce packed structs for NM_ATT_IPACC_RLC_CFG{,_2,_3} values
Change-Id: I60e17dedd1fadce0f705616e3ed96cabb318bcec
2023-09-02 08:51:44 +00:00
Daniel Willmann ec7d491589 osmo_io: Use local variable to reference msghdr->msg
Change-Id: I336ef7a5460dd18bf8e0f4ac5e97747f9fec5a35
2023-08-31 14:28:13 +00:00
Daniel Willmann f39c23f918 osmo_io: Change parent of msghdr to iofd (instead of msg)
msg was made a parent of msghdr after discussion in change
I3a279b55a3adff96948120683c844e1508d0ba94

It turns out this violates some assumptions made in osmo_io,
specifically that the user read callback shall free msg, but we expect
msghdr to remain valid until after that callback returns.

In general I think it is cleaner to make iofd a parent of msghdr.

Change-Id: I41277190e3020cd8fa625bd57a743973e2a65c4b
2023-08-31 14:28:13 +00:00
Oliver Smith 405e7cc971 debian: fix build on ubuntu 20.04 without liburing
Ubuntu 20.04 is based on debian 11, but does not have liburing. Extend
the logic to cover this distribution too, so building packages for it
isn't stuck anymore on libosmocore not being able to resolve the
liburing-dev dependency.

I have verified that this makes libosmocore properly build with/without
liburing on debian 10, 11 and ubuntu 20.04 and 22.04.

Fixes: e486e012 ("debian: depend on liburing-dev for debian >= 11")
Change-Id: If18d6543fae9537c8b188e90499491bda3fdfe59
2023-08-31 14:48:49 +02:00
Daniel Willmann 3236fdffd6 ns2: Add VTY option to change the max write queue size for UDP
Ensure that existing binds are updated as well.
In some cases the default max length of the osmo_io txqueue could be too
small. Set it to 128 by default and add a VTY option to change it for
an NSI (program-wide).

Change-Id: I993b87fd6b83b3981f5e293f70b931075afec715
Related: SYS#6550
2023-08-30 09:18:35 +00:00
Oliver Smith 8c0a2c72b0 contrib/libosmocore.spec: centos7: disable uring
liburing is not available in CentOS 7, so disable it there. I've
verified that this works as expected in our OBS with CentOS 7, 8 and
openSUSE Tumbleweed.

Related: OS#5751
Change-Id: Ie2399754952d460499c9355706be37f792988bac
2023-08-29 15:48:39 +02:00
Pau Espin b437f80e89 socket: Avoid aborting socket creation if setsockopt for ASCONF fails
Avoid aborting the entire socket creation, since those sockopt are fairly
new in the kernel (v5.4), and the feature can still be enabled in older
versions system-wide with sysctl. The worst it can happen is that the
ability to submit address updates (such as Peer Primary Address) doesn't
work, which is not really critical.

Related: SYS#6501
Change-Id: Iff261c8592b6b3c4237c90c84b4e8e921e3c4a65
2023-08-28 13:59:03 +02:00
Daniel Willmann f91d2aac9d osmo_io: Add io_uring backend
Change-Id: I5152129eb84b31ccc9e02bc2a5c5bdb046d331bc
2023-08-24 17:33:19 +02:00
Oliver Smith e486e012c8 debian: depend on liburing-dev for debian >= 11
Prepare for the io_uring backend, by conditionally depending on
liburing-dev on debian >= 11 based distributions. On debian 10 based
distributions, set --disable-uring as configure flag.

Closes: OS#6143
Related: https://askubuntu.com/a/761943
Change-Id: If7832baec0bddbe0bbbbfe07f77bba3deb328d5c
2023-08-24 15:24:33 +00:00
Daniel Willmann 012d9044a2 osmo_io: Avoid potential double free when sending msgb
Ensure that a msgb  has the proper talloc parent:

All msgbs inside an iofd get the iofd as parent. Received msgbs are reparented
to iofd->msgb_alloc.ctx (which was set in osmo_iofd_setup()) before
being passed to the receive callback.

Before this change the code could fail for msgbs that are submitted via uring
where the (failed) write returns after the iofd has already been
osmo_iofd_free()d. free()ing the iofd is deferred until the write
completes, but the (iofd) parent context could have been free()d in the
meantime.

Change-Id: I3a279b55a3adff96948120683c844e1508d0ba94
2023-08-24 17:13:33 +02:00
Daniel Willmann 2b34e92d0e osmo_io: Add iofd_handle_recv()
Handle msg reception in a common function that can be called from the
different backends.

Change-Id: Ifc407d446805f885d37767f421ff710cb276a01f
2023-08-24 14:46:51 +00:00
Pau Espin 45ab0d7335 lapdm: Update public lapdm_msg_ctx upon CCCH data ind
This allows uses accessing the updated fields such as fn from the l3_cb
when receiving a msg from CCCH, eg: "le->datalink[DL_SAPI0].mctx.fn;"

Related: OS#3626
Change-Id: Icabc3759c47b0f7cfe61f1b7a96f08f36714262e
2023-08-24 13:48:19 +00:00
Pau Espin 0ef0a1cb1e Revert "rsl: Introduce new osmocom extension IE RSL_IE_OSMO_ABS_FRAME_NUMBER"
This reverts commit 54b1b3be37.

osmo-bts is forwarding the msgbs as they come from lapdm to the RSL on
the wire, which means we end up sending the osmocom-specific IEs on the
wire, something which was not envisioned when adding this IE.

Change-Id: Id9029ef378970322063478e9ce888daf335d6103
Related: OS#6142
2023-08-23 17:13:34 +00:00
Pau Espin 06da40bdb3 Revert "lapdm: Append RSL_IE_OSMO_ABS_FRAME_NUMBER to RSLms msgs towards upper layers"
This reverts commit d981794113.

osmo-bts is forwarding the msgbs as they come from lapdm to the RSL on
the wire, which means we end up sending the osmocom-specific IEs on the
wire, something which was not envisioned when adding this IE.

Change-Id: I0ab0d5b545b4862e72eb1842edd07ca2e4955311
Related: OS#6142
2023-08-23 17:13:34 +00:00
arehbein cd23806264 select: Prevent negative index lookup on osmo_fd_lookup.table
Marked as WIP because I'm not entirely sure if negative index lookups
were allowed on purpose (although I doubt it)

Change-Id: Iba81873cbc435229599b1a8139cf4b627f8e6924
2023-08-23 17:10:13 +00:00
Pau Espin d981794113 lapdm: Append RSL_IE_OSMO_ABS_FRAME_NUMBER to RSLms msgs towards upper layers
This makes it possible to track GSM time in the upper layers.
The existing RSL_IE_FRAME_NUMBER and RSL_IE_STARTNG_TIME cannot be used
there, since those are 16bit fields containing Relative FN values.

The IE needs to be added before the L3_INFO one, because user code
usually assumes the msgb->l3 pointing to L3_INFO value extends until the
end of the message, using msgb3_len(msg). Regarding having an extra IE
at the middle, it's not a big problem since the libosmocore version
submitting this commit to the upper layers is the same which will also
be parsing it through rsl_tlv_parse() later on by the app.

Related: OS#3626
Change-Id: Id62c18f49f270449067b25b7104eb8b47f1955ec
2023-08-21 14:34:55 +00:00
Pau Espin 54b1b3be37 rsl: Introduce new osmocom extension IE RSL_IE_OSMO_ABS_FRAME_NUMBER
This will be used in RSLms to provide Absolute Frame Number information
of the primitive indications being sent to upper layers, so that it's
possible to track GSM time in the upper layers.
The existing RSL_IE_FRAME_NUMBER and RSL_IE_STARTNG_TIME cannot be used
there, since those are 16bit fields containing Relative FN values.

Related: OS#3626
Change-Id: Ia28caa24dd141b1162b6e11500d753353fe6500d
2023-08-21 14:34:55 +00:00
Pau Espin e83227f735 socket: Add osmo_sock_init flag to enable SCTP ASCONF features
The SCTP_ASCONF_SUPPORTED sockopt, which enables ASCONF features
for the SCTP associations managed by the SCTP socket, gets its default
value from to sysctl "net.sctp.addip_enable", which, at least up to
current kernel 6.4.8 is set to "0" (disabled) by default.
As a result, ASCONF related features such as
setsockopt(SCTP_SET_PEER_PRIMARY_ADDR) fail with -EPERM
since ASNCONF extensions where not negotiated during the SCTP init
handshake.
This commit adds support for setting SCTP_ASCONF_SUPPORTED=1 during
socket creation, since that needs to be applied before the first
bind()/connect() (before first assoc is created).

Furthermore, for ASCONF features to work properly, the assoc also needs
to announce/use the AUTH extension, as per RFC5061 section 4.2.7.
Otherwise, the peer receiving an SCTP INIT with
ExtensionFeatures=ASCONF,ASCONF_ACK but without AUTH, will reject the
assoc with an ABORT since it's not complying with spec (this behavior
can be tweaked through sysctl "net.sctp.addip_noauth_enable").

The AUTH extension is enabled through sockopt SCTP_AUTH_SUPPORTED, and
its default value is that of sysctl "net.sctp.auth_enable", which is
also disabled (0) by default.

Kernel support for those is relatively new:
SCTP_FUTURE_ASSOC added in: 80df2704a375bb4b3c9c5cce9c00052361b16d61
Follows: v5.0-rc4
Precedes: v5.1-rc1

SCTP_ASCONF_SUPPORTED added in: df2c71ffdfae58961981d7cbcccea93688fc4e96
Follows: v5.3-rc5
Precedes: v5.4-rc1

SCTP_AUTH_SUPPORTED added in: 56dd525abd56f7acd7b44a52935726e3ada4916c
Follows: v5.3-rc5
Precedes: v5.4-rc1

Related: OS#6076
Change-Id: Iac07031927b66a9d32d2bb2faab817e4c922a359
2023-08-21 10:28:11 +02:00
Pau Espin aea78a2483 gsm: Introduce functions to convert between FN and RFN (Reduced FN)
Implementation ported from osmo-pcu.git
e98b315d12fb009359410809f4169f9380f3d933, function bts_rfn_to_fn().

This functionality can be used by osmo-pcu, libosmo-gprs or any other
related code which needs to handle RFNs.

Change-Id: Ib71e8da976f6cc84c3a4ab17b0a8c2101492e243
2023-08-11 20:46:04 +02:00
Pau Espin 1247aa1fc0 lapdm: Track fn of primitives in struct lapdm_msg_ctx
This field will be used in follow-up commits to provide FN information
in RSLms primitives towars upper layers. This is needed for instance on
the MS side when a CCCH_DATA.ind is received containing a TBF ImmAss
with a relative FN indicating the Starting Time. Without tracking FN
advance, the uppers layers are not capable of figuring out the absolute
FN of the TBF Starting time.

The struct lapdm_msg_ctx is not really used outside of libosmocore, so
we are safe extending it.

Related: OS#3626
Change-Id: Icf986f4202703eb452bedc1b749bb8ce0c73706f
2023-08-11 17:37:07 +02:00
Pau Espin 6df53dc769 tlv: Introduce API msgb_tv32_push()
msgb_tv32_put() already exists, but msgb_tv32_push doesn't.
The tv16 counterparts are already present, and having to pass 32bit
integers is also quite common, so let's add an API for it.

Change-Id: I68d5693a18d55ce8d0647359044157d7e5bfae50
2023-08-11 15:36:27 +00:00
Philipp Maier 3c577269c8 gprs_bssgp_rim: add decoder for RIM ROUTING ADDRESS
We have a decoder for RIM ROUTING INFORMATION (bssgp_parse_rim_ri),
let's also have a decoder for RIM ROUTING ADDRESS (bssgp_parse_rim_ra.

Related: OS#6095
Change-Id: Ibca1f08906c4ffeecdae80d4e91c6c7b05fe4f8a
2023-08-10 12:01:25 +02:00
Philipp Maier 9e75544137 gprs_bssgp_rim: allow sending of encoded RIM messages
The API function bssgp_tx_rim() accepts decoded RIM PDU structs, encodes
them and eventually sends them. However, there may be cases where the
RIM PCU already exists in its encoded form. (This is in particular the
case when the RIM PDU is forwarded from GTP to BSSGP)

Lets add an API function bssgp_tx_rim_encoded to allow sending of
already encoded RIM PDUs

Related: OS#6095
Change-Id: Id4a793bbaf32d7b9d894dcc5be3faaf2f2d91d82
2023-08-10 10:17:03 +02:00
Philipp Maier a0d84832be gprs_bssgp_rim: also print NSEI when sending RIM messages
In bssgp_tx_rim we print source and destination address of the RIM
message we send, but we do not print the NSEI, even though this is also
an important address parameter.

Related: OS#6095
Change-Id: I2595abff28fc1d89c1409a2ca0194fedc6f15313
2023-08-10 08:16:05 +00:00
Pau Espin f6ebc8a9d0 cosmetic: lapdm: Fix typo in comment
Change-Id: I5cf9aea6ba072bd1ccb3e894c0a311844bcad8df
2023-08-09 18:57:35 +02:00
Daniel Willmann 92efac26d7 osmo_io: Use MSG_NOSIGNAL to avoid SIGPIPE on write
Change-Id: I85433124a8e80fc2aa19b551bdaf2655ef1eea2c
2023-08-08 10:02:33 +02:00
Daniel Willmann f083382b9c osmo_io: Ensure correct ownership of msgb when sending
Use talloc_steal() if a msg is passed in to osmo_io when sending. This
avoids the message being free()d early in case the original parent is
free()d.

Change-Id: Ie36bd68a8bd63e67d76fb41996f8fdf99f51d96c
2023-08-08 10:02:33 +02:00
Pau Espin ad9757a3b1 sockaddr_str: Introduce macro OSMO_SOCKADDR_STR_FMT_ARGS_NOT_NULL
Under certain cases, gcc version 13.1.1 20230714 catches the fact that
the pointer being passed cannot be null, (eg local variable struct
osmo_sockaddr_str addr_str passed as &addr_str), and errors about
checking nullability of a pointer which cannot be null.

"""
/include/osmocom/core/sockaddr_str.h:63:10: error: the address of 'addr_str' will always evaluate as 'true' [-Werror=address]
   63 |         ((R) && (R)->af == AF_INET6)? "[" : "", \
      |          ^
"""

Let's add a macro which can be used for pointers known to be there (tbh,
I'd expect that to be the usual case in most code paths). Using this new
macro should be more optimal in those cases, and avoid gcc erroring.

Change-Id: I59c7b05450cb463d2e87ddb022f0b6ba7109d398
2023-08-01 19:03:49 +02:00
Vadim Yanitskiy 39469b9fcb isdn: mux_timeslot_provide_bits(): remove unused 'count'
Change-Id: Id2c6d05c56424fa79ade84a29b8b70293dc690e4
2023-07-28 04:58:07 +07:00
Andreas Eversberg 209bc38974 ASCI: Add missing check for return value of gsm0808_enc_speech_codec_list2()
Fixes: CID#318987
Change-Id: I771b8ee8dfe1588d0af1c4957489f723447a7054
2023-07-26 12:52:30 +00:00
Vadim Yanitskiy d0be3909b8 gsm48_ie: fix gsm48_encode_bearer_cap(): encode bcap->data.transp
Currently this function is hard-coding the "Connection element (octet
6c)" (see Table 10.5.101h/3GPP TS 24.008) to "Transparent" (0).  This
breaks non-transparent data calls.

Use the value from bcap->data.transp.  The decoding equivalent of
this function needs no changes, it does populate this field already.

Change-Id: I7339908864e8a2aef6f2b48a108650167e413c7f
Related: OS#6110, OS#4394
2023-07-26 02:32:49 +07:00
Pau Espin a2d8bf8acc exec: osmo_system_nowait2(): Improve logging and error checks
Change-Id: I9b971dda389fe958627d41fa5ba6f45ee588bf99
2023-07-25 15:22:14 +00:00
Vadim Yanitskiy f93ef0c634 gsm_08_08: define GSM0808_SCT_EXT (separately)
As per 3GPP TS 48.008, section 3.2.2.103, the "Codec Type" field may
contain either a certain 3GPP Speech Codec Type directly (4 bit value),
or the so called "Codec Extension" = 0xFh, in which case the real Codec
Type follows in the next octet as "Extended Codec Type".

CSD is such an example, the encoding is defined as follows:

     8    7    6    5    4    3    2    1
  +----+----+----+----+-------------------+
  | -- | PI | PT | -- |        0xFh       |
  +----+----+----+----+-------------------+
  |      Extended Codec Type (CSData)     |
  +----+----+-----------------------------+
  | R2 | R3 |                             |
  +----+----+-----------------------------+

  CSData is coded with 0xFDh or '1111 1101' (0xfd).

Let's have the "Codec Extension" value clearly defined in the header
file, but intentionally separate from the other GSM0808_SCT_* values.

Change-Id: Iafaa25070684d2ba400c75fa33e803651a5ce857
Related: OS#6110, OS#4393, OS#4394
2023-07-25 04:23:12 +07:00
Pau Espin 547a65aae2 gsm: Add missing IE definition for GMM Receive N-PDU Number list
Change-Id: Ifac09653141758af345efe2eb9cef25ebf4dcff9
2023-07-18 18:02:46 +00:00
Daniel Willmann 97d21447f7 osmo_io: Fix length calculation in iofd_handle_segmentation()
We need to account for the fact that segmentation_cb() could have
changed the length by calling msgb_pull(). Calculate the new len
according to the new tail/data pointers.

Change-Id: I5486ddc0d3345e92b20cbc6e5bcf2cefea3958c8
2023-07-18 09:58:47 +00:00
arehbein 4ff5db2839 Revert "gsm/ipa: Add segmentation callback"
It has been decided that the segmentation callback be changed
and moved to libosmo-netif, so we remove it here.

This reverts commit 2c59d1285e.

Related: OS#5753
Change-Id: I9b380326c63587fc79d6a5d8cd458188074fc55d
2023-07-18 09:55:26 +00:00
Daniel Willmann d0d9ecbad1 osmo_io(cosmetic): End in a dot for doxygen AUTO_BRIEF
Change-Id: I397304eed524db12e60a6534d21ea268f304cfdc
2023-07-18 06:30:28 +00:00
Daniel Willmann 4731e71a79 cosmetic: Fix doc comment
Change-Id: Iec614004a0382534f4bfcc375f4d89192d7f27aa
2023-07-18 06:30:28 +00:00
Daniel Willmann a9303f3bce osmo_io: Add function to change the maximum length of the tx_queue
Change-Id: If3d1de8bffe1123002515878655ea9e02b482888
2023-07-18 06:30:28 +00:00
Daniel Willmann 7b59bab794 osmo_io: Document expectation that segmentation_cb() can modify msgb
This is used for parsing e.g. the ipa header and setting msg->cb.
Guard against segmentation_cb changing msg->data in
iofd_handle_segmentation().

Change-Id: Idd2115baae98a7818aabb26232d4423d2d48fb5c
2023-07-18 06:30:28 +00:00
Pau Espin a18f1d7be4 gsm0502.h: Document spec number
Change-Id: I3a3fdde39a4f3927516b9c160c04144764800fda
2023-07-17 10:53:07 +02:00
Pau Espin c3b772b61e socket: Cache errno before calling further functions
No issue is in principle expected with previous code since snprintf
doesn't seem to be setting errno according to "man snprintf", but better
be safe, specially in case someone calls the functions calling snprintf
in the future, or if snprintf sets errno in other implementations.

Change-Id: I6969be10db867b4821e05aed50bc22a7ccd4a633
2023-07-12 08:05:25 +00:00
Vadim Yanitskiy 9ec7749f01 lapdm: cosmetic: simplify lapdm_phsap_up(), use OSMO_PRIM[_HDR]
Change-Id: I87dedca0a38f290ae56649373dc9172433b8e4b1
Related: OS#3626
2023-07-10 09:53:00 +00:00
Vadim Yanitskiy fadda01f44 coding: implement encoding/decoding API for TCH/F2.4
See 3GPP TS 45.003 section 3.6.  This channel mode is a bit special,
because unlike the other CSD specific channel modes it's interleaved
over 8 (not 22!) consecutive bursts, just like TCH/FS.

Change-Id: I4685376c8deb04db670684c9ebf685ad6fc989fa
Related: OS#1572
2023-07-08 06:42:09 +07:00
Vadim Yanitskiy f8e570a20f coding: remove redundant memset()s in gsm0503_tch_fr{96,144}_encode()
Convolutional codes terminated with CONV_TERM_FLUSH (the default)
always append k-1 zeroes at the end to "flush" the encoder state.
This is the case for both TCH/F9.6 and TCH/F14.4.

Change-Id: I4a77ecb9af72b2fd4ea92c42d6748879e73d2cf2
Related: OS#1572
2023-07-08 06:05:13 +07:00
Vadim Yanitskiy 918b0ceb6f core: fix pointer access in msgb_l[1-4] macros
Put the 'm' pointer into braces, so that it's possible to pass an
expression to these macros, e.g. a pointer-to-pointer dereference.

This patch makes the following example compile:

  struct msgb **msg = /* ... */;
  return msgb_l2(*msg); /* <-- currently this fails */

Currently it fails with the following error:

 error: ‘msg’ is a pointer to pointer; did you mean to
        dereference it before applying ‘->’ to it?

Change-Id: I2d19ea3c09ff9499314255d408fb71c07148fe25
2023-07-07 22:21:28 +00:00