Commit Graph

4742 Commits

Author SHA1 Message Date
Andreas Eversberg 285f3693de Add flag to enable RTS based polling
RTS based polling in LAPDm code is disabled by default. Make libosmogsm
stay compatible with existing applications that do not use RTS based
polling.

This patch fixes the issue that LAPDM_ENT_F_POLLING_ONLY did enable RTS
based polling too, which breaks existing applications like older
versions of osmo-bts.

Change-Id: I2a75c192bbc24e85bfc1656b2be21cea7a92814a
2023-11-29 14:19:48 +01:00
Andreas Eversberg 5560c040bd Fix union abis_rsl_chan_nr and abis_rsl_link_id
All bit fields in a union will overlap in memory, as all elements in a
union do. To prevent the bit fields from overlapping, wrap them into a
packed structure.

Change-Id: I5ef5aa62be8310da4ebe9ea73ebbedcbcc2ba49c
2023-11-29 10:15:33 +00:00
Harald Welte d6e16decad libosmosim: Support Microsoft smart card discovery process
Our class/instruction tables (used mainly by simtrace cardem host
software) only contain support for those instructions permitted
in the related card specification.

Microsoft blindly tries CLA=0xCA with INS=0x00 which is not somethin
that the GSM SIM, ETSI UICC or 3GPP USIM specs specify, and which
hence results in log output like this:

DLINP DEBUG [0] <= osmo_st2_cardem_request_sw_tx(sw=6a88)
DLGLOBAL INFO => DATA: flags=0x01 (HDR ), 00 ca 7f 68 00
DLGLOBAL ERROR Unknown APDU case 0
DLGLOBAL FATAL Failed to recognize APDU, terminating

Let's adjust to microsoft and *always* support their instructions
no matter which osim_cla_ins_card_profile was used.

Special thanks to Eric Wild for pointing me to this unexpected
behaviour of PC/SC on modern Windows.

Change-Id: I424964c0afab643e6a5d7824d91c2c86b0d3f25b
Related: SYS#6617
2023-11-28 22:50:01 +01:00
Harald Welte 42602ec932 sim/class_tables: Prevent out-of-bounds access
The INS tables always must be declared with 256 elements, even
if they only use some of them.  We never know which random INS
code might be used to index them.

This was not discovered until now as the only known user of those
tables is always using the SIM/UICC/USIM table and not the plain
ISO7816 table.

Change-Id: I6739f469f6e84eed9aab403cc481ebff86df0181
2023-11-28 21:22:19 +00:00
Alexander Couzens 505f70552a gsup: add message type for osmo-epdg CEAI interface
The CEIA interface is an interface between osmo-epdg and
strongswan.
It is used by the osmo-epdg to synchronize state.

Related: OS#6091
Change-Id: I6f7c20340c99f94b1326a8a7dc99c86cf6a0dbc3
2023-11-28 17:05:22 +00:00
Andreas Eversberg ebdf3dcac7 coding: gsm0503_tch_{afs,ahs}_encode(): add ability to emit BFI
Similar to Change ID Iade3310e16b906efb6892d28f474a0d15204e861, add
BFI support to TCH AFS and TCH AHS encoder.

Every BTS needs to have some graceful handling for the scenario
where it is time to send out a speech frame on TCH DL, but there is
no frame to be sent. One possible solution is to transmit dummy
FACCH, but this option is unattractive for TCH/AHS where FACCH
displaces two speech frames rather than one. A more elegant solution
is to emit a speech frame with inverted CRC6, causing the MS receiver
to declare a BFI condition to trigger substitution and muting procedure.
Setting all u(k) bits to 0 is one way to produce such an inverted-CRC
speech frame (normal TCH FR/HR CRC6 for an all-zeros frame would be
111111). This patch adds the abiliy to gsm0503_tch_{afs,ahs}_encode()
functions, indicated by payload length of 0.

See §6.2 of 3GPP TS 26.191 for substitution and muting procedure.

Related: OS#6049
Change-Id: I82ce2adf995a4b42d1f378c5819f88d773b9104a
2023-11-27 16:27:32 +00:00
Andreas Eversberg 6cc5301e4c LAPD: Indicate sequence error after indicating received data
First indicated the received data in an I frame, if possible. Then
indicate the sequence error using MDL-ERROR-INDICATION. This way the
data is delivered before the error is handled by BSC.

Also there is no reason to indicate sequence error on supervisory
frames.

See §8.7.4 of 3GPP TS 44.006.

Related: OS#5968
Change-Id: I535c18018bf0df4124a5e9618238028fa31be289
2023-11-27 16:25:53 +00:00
Andreas Eversberg bd2b897b72 LAPDm: Add a flag to enable suppression of subsequent REJ frame
This behaviour was default in earlier versions of LAPDm/LAPD. Because it
is only required for osmocom-bb, a flag is added to enable it there.

Related: OS#5969
Change-Id: I93994dbbd1fc2c9edb8f3015c6b18ecd0fce0565
2023-11-27 16:25:53 +00:00
Andreas Eversberg f51f916e1c LAPDm: Add an extra queue for UI frames
The extra queue is used to transmit the UI frame only when there is no
frame in the regular TX queue. This allows to give LAPD frames prioity
over UI frame.

Related: OS#4074
Change-Id: I00c8ee73be8b7c564a4dee3fca3e893484f567da
2023-11-27 16:25:53 +00:00
Andreas Eversberg 2d7119d85b LAPDm: Add support for RTS based polling
The lower layer must set the 'POLLING_ONLY' flag and provide frame
number when polling a frame. If T200 is pending, it is started with a
timeout frame number in advance to given frame number.

The lower layer must call lapdm_t200_fn() after a frame has been
received or if a frame has not been received. Also it must be called
after a TCH frame has been received. LAPDm uses this to check the T200
timeout condition.

A new function is used to set the frame number based timeout values.

Related: OS#4074
Change-Id: I6ebe83f829d7751ea9de1d90eb478c7a628db64c
2023-11-27 16:25:53 +00:00
Andreas Eversberg 49b7087360 LAPD: Add support for RTS based polling and T200
The T200 timer is started when the current frame is polled at
PH-READY-TO-SEND event.

A flag is used to enable this feature. The user of LAPD core must track
frame numbers to check the timeout condition. Then it must call the
external timeout function.

Related: OS#4074
Change-Id: Ib961b5a44911b99b0487641533301749c0286995
2023-11-27 16:25:53 +00:00
Daniel Willmann 0266b531c5 Disable uring when building for embedded
Change-Id: Iec2503986c6d3487761ba592daef0fd42478aa7d
Related: OS#6233
2023-11-24 16:13:07 +00:00
Vadim Yanitskiy d4b94ceb88 soft_uart: fix spelling in doxygen docs
Change-Id: Ib719d1fe4ee6c058860e861c91ec2417d9dff0af
2023-11-24 03:00:02 +07:00
Harald Welte c380f29c0c osmo_io: Reject unknown/unsupported modes in osmo_iofd_setup()
The current code does not check the value range of the 'mode' parameter
and would later run into OSMO_ASSERT(), rather than rejecting such a
mode from the very beginning.

Change-Id: I10dd612487638f456d0ad59c2cca203f1e098da3
Related: OS#5751
2023-11-22 12:20:12 +00:00
Harald Welte 38d8170fa4 osmo_io: rename unsupported SCTP mode to OSMO_IO_FD_MODE_SCTP_RECVMSG_SEND
The two functions of the SCTP socket interface we use in osmo-* are
sctp_send() and sctp_recvmsg().  We do not use sctp_sendmsg() at all,
so let's make sure the mode is named correctly.

Change-Id: Ie2d1c7ce6f211dbe025a0e843ad733443102ea15
Related: OS#5751
2023-11-22 12:20:12 +00:00
Harald Welte 987a86af88 io_uring: add some more source code comments/docs
Change-Id: I8ba77a18b51f67a9edbd1fa488b9791f8bf6e40a
2023-11-22 12:20:12 +00:00
Harald Welte 641cc3c60d add new osmo_sockaddr_from_str_and_uint() function
The function is basically a shortcut for getaddrinfo with storing the
output data into our 'struct osmo_sockaddr'.

Change-Id: I6b5c0bf8ca97e6358d992fb2ff45ffd53ba15197
Related: SYS#6657
2023-11-22 12:18:26 +00:00
Daniel Willmann afdfc6a034 osmo_io: Assert that iofd mode is correct when calling *_write_msgb
Change-Id: Ief82ba7f9b280f85d66d68c358c36ba9866fe47a
Fixes: OS#6264
2023-11-21 21:02:13 +00:00
Vadim Yanitskiy 459cb06912 soft_uart: check n_bits against 0 in osmo_soft_uart_tx_ubits()
Currently calling this function with n_ubits == 0 would result in
requesting one character from the application (via the .tx_cb()),
but not actually transmitting anything.  Make it return early.

Change-Id: Icbf99a9f2f6fa64dd71a5f37922f9001577c6c97
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy ffdd99779d soft_uart: fix pulling a small number of Tx bits
Change-Id: I454c8786697a6f2389d56b350e6e20ca953fe859
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy dab6629f1c soft_uart: demonstrate a problem with osmo_soft_uart_tx_ubits()
As can be seen, pulling a small number of bits at a time (smaller
than a single UART frame would fit into) results in calling the
.tx_cb() with a msgb having no room at all, and thus pulling the
stop bits instead of the actual data.

Change-Id: Icfee378f0fdc5e32fe9ce0afab5f75bc278653a9
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy 0d78a00b9f soft_uart: implement OSMO_SUART_PARITY_{MARK,SPACE}
Change-Id: I4c8fe5bfdcc2f4eb52c259d1e62d06684cd8f823
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy 2d2ce49e52 soft_uart: fix handling of num_data_bits < 8
Change-Id: Ife13b1f2d9063ba7253d01523ca9ecb15e9eaf07
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy bf95f82291 soft_uart: fix Rx buffer flushing logic in suart_rx_ch()
Whenever we encounter a parity and/or a framing error, we should
call the .rx_cb() immediately, even if this was the first
character in the receive buffer.

Change-Id: I73fab1a5c196d2dbdfe98b0c20d8dadbd22f4f64
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy 9ef304dd25 soft_uart: add unit tests for the receiver and transmitter
Change-Id: Icdfa0c644548964d37940c32dc9dcfcfc53c3a19
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy 03f0ed78ef soft_uart: allow manually flushing the receive buffer
Change-Id: Id600a2db99e6cb84866cbdcfcd4f78265e067291
Related: OS#4396
2023-11-21 18:50:09 +07:00
Vadim Yanitskiy c9fc77f541 soft_uart: implement the transmitter
Change-Id: Ibcd9643227e5616efd8bbd7a1430feda6fcef45c
Related: OS#4396
2023-11-21 00:58:53 +07:00
Vadim Yanitskiy 1c2b8c1eb7 soft_uart: implement parity checking for the receiver
Change-Id: I28be2ca19d423447a718fb518566d52ae1967ec7
Related: OS#4396
2023-11-21 00:58:53 +07:00
Vadim Yanitskiy 1a3b511b32 soft_uart: rework osmo_uart_rx_bit() to use flow state
Change-Id: I40ab5d12b6f7087daa51405468f5c4ea639561ea
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 b72625d40e soft_uart: add doxygen documentation
Change-Id: Ib0dcea0c35619bda5626cf75044000951b26485b
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 259a0b7e88 tests/testsuite.at: remove copy-pasted 'touch experr'
Doing this after creating a file yields nothing.

Change-Id: Ib3bdaf6db25e4a2995abdff5c859d4be023d45a9
2023-11-19 10:21:14 +00:00
arehbein 90d79f4eac gmstap_util: Fix sending out gsmtap messages
Previously undetected, because the vty command 'gsmtap log ...' never used write queue mode

Change-Id: I88ba8984518d2d0327cfacd0d2cdf33c7e1d091b
2023-11-17 18:52:58 +01:00
arehbein f67e45828d gsmtap_util: Simplify sink
- Instead of using the osmo_fd API to call read() on the socket's file
   descriptor each time (unused) data is received, simply open the
   socket and never read

Related: OS#6213
Change-Id: I4025920d5f62d17133e9b5fe81cd34a88c4f20b5
2023-11-15 21:29:23 +00:00
Andreas Eversberg 1bb0b99552 LAPD: Always update N(R) in pending TX frames if V(R) is incremented
The outcome of the update function is still used to indicate if an RR
frame must be sent or not. Only if there is no I frame in the TX queue,
RR frame must be sent.

Related: OS#4074
Change-Id: I71676c709878105bfd18b9370fecc61b92796a6f
2023-11-15 21:28:22 +00:00
Andreas Eversberg 913a783ff2 LAPD: Flush TX queue, if remote peer enters busy condition or rejects
In case of a busy condition or a reject (sequence error) from the remove
peer, the messages in the TX queue are obsolete and will be flushed.

Related: OS#4074
Change-Id: Iaaf9aaabb958ef889e252ddd0026ff82cfac981f
2023-11-15 21:28:22 +00:00
Andreas Eversberg cc63aae030 LAPD: Prepare lapd_send_i() for RTS support
When RTS is used, lapd_send_i() is called very frequently. (for every
PH-READY-TO-SEND primitive) The logging output can be suppressed in this
case.

As there is no complete lctx (lapd context) when calling lapd_send_i()
at RTS, take the stored lctx.

Related: OS#4074
Change-Id: I3109b7aa15c0f75f4a7458fc1c5d0ce633100f76
2023-11-15 21:28:22 +00: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 a995269c6d coding: gsm0503_tch_a[fh]s_encode(): improve cmr/ft checks
Change-Id: If03d5b015ab1c8db56a4c67bdc8e36e260c06562
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
arehbein f38077ee6a gsmtap_util: Use Osmo IO instead of Osmo write queues
- Adapt decl. of 'struct gsmtap_inst' for usage of Osmo IO while maintaining backwards compatibility
 - Maintain legacy behavior without any message queues if osmo_io_mode is zero

Related: OS#6213
Change-Id: Iadbbef74e3add7001d84dd6b68f51eac293e44d0
2023-11-09 12:48:07 +00:00
Daniel Willmann f2629675aa logging_gsmtap: Temporarily disable logging when sending the logs
This avoids an infinite recursion when sending a gsmtap log message
causes a log message.
Temporarily set target->loglevel higher than LOGL_FATAL, which
effectively disables logging for that target. Other targets like stderr
will still log this message so there is still an indication that
something went wrong.

Change-Id: I19203cadbad6019a3834793b8ac816d903fe088e
Related: OS#6213
2023-11-09 19:34:37 +07:00
Manawyrm 11a416827d logging: ensure ANSI color escape is sent in same line/before newline
This fixes multi-line color clobbering in logging daemons like
systemd-journald, which work with single-lines only.

Change-Id: Ia7de9d88aa5ac48ec0d5c1a931a89d21c02c5433
Closes: OS#6249
2023-11-07 16:50:22 +00: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
Pau Espin e4f34d8d0a socket.c: Fix compilation with --disable-libsctp
Fixes: 64ba9edf17
Related: OS#6234
Change-Id: I988d01461822d18b7350a6e69e3b504f7fd5b84f
2023-10-23 09:58:50 +00:00
Andreas Eversberg 676b361fa7 LAPDm: Correctly count expiry of T200 during estabishment/release
After T200 expires N200+1 times, the link establishment or relase
fails. The counting must be performed prior check.

Related: OS#5970
Change-Id: Icf44e26420fc91312e7c8972a2f3ed475e42fc48
2023-10-23 09:07:28 +00:00
arehbein a59e8d7c1d write_queue: Fix Doxygen comment
Change-Id: Ib2508411ae46e2456466beaae63d3f401e34d0d4
2023-10-20 20:55:54 +00:00