Commit Graph

1847 Commits

Author SHA1 Message Date
Vadim Yanitskiy c9fc77f541 soft_uart: implement the transmitter
Change-Id: Ibcd9643227e5616efd8bbd7a1430feda6fcef45c
Related: OS#4396
2023-11-21 00:58:53 +07:00
Vadim Yanitskiy 82a1ae785e soft_uart: make osmo_soft_uart_alloc() accept *cfg
Let the API user pass their own default config when allocating
a soft-UART.  Make the default config publicly accessible.

Change-Id: I7e78d60c747a8805064d5e4bacfd47a30bc65cba
Related: OS#4396
2023-11-21 00:58:53 +07:00
Vadim Yanitskiy cdde67186b soft_uart: split osmo_soft_uart_enable()
The problem with a single function controlling both Rx and Tx is
that enabling/disabling one of the directions requires knowing
state of the other one.  In other words, disabling Tx requires
knowing the state of Rx, which may be inconvenient.

Change-Id: Ieacc7e639304eeb14fdb298c7e14d772c136ca6e
Related: OS#4396
2023-11-21 00:58:53 +07:00
Vadim Yanitskiy 877cfed3b2 soft_uart: add osmo_soft_uart_free()
Change-Id: I2fdcf6116144d8f16cf4167c37cfa7215d16337f
Related: OS#4396
2023-11-21 00:58:53 +07:00
Harald Welte dc023cfc2e core: Add software UART implementation
This patch brings a Work-in-Progress implementation of the software
UART (Universal Asynchronous Receiver/Transmitter) to libosmocore.

Not only it will be useful in the context of retro-networking, but
also it's needed for the MS-side CSD implementation (see OS#4396).

It should be noted that the definition of struct osmo_soft_uart
is intentionally kept private, since the API is not stable yet.

Currently, the following limitations apply:

* Only the receiver part is implemented, the transmitter is TBD.
* Parity checking is not implemented in the receiver part.
* Software flow control is not implemented.

These missing components will be addressed in subsequent patches.

Change-Id: I2ca95963fd5852ddb89bdd35b86b31489127fe84
2023-11-21 00:58:53 +07:00
Vadim Yanitskiy d739e257bb coding: gsm0503_tch_a[fh]s_encode(): make *codec const
Change-Id: I9e37a47c080cf57005e0205aa0d3cd25755a75f0
2023-11-14 11:57:19 +00:00
Vadim Yanitskiy e0d0fff41f msgb: fix doxygen docs for msgb_pull_u{8,16,32): end -> front
Change-Id: Ie9851683fa9cc88cd7f6b63ad708b4f78c8f37c9
2023-11-12 14:24:11 +07:00
Andreas Eversberg 4ca0f62cc4 ASCI: Add primitive to L1-SAP to switch uplink access detection on or off
Related: OS#4851
Change-Id: Ibd6a1d468a70126a8f67e944fcb916969cc3c36b
2023-10-24 17:32:15 +02:00
arehbein 1584b2ac39 gsmtap: Hide implementation of gsmtap_inst
- Use forward decl. of struct gsmtap_inst in header
 - Remove 'static inline' attributes from gsmtap_inst_fd() declaration,
   move function definition to gsmtap_util.c and mark it as deprecated
 - Add gsmtap_inst_fd2() as replacement for gsmtap_inst_fd()

Related: OS#6213
Change-Id: Ibe1a51205a6df764571b6d074e365825555609a5
2023-10-13 01:33:46 +02:00
Pau Espin 64ba9edf17 socket: Introduce APIs osmo_sock_multiaddr_{add,del}_local_addr()
These APIs are used to bind or unbind an active socket adding or
removing addresses from the existing set.

Related: OS#6077
Change-Id: Ifc6e7d643c2a0c53f479bfd0d5c36d08c0c01953
2023-10-03 18:38:02 +02:00
arehbein 2a405d4f06 osmo_io: Clean up code
- Remove osmo_io_init() from header, since it has no function definition
 - Add osmo_iofd_init() to header

Change-Id: I77f7ae2b211507f420d87c484ec75ee054fceb63
2023-09-29 15:27:11 +00:00
Vadim Yanitskiy 15b76f068d gsm: rename s/gsm0502_fn_compare/gsm0502_fncmp/
Change-Id: Ie8bb9c49c6f81b8f4a1766547d6943f9880d1186
Related: OS#5500
2023-09-26 11:03:49 +00:00
Pau Espin d9a5c8d32f sockaddr_str.h Fix OSMO_SOCKADDR_STR_FMT_ARGS_NOT_NULL syntax error
It's fine changing the define because due to the previous error it means
basically that it was never used so far, because using it triggers a
compilation error.

The error was introduced because I ended up not using this in the past
after submitting this code, and now that I want to use it it went
noticed that it fails.

Change-Id: Iee361d740845257fa62c9093e30e8079fa933827
2023-09-26 10:50:55 +00:00
Vadim Yanitskiy 5285d47548 gsm: add gsm0502_fn_compare() for comparing TDMA FNs
We need this function in:

* osmocom-bb.git for trxcon and l1gprs,
* osmo-pcu.git replacing fn_cmp().

Change-Id: I9590f2e836fc48650decf1564b6ab46306c4fe2d
Related: OS#5500
2023-09-25 23:58:40 +07:00
Manawyrm 522f51b9d8 gsmtap.h: Add definitions for ISDN PPP sub-type
This change adds a new sub-type for PPP in GSMTAP_TYPE_E1T1.

Change-Id: I17137167b2c74b6c5e53459743b6e140fc1a4386
2023-09-20 16:10:57 +00:00
arehbein ae07127f73 write_queue: Enable updating max_length field
Dequeue and free any excess messages, in case the new queue length
is shorter than the old.

Related: OS#5774
Change-Id: Ibfe51a2faf29f8ae160a9c330c9af0d09b5a9002
2023-09-19 18:46:09 +00:00
Mychaela N. Falconia d5c6651ae0 gsm/protocol/gsm_04_11.h: add SMSC-address length limit definitions
Change-Id: Iea5c29909c5be80f81dbbc2873656ff5cf590a5d
2023-09-18 19:07:51 +00:00
Andreas Eversberg 84d5a825a4 ASCI: Add definition for TALKER INDICATION and UPLINK RELEASE
Change-Id: I5ab196d46cdee160e59ee4ecf72c79aa1b25815f
2023-09-12 10:42:48 +00:00
Andreas Eversberg 0267b34290 ASCI: Add BCC call state definitions
BCC and GCC share same call states, except for two states that have same
value, but different state names and conditions.

Related: OS#5364
Change-Id: I2180b43b940542565188f52c554c960858fe2a95
2023-09-12 10:42:48 +00:00
Vadim Yanitskiy 13c29c7c73 gsm_12_21.h: fix typo: NM_IPAC_F_CHANT_P{C->D}CHF
Change-Id: I35ee30978820f2038f562b7703ca886852a4f708
Fixes: a7d7cf28 "gsm_12_21.h: add flags for NM_ATT_IPACC_SUPP_FEATURES"
2023-09-12 05:16:32 +07:00
Pau Espin a45b0be25f socket: Support setsokopt SCTP_INITMSG in osmo_sock_init2_multiaddr2()
This allows setting several socket paramets which can only be set before
SCTP INIT phase (connect()).

Since no release with osmo_sock_init2_multiaddr2() happened yet, we are
allowed to extend struct osmo_sock_init2_multiaddr_pars without bumping
the version field.

Related: SYS#6558
Change-Id: Ibc55932d954279927d1e70ccce1e8bf32b180d44
2023-09-08 13:49:59 +02:00
Pau Espin 658c509061 socket: Remove OSMO_SOCK_F_SCTP_ASCONF_SUPPORTED, add osmo_sock_init2_multiaddr2()
The OSMO_SOCK_F_SCTP_ASCONF_SUPPORTED flag was added recently to enable
use of ASCONF in osmo_sock_inti2_multiaddr. Since we didn't release yet,
we are still in time to get rid of this flag.

It turns out that we'll want to add more features which must be set
before SCTP INIT (connect()) time, like setsockopt SCTP_INITMSG, which
in turn contains a struct with several parameters.
Hence, adding flags for all those makes no sense.
Instead, add a new API which allows passing an extensible struct which
allows much more fine-grained setup from the caller.

The new struct "pars" parameter is non-const on purpose, in order to be
able to extend the struct in the future if we wish to get/obtain some
data from the socket.

Related: SYS#6501
Related: SYS#6558
Change-Id: I1f6fd09a79b0a2bd794e5669d933be25bbf1eeaa
2023-09-08 13:49:08 +02:00
Vadim Yanitskiy a7d7cf284d gsm_12_21.h: add flags for NM_ATT_IPACC_SUPP_FEATURES
Change-Id: Ia4208e10d61843dd6ae77398f6624c918dc81ea4
2023-09-05 19:04:58 +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 f91d2aac9d osmo_io: Add io_uring backend
Change-Id: I5152129eb84b31ccc9e02bc2a5c5bdb046d331bc
2023-08-24 17:33:19 +02: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
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
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 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
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 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
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 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
Daniel Willmann e2a8dc4131 osmo_io: Add osmo_iofd_notify_connected()
Don't call write_enable() in osmo_iofd_register(). This was used to
detect whether a socket is connected or not, but would always be
enabled, even on unconnected sockets. Instead make this behaviour
explicit by calling osmo_iofd_notify_connected().

Change-Id: Ieed10bc94c8aad821c0a8f7764db0e05c054c1e3
2023-06-30 13:57:05 +02:00
Vadim Yanitskiy 418d76c2cb gsm: add gsm0502_fn2ccch_block()
This API is useful for checking whether a Downlink CCCH block belongs
to PCH or AGCH.  We need this API in osmo-bts.git and osmocom-bb.git.

Change-Id: I8cbd31226754e95887358ed83a928e2f567f4cf3
Related: OS#5500
2023-06-25 08:45:26 +00:00
Mychaela N. Falconia 315e78aab1 ecu: add is_dtx_pause() method
The ECU API of libosmocodec is unfortunately a peculiar non-3GPP
entity: an ECU by itself, severed from Rx DTX handler functions,
which is a logical/conceptual function with no place in the standard
3GPP architecture.  The closest thing that exists in the standard
architecture is the TFO spec (TS 28.062 section C.3.2.1.1) calling
for an ECU application, but not comfort noise generation, in the case
of destination leg doing DTXd - but even then it is not a totally
"pure" ECU like libosmocodec API, it is an ECU plus a SID preener,
and the SID preening transform is not possible within the constraints
of existing libosmocodec ECU API.  Hence truly correct handling of
corner cases, particularly invalid SID, is sadly impossible in the
current libosmocodec ECU framework.

The only current user of this API is the UL path in osmo-bts-trx;
however, as described in OS#6040, we would like to move that ECU call
from osmo-bts-trx model-specific code to the common layer of osmo-bts.
The current osmo-bts-trx incarnation avoids the SID handling problem
by suppressing the call to ECU frame_out() after any SID (valid or
invalid) was received on the air, thus pausing the RTP stream instead
of emitting ECU output during DTXu pauses.  We would like to retain
the same behavior when we move this ECU call to the common layer,
into its proper place _after_ the link quality check in l1sap - but
the current method of flagging post-SID state in osmo-bts-trx will
no longer work on the other side of that link quality check.

As a workaround, have the ECU remember via a separate Boolean flag
whether it is in post-SID state or not (was the most recent frame_in()
any kind of SID or not), and provide is_dtx_pause() method to
retrieve this flag - the relocated ECU call in osmo-bts UL path
will use this new is_dtx_pause() method call to decide if it should
call frame_out() or switch to pausing RTP output.

Related: OS#6040
Change-Id: I3857be84bba12aaca0c2cca91458b7e13c5a642a
2023-06-23 18:42:11 +00:00
Andreas Eversberg 29a9fc010c Add VGCS UPLINK GRANT message structure to gsm_04_08.h
Change-Id: I8a16ce4ddc7a36e0db2936227a910b4d53cddfca
2023-06-21 11:04:22 +00:00
Pau Espin 63e45e6c6a osmo_io: Make name optional, add _set_name() API
This allows renaming the iofd at any later point in time. This is useful
for instance if the parent object holding the iofd changes its name.

Change-Id: If2772a3ccaa98616e0189862a49ab0243435e343
2023-06-20 07:16:41 +00:00
arehbein 2c59d1285e gsm/ipa: Add segmentation callback
Add segmentation callback to be used by the streaming backend of libosmo-netif

Related: OS#5753, OS#5751
Change-Id: I3a639e6896cc3b3fc8e9b2e1a58254710efa0d3f
2023-06-19 18:30:47 +00:00
Andreas Eversberg a0635fc4f5 ASCI: Add Notification/NCH message to gsm_04_08.h
This message is (the only message) used on the NCH to notify the MS
about all currently ongoing voice group/broadcast calls.

Change-Id: Iff1555a2914ce0a1ead6ab883498adb2c33b135e
2023-06-09 15:06:34 +00:00
Andreas Eversberg 86efdf4ad1 Fix short L3 header of SI 10 at gsm_04_08.h
Change-Id: I1c3002716b08e31016cc6e623f8f8a413ef7916f
2023-06-09 15:06:34 +00:00
Andreas Eversberg bfb917f566 Add short L3 header to gsm_04_08.h
Change-Id: I0eceb380e401e1f842edbaa92f4b4738703a031c
2023-06-09 15:06:34 +00:00
Andreas Eversberg 532b8e92c5 ASCI: Add message definition and encoding according to 3GPP TS 48.008
Change-Id: Ib94c64136c31ce4af67c314a8550d93946cc844f
2023-06-09 15:06:34 +00:00
Andreas Eversberg bb20d4e703 Added generation of include/osmocom/core/socket_compat.h
This file is required to compile header files on machines that do not
have sys/socket.h.

Change-Id: Ia3eafc992221900bbbf1760f669725bf9da92105
2023-06-09 15:06:34 +00:00
Neels Hofmeyr 8d42394c89 improve API for osmo_routing_area_id
Code review for [1] has asked for providing proper API for struct
osmo_routing_area_id.

For historical reasons, we have struct gprs_ra_id and
struct osmo_routing_area_id serving the exact same purpose: represent a
decoded 3GPP TS 24.008 § 10.5.5.15 Routing area identification.

The "better" one is struct osmo_routing_area_id: it allows using API
like osmo_plmn_cmp(), because it is made up of meaningful sub-structs.

Implement de/coding using the functions already available for the
sub-struct osmo_location_area_id, and simply add the RAC.

Add a test in gsm0408_test.c.

Note that other utility functions are already available for struct
osmo_routing_area_id: osmo_rai_name2(), osmo_rai_cmp().

There is no real need to deprecate struct gprs_ra_id, because there is
not really anything wrong with it. It just isn't as well integrated with
other utility API as struct osmo_routing_area_id is. Just add comments.

[1] osmo-hnbgw.git:
    cnpool: extract Mobile Identity from RANAP payload
    https://gerrit.osmocom.org/c/osmo-hnbgw/+/33133
    I373d665c9684b607207f68094188eab63209db51

Change-Id: Ic5e0406d9e20b0d4e1372fa30ba11a1e69f5cc94
2023-06-08 00:55:40 +02:00
Daniel Willmann eb9edbab54 osmo_io: Remove osmo_iofd_read/write_enable/disable
This API is not really used or needed, so remove it.
See discussion in https://gerrit.osmocom.org/c/libosmocore/+/33084

Change-Id: I0dbc14a8cbbdc7b6e4688942c0dac865bbd72c8b
2023-06-07 15:04:47 +02:00
Daniel Willmann 3ed87720b3 osmo_io: Don't make msg in write_cb const
This was discussed in a previous change, but the change was merged
as-is.

Change-Id: I8b4a2dd7a336dea5c52c9da6e78bbc4d5f2a02f8
2023-06-07 15:00:02 +02:00
Daniel Willmann 2dd8da6b98 osmo_io: Consistency - put read/recv callback first in osmo_io_ops
Change-Id: I70002a83c647854e0f2e30c0f6f82a2b0c63f114
2023-06-07 14:32:29 +02:00
Vadim Yanitskiy 3ada0bd15e struct osmo_sub_auth_data: remove OSMO_DEPRECATED_OUTSIDE
I was the one who suggested adding this attribute during code review,
and now, having realized it was a bad idea, I am removing it.  The
problem is that this attribute spams compilation logs of projects
including file <osmocom/crypt/auth.h>, even if the deprecated struct
is not used directly at all.

Change-Id: Ia5d365206207872d5d3fdd4ae40273eab909fb33
Fixes: 08450c9e "libosmogsm: Support authentication with 256-bit K and/or OP/OPc"
2023-06-05 18:33:52 +00:00
Harald Welte 8bd9d5d7a3 libosmogsm: Add support for TUAK authentication algorithm
The TUAK algorithm is specified in 3GPP TS 35.231, 232 and 233 and
intended as an alternative to MILENAGE.  It's based around the
cryptographic function of KeccakP1600, which is part of SHA-3.

This patch adds support for TUAK to the libosmogsm authentication
core API via 'struct osmo_auth_impl'.

Unit tests covering the test cases from the 3GPP specification are added
(and are all passing).

Change-Id: Ib905b8d8bdf248e8299bf50666ee1bca8298433d
2023-06-02 10:44:05 +02:00
Harald Welte 76f4c5cf5c libosmogsm: Factor out the C2 derivation function
3GPP specifies the C2 derivation function (generating GSM SRES from UMTS XRES)
independent of the MILENAGE algorithm.  So instead of open-coding it in
milenage.c:gsm_milenage(), let's create a separate public function
osmo_auth_c2() similar to the already-existing osmo_auth_c3() function.

gsm_milenage() can then simply use that function.

Change-Id: I0e7cd55f5578f891cb6cc1b0442920ba5beddae4
2023-06-02 08:29:55 +00:00
Harald Welte d8e5309527 libosmogsm: Allow auth API caller to specify RES length
There are 3G algorithms which support different lengths of RES values
(4, 8, 16 byte).  For MILENAGE, we never really had to bother, as
the 4-byte RES is simply the first 4 bytes of the 8-byte RES.

However, for TUAK, the expected RES length is an input parameter to
the Keccak crypto functions, so the result of all parameters (including
CK, IK, ...) will be completely different for RES length 4 than RES
length 8.

So let's permit the caller of the osmocom auth API to specify the
requested RES length via the osmo_auth_vector.res_len parameter.

For backwards compatibility of callers of the old osmo_auth_gen_vec/
osmo_auth_gen_vec_auts API: Always force the res_len to 8 in this case,
which was the hard-coded length before this patch.

Change-Id: Ic662843fbe8b5c58e4af39ea630ad5ac13fd6bef
2023-06-02 08:29:55 +00:00
Harald Welte 08450c9ec6 libosmogsm: Support authentication with 256-bit K and/or OP/OPc
3GPP TS 33.102 Section 6.3.7 states that K can be 128 or 256 bits,
while our 'struct osmo_sub_auth_data' had a fixed-size 128bit field.

This means we cannot use our auth_core for algorithms with larger
key sizes, such as TUAK.  Let's introduce osmo_sub_auth_data2 for
larger (and variable) sized K and OP[c].

K and OP[c] can even have different sizes in TUAK, where OP[c] is
always 256bit, but K can be 128 or 256 bits.  So we need separate
length fields for K and OP[c].

I'm adding backwards-compatibility API wrappers, so old applications
just continue to work as they always did.

However, I'm not adding compatibility wrappers for the plug-in API
that can be used to register additional authentication implementations
at runtime.  We don't know of any user of that API outside of
libosmocore, so the function signatures of the 'struct osmo_auth_impl'
are modified in an incompatible way.

Change-Id: Ie775fedba4a3fa12314c0f7c8a369662ef6a40df
2023-06-02 08:29:55 +00:00
Andreas Eversberg 5c7336ce88 ASCI: Add IE transcoding according to 3GPP TS 48.008
Change-Id: Ic1fc714bb04228a7f32e9925811e21c8efc610bd
2023-06-02 08:28:49 +00:00
Andreas Eversberg 19b0bb7dd2 ASCI: Add 3GPP TS 44.068 and 44.069 protocol definitions
Change-Id: I3554cea47e714c8fca18c3e9c0e6e80695915a90
2023-06-02 08:28:49 +00:00
Mychaela N. Falconia 18e5af55be codec: new function osmo_hr_sid_reset()
If a network element that receives call leg A UL and is responsible
for preparing leg B DL receives a GSM-HR SID frame whose SID field
is not all 1s but which is marked as valid SID by out-of-band means
(TRAU-UL frame control bits or the FT field in RFC 5993 ToC octet),
this SID frame should be rejuvenated (SID field reset to all 1s)
prior to retransmission on call leg B DL.  Provide a function
that performs this operation.

Related: OS#6036
Change-Id: Iebc0863ffcc3f8f25aeb54d4b14fac0487bc2bbb
2023-05-27 10:51:17 +00:00
Mychaela N. Falconia 2974a23c75 codec: new functions osmo_{fr,efr}_sid_reset()
In Iec5c1f2619a82499f61cb3e5a7cd03ff0f020ad8 we added
osmo_{fr,efr}_sid_preen() functions that apply SID classification
of GSM 06.31/06.81 section 6.1.1 (osmo_{fr,efr}_sid_classify()),
reject invalid SID, and "rejuvenate" deemed-valid SID frames by
resetting their SID code word, correcting the one bit error that
may be present in a deemed-valid SID frame.  However, the last
operation (rejuvenation of a SID frame by resetting its SID field)
should also be made available as its own function, as it may be
more efficient in some applications: for example, an application
may need to call osmo_{fr,efr}_sid_classify(), apply the rejuvenation
to valid SID, but also use the classification result to drive other
logic.  Factor out these functions.

Change-Id: I1d6dd867a358bdda8850cd8c959d0f361c0a5b6d
2023-05-27 10:49:41 +00:00
Vadim Yanitskiy b334022aba coding: implement dedicated codec API for FACCH/[FH]
Currently FACCH/[FH] encoding and decoding is implemented as part of
the gsm0503_tch_[fh]r_{en,de}code and gsm0503_tch_a[fh]s_{en,de}code
API.  This works fine for speech because one FACCH frame completely
replaces one or two speech frames, but this is not the case for CSD.

According to 3GPP TS 45.002, sections 4.2.5 and 4.3.5, for TCH data
channels FACCH does not replace data frames but disturbs some amount
of bits from them.  Therefore we need to be able to perform FACCH
encoding and decoding independently from CSD specific coding API.

Change-Id: I0c7a9c180dcafe64e6aebe53518d3d11e1f29886
Related: OS#1572
2023-05-26 02:35:11 +07:00
Vadim Yanitskiy 9a22827cf6 coding: implement TCH/F9.6, TCH/[FH]4.8, TCH/H2.4, TCH/F14.4
Implement all CSD specific channel modes, except TCH/F2.4.  All of
these modes are more or less similar to each other.  The TCH/F2.4
is more similar to TCH/FS and slightly more complicated.

FACCH/F and FACCH/H will be implemented in a follow-up change.

Change-Id: Ib482817b5f6a4e3c7299f6e0b3841143b60fc93d
Related: OS#1572
2023-05-25 19:08:53 +07:00
Mychaela N. Falconia 57a3b3a51f gsm0503_tch_hr_decode2(): new function, emits TS101318 format
The original design of gsm0503_tch_hr_{en,de}code() functions contains
a mistake in that a pseudo-RFC5993 format was chosen for HR codec frame
input and output, instead of "pure" (agnostic to outer RTP encoding)
form of 14 bytes.  We would like to change this design so that we can
feed pure 14-byte HR codec frames to the channel coding function and
get such frames back from the channel decoding function - however,
we cannot break libosmocoding API for existing users.  In the decoding
direction, create a new function that emits TS 101 318 format, and
turn the legacy gsm0503_tch_hr_decode() API into a wrapper function
for backward compatibility.

Related: OS#5688
Change-Id: If28ddb20789e8993b7558ca08020478615b4c708
2023-05-23 16:42:01 +00:00
Neels Hofmeyr a9c29b45ea gsm_04_08_gprs: add IEI "GMM TMSI Based NRI Container"
OsmoHNBGW will need to obtain the NRI from GMM Attach Request and GMM
RAU Request to implement CN pooling.

Related: SYS#6412
Change-Id: Id661abfdb2c81a92c9046542bbc08d6ccd39f073
2023-05-22 15:35:02 +00:00
Harald Welte 1dffb53aac gsm_08_58.h: Add 'struct rsl_ie_nch_drx_info'
This adds the definition of 'struct rsl_ie_nch_drx_info' representing
the bit-field of the 'NCH DRX Information IE' of A-bis RSL.

Change-Id: I9586b5cb8514010d9358fcfc97c3d34741294522
Related: OS#5781
2023-05-22 10:33:10 +00:00
Harald Welte 8079a0636e cosmetic: Fix spec reference in RSL header file
Change-Id: I671ee927b49099f7c8cc1fbd5f8b19f94ba1af81
2023-05-22 10:33:10 +00:00
Harald Welte 1192687620 Add osmo_gsm48_si1ro_nch_pos_{encode,decode} functions
These functions encode/decode the NCH position field within the SI1
rest octets.  This is used within ASCI (VBS/VGCS).

Change-Id: I24a0095ac6eee0197f9d9ef9895c7795df6cdc49
Related: OS#5781
2023-05-22 10:33:10 +00:00
Vadim Yanitskiy 242ef1bdea coding: declare gsm0503_tch_f96_[de]interleave()
Change-Id: I9a631db088a4e279668beb962c98cc1a0929f44d
Related: OS#1572
2023-05-20 19:06:11 +07:00
Daniel Willmann d4d03705f9 osmo_io: Improve handling and documentation of segmentation_cb
The read length is not needed in the segmentation callback, msgb
already has all the necessary information, the parameter previously was
just msgb_length(msg).

Also handle negative return values (except -EAGAIN) of the callback as
errors which cause the msg to be dropped. -EAGAIN will defer the msg.

Change-Id: I6a0eebb8d4490f09a3cc6eb97d4ff47b4a8fd377
2023-05-19 12:50:21 +00:00
arehbein 0c374c68a1 core: Add function to update osmo_io_ops field for osmo_io_fd
Added, because the field 'io_ops' of 'struct osmo_io_fd' is not a
reference, so subsequent changes to the osmo_io_ops structure that was
used to set it up aren't automatically reflected in the osmo_io_fd
structure that got its copy.

Change-Id: Ie45402ad8e86e3cecf75ad78a512c17e61e68b19
2023-05-19 12:50:24 +02:00
Mychaela N. Falconia 5eb356be99 codec: replace GSM-FR ECU with new implementation
The original GSM-FR ECU implementation from 2017 exhibits a lot of
defects, as detailed in OS#6027.  Replace it with a new implementation
based on Themyscira libgsmfrp (a complete Rx DTX handler for GSM-FR),
but reduced to just the ECU function, without the comfort noise
generator function.  (These two functions are coupled together in the
classic GSM architecture, but not in libosmocodec ECU model.)

Related: OS#6027
Change-Id: I0200e423ca6165c1313ec9a4effc3f3047f5f032
2023-05-17 13:53:20 +00:00
Mychaela N. Falconia f86ec508e9 codec: add osmo_gsm611_silence_frame[] datum
Table 1 in section 6 of 3GPP TS 46.011 (FR codec, substitution and
muting of lost frames) specifies a silence frame in the form of
GSM 06.10 parameters - add a const datum to libosmocodec embodying
this GSM 06.11 silence frame in GSM-FR RTP encoding.

Related: OS#6027
Change-Id: Idf31051ea783435268944286a71d2b0ac342a4b5
2023-05-10 18:18:42 +00:00
Harald Welte 8857f3b798 Add osmo_io with initial poll backend
* make backend configurable for later
* segmentation callback for chunked streams
* logging target for osmo_io
* support partial writes

Change-Id: I50d73cf550d6ce8154bf827bf47408131cf5b0a0
Related: SYS#5094, OS#5751
2023-05-10 06:04:57 +00:00
Mychaela N. Falconia 341c4ec3a4 codec: add osmo_{fr,efr}_is_any_sid() inline functions
Recently added osmo_{fr,efr}_sid_classify() functions classify FR
(EFR) codec frames according to the rules of GSM 06.31 (06.81)
section 6.1.1.  Both of these specs also define the term "accepted
SID frame", encompassing both valid and invalid SID frames, but not
regular speech frames.  A boolean check for this wider category of
"accepted SID frame" is a useful function - many existing calls to
legacy osmo_{fr,efr}_check_sid() functions should be converted
to this "accepted SID frame" check for full correctness.  Add wrapper
functions for convenience, and to allow this transition to be made
without adding bloat to every use instance.

Change-Id: I5e6e91baf18440af01dccc6ac0171476a8a5c71c
2023-05-09 07:51:12 +00:00
Neels Hofmeyr e25786ab6a gsm: add osmo_mobile_identity_decode_from_l3_buf()
We have osmo_mobile_identity_decode_from_l3(), which takes a msgb as
argument, and decodes msg->l3h. Not all callers have their data in this
form. Offer a more flexible API for the same decoding.

For example, before the new function, osmo-hnbgw, which extracts a NAS
PDU from asn.1 packed data for CN pooling, would allocate a new msgb and
copy the NAS data just to pass a data pointer as argument.

Related: SYS#6412
Change-Id: I9bd99ccd01f0eedc091fe51687ff92ae1fdff60b
2023-05-06 03:49:08 +00:00
Neels Hofmeyr e4b84738b5 vty: move struct vty_parent_node to private API
Change-Id: Id2070f03b09feea966c5342361d409551e557d38
2023-05-06 03:49:08 +00:00
Neels Hofmeyr 67d84d2131 vty: fix vty->index for implicit go_parent_node
After this patch, most vty_go_parent() functions are really obsolete, as
originally intended: A vty_go_parent() is only needed if the program
requires an action to run on VTY node exit.

vty_transcript_test.vty shows the fixed behavior.

For details, see preceding patch
"vty: show bug in implicit go_parent_node"
I2472daed7436a1947655b06d34eb217e595bc7f3

Change-Id: Id408c678d18ba19b1c1394c3fb657536153d2094
2023-05-06 03:49:08 +00:00
Philipp Maier 4cf72df3f9 codec: add define constants for RFC5993 and TS101318
The difference between the RFC5993 and the TS101318 format is only that
RFC5993 has one additional ToC (Table of contents) byte at the
beginning. However it can be difficult to remember which of the two
formats has the ToC byte at at the beginning and which hasn't.

Let's add a constant that defines the length for both formats so that we
can make it more clear in the code which format we are refering to.

Related: OS#5688
Change-Id: I125ef9cdab98c073971841c175b1a7dcd927f9c2
2023-05-04 00:10:47 +00:00
Pau Espin f6ef9ba1e9 gb: ns2: Rename parameter name in gprs_ns2_nsvc_by_sockaddr_bind()
The old name seems to describe that this function can only be used in
incoming message paths, but it can be used in transmitting context too,
so the param is actually a remote address.

Change-Id: I3f45a4ef339cadd47920ee3b36c38628b38221f6
2023-04-27 17:52:16 +02:00
Pau Espin 550fdf8b6b gsm_04_08_gprs.h: Add enum field for GMM 'P-TMSI type' IE
Change-Id: Ief4e03785f01f07c8d97b33bbb55c89a863baccc
2023-04-25 18:37:36 +02:00
Mychaela N. Falconia 295636b320 codec: add SID preening functions for FR & EFR
Those network elements which receive a stream of codec frames that
may come from the uplink of GSM call A and which are responsible
for preparing the frame stream for the downlink of GSM call B
(OsmoMGW feeding TRAU-DL, or OsmoBTS receiving RTP and feeding DL
to its PHY) must be prepared for the possibility that their
incoming frame stream may contain corrupted SID frames, presumably
from bit errors on radio link A.  Per the rules of section 6.1.1
of GSM 06.31 for FR and GSM 06.81 for EFR, SID frames with just one
errored bit are still to be accepted as valid, whereas frames with
more corrupted bits which are still recognizable as SID are classified
as invalid SID.

In the case of a TrFO call, the entity switching from leg A UL to
leg B DL is responsible for *not* transmitting invalid SID frames
on the destination leg (they should be treated like BFIs), and any
deemed-valid SID frames that are forwarded should be preened,
correcting that one bit error they may exhibit.  The functions
added here provide that functionality.

Change-Id: Iec5c1f2619a82499f61cb3e5a7cd03ff0f020ad8
2023-04-17 17:19:25 +00:00
Mychaela N. Falconia ec65085d5f codec: add SID classification functions per GSM 06.31 & 06.81
The existing osmo_{fr,efr}_check_sid() functions detect whether or not
the frame of bits passed to them constitutes an absolutely perfect
SID frame, with each of 95 SID code word bits set to 0 for FR or
1 for EFR.  However, the rules of section 6.1.1 in GSM 06.31 & 06.81
allow up to one bit to be in error for the frame to be accepted as
valid SID, and the same rules also call out a third state (invalid SID)
in between valid SID frames and other frames that are classified as
speech.  Support for these rules cannot be patched into those familiar
osmo_{fr,efr}_check_sid() functions because doing so would alter
behavior of existing programs, hence new functions need to be added.

The new functions that implement the exact rules of section 6.1.1 of
GSM 06.31 and 06.81 will need to be used if anyone needs to construct
an outgoing TRAU-UL frame (for example, as part of implementing
TS 28.062 TFO), and they are expected to be useful as part of more
sophisticated ECU implementations.

Change-Id: Ie91a52c6f04689082d8004311517d8ce0c544916
2023-04-16 01:34:35 +00:00
Pau Espin 5e79a302d5 gsm_04_08_gprs.h: Add missing GMM IEs for T3302 and T3346
As specified in TS 24.008 9.4.4 "Attach reject"

Change-Id: I2d36d76ee6fe8ed1a36e37a7d74fbbdc9c27c2c7
2023-04-13 13:46:34 +02:00
Vadim Yanitskiy 37dc995234 core: remove unnecessary #include <osmocom/core/talloc.h>
Including this header just for TALLOC_CTX is an overkill, we use
'void *' for talloc contexts in nearly all other Osmocom projects.

Change-Id: I4b9ffd7a329081df3d2c0b0ee8698a3cf759e94e
Related: OS#5960
2023-03-31 05:39:24 +07:00
Pau Espin ec7d5029ef gsm: Add missing TS 24.008 SM layer IEs
Change-Id: Iec0dbf617c8d0f2c8c44156d936244cedda9b303
2023-03-28 18:22:09 +02:00
Mychaela N. Falconia 7f91880534 codec: add osmo_efr_check_sid() function
Previously existing code provides osmo_fr_check_sid() and
osmo_hr_check_sid() functions for FR1 and HR1 codecs; these functions
are used by various RTP-touching programs in the Osmocom CNI suite
when they need to differentiate between speech and SID frames.
However, there was no corresponding function of this form for EFR
codec, with the result being that the same programs that handle
speech vs SID distinction correctly for FR1 and HR1 fail to do so
for EFR.

The present change adds an osmo_efr_check_sid() function to libosmocodec
that fully mirrors previously existing osmo_fr_check_sid() and
osmo_hr_check_sid(), providing the first step toward more correct
EFR handling in programs where a SID check may be needed.

Change-Id: Iab9fb60028f4135375287bc42f5da7ca7838b5f0
2023-03-25 08:04:04 +00:00
Harald Welte 8969298a77 rate_ctr: Add rate_ctr_add2() similar to rate_ctr_inc2()
The convenience wrapper relieves the caller from manually resolving
the individual counter, and instead specify just the counter group
and the index.

Change-Id: If93e8b4fb0b86a87358f32d2b45438ca1887e9f3
2023-03-24 14:08:08 +01:00
Harald Welte 5e3aaf9f0d gsmtap.h: Define a packet type for encapsulation of GSM RLP frames
This allows us to feed RLP frames (occurring in GSM CSD) into wireshark
for dissection.

Change-Id: Ibb7f0731c31e5a5cd2911f733da5510ce0f3a1d6
2023-03-24 13:07:58 +00:00
Vadim Yanitskiy c57cc4bf64 gsm0808: handle new enum gsm48_chan_mode speech/data values
Change-Id: I87d977228b1e039c2876941d1c6df1f69d1a54d4
Related: OS#1572
2023-03-23 18:38:11 +07:00
Vadim Yanitskiy 173c84c52e gsm_04_08: add more enum gsm48_chan_mode data values
From 3GPP TS 44.018 (version 15.4.0), table 10.5.2.6.1.

Change-Id: Ia6b428e5b6aaecf151cbfa980b89eff6d0fe6006
Related: OS#1572
2023-03-23 18:38:11 +07:00