Commit Graph

4533 Commits

Author SHA1 Message Date
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
arehbein 99653047d7 core: Check return value of osmo_fd_register()
Change-Id: I15bb456c42d5033c9cf4c0937df22fa02b6a6086
2023-05-09 23:37:34 +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
Neels Hofmeyr cc9b699931 vty: show bug in implicit go_parent_node
Add test to show a problem in VTY node exiting.

Back in 2017 when I introduced VTY config file scopes by indenting [1],
I actually mistook the vty->priv for the vty->index that we use
everywhere to link to the state for our VTY nodes.

The intention was that each VTY node child level has its own object
linked to it by the vty->index pointer. When the config file leaves a
scope, the vty->index should reflect the parent object.

Instead I implemented that for the vty->priv pointer only, but we don't
use that.

Why did this bug not show? A problem happens only if:
- a node that uses vty->index is nested inside a node that also uses
  vty->index.
- config sets parent node attributes after a child node.
- there is no legacy vty_go_parent() function that sets the correct
  index via a switch().

[1]
"VTY: implicit node exit by de-indenting, not parent lookup"
4a31ffa2f0
I24cbb3f6de111f2d31110c3c484c066f1153aac9

Change-Id: I2472daed7436a1947655b06d34eb217e595bc7f3
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 beb7c1741e Fix 'Fix parsing of TLV_TYPE_SINGLE_TV'
A commit was merged recently attempting to fix decoding of
TLV_TYPE_SINGLE_TV. It did mostly a good job, but missed updating the
o_tag pointer used to fill in the structures.
This commit fixes that specific part missing.

Fixes: 559a6ee683
Change-Id: Id619459c17976b77cd2c7e4179123bb06807285c
2023-05-02 15:20:53 +02:00
Pau Espin e2217ee098 tlv: Show bug in decoded tlv_parsed for type TLV_TYPE_SINGLE_TV
A commit was merged recently attempting to fix decoding of
TLV_TYPE_SINGLE_TV. It did mostly a good job, but missed updating the
o_tag pointer used to fill in the structures.
This new unit test showcases the mentioned problem.
A follow-up patch will fix the bug.

Change-Id: Ia17c84059a413f80c2bcf194034ebac586ecf7e1
2023-05-02 12:11:26 +02: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
Oliver Smith 779ff09fc9 debian: set compat level to 10
Related: OS#5958
Change-Id: I6ee4aace6bf7c246338408c41f790189d75d5488
2023-04-27 12:28:12 +00: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
Vadim Yanitskiy 68d5139abc libosmocore.map: add missing symbols needed for osmo-qcdiag
Change 213fc420e broke osmo-qcdiag:

  /usr/bin/ld: diagchar_hdlc.o: in function `osmo_crc16_ccitt_byte':
  src/diagchar_hdlc.c:46: undefined reference to `osmo_crc16_ccitt_table'
  /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
  collect2: error: ld returned 1 exit status
  make: *** [Makefile:8: osmo-qcdiag-log] Error 1

Change-Id: I7e84546b484db4822554681b31625d0520617d2b
Fixes: 213fc420e "Add libosmocore.map"
2023-04-23 01:48:50 +07: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
Neels Hofmeyr 91f5eee672 logging vty: probe 'print' and 'logging timestamp' cmds
Upcoming patch I58c792dda3cbcf8618648ba4429c27fa398a9e15 aims to change
the timestamp configuration. Show current state before these changes.

Change-Id: I8e0a373496130004e453a2044c1091665fe02a05
2023-04-14 22:52:30 +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
Max 028813414c logging: print talloc report on exit from vty test
There's not much point in deallocating memory in a test fixture
which is about to terminate anyway. Having talloc report though
is handy to make sure we're not leaking smth.

Change-Id: I5739bceb90d36164fd4cbf21242bbe26bd1e7075
2023-04-05 10:41:48 +00: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
Vadim Yanitskiy 48c60f9771 fixup (partial revert): "coding: clean up Makefile.am"
This is a partial revert of "9dca9027 coding: clean up Makefile.am".

Even though libosmocoding does not use talloc API, it still depends on
this library indirectly via libosmo{core,codec,gsm}.  Furthermore, some
of libosmocore's header files do #include <osmocom/core/talloc.h>, and
thus #include <talloc.h> via this internal header.

Under Slackware 14.2 talloc.h header lives in /usr/include/samba-4.0,
and without $(TALLOC_CFLAGS) compilation of libmsocoding fails due
to the preprocessor failing to find this header.  The culprit is my
recent patch 9dca9027 removing $(TALLOC_CFLAGS) and $(TALLOC_LIBS).

Put $(TALLOC_CFLAGS) back to AM_CFLAGS;  it will likely be emply under
distributions having talloc.h header in the standard include dir.  The
$(TALLOC_LIBS) does not need to be resurrected because libtool will
add '-ltalloc' automatically for each libosmo*.la in LIBADD.

Change-Id: Ic1bd82159a827af21fe36bea998f8f58f732473a
Related: OS#5960
2023-03-31 05:10:52 +07:00
Vadim Yanitskiy 89a3fc95af tests: make VTY tests depend on the respective binaries
Change-Id: I784fe3b5737b804f7b55da01d8beb619c57bafd6
2023-03-30 12:32:53 +00: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
Vadim Yanitskiy 1c88ff9ba5 gsm_04_08: add more enum gsm48_chan_mode speech values
From 3GPP TS 44.018 (version 15.4.0), table 10.5.2.6.1.

Change-Id: I6adda28698c0e479ef20f5d090c1f7f76a2ec97e
Related: OS#1572
2023-03-23 18:38:11 +07:00
Vadim Yanitskiy 8c7f023784 gsm_04_08: document/clarify enum gsm48_chan_mode values
The values are defined in 3GPP TS 44.018, section 10.5.2.6.  Only the
radio interface rates for CSD (GSM48_CMODE_DATA_*) are given, but the
respective service rates can be found in 3GPP TS 45.003.

Change-Id: I716027f73ab6f20037f6de16e4a3740811aa38a2
Related: OS#1572
2023-03-23 18:38:11 +07:00
Pau Espin 559a6ee683 Fix parsing of TLV_TYPE_SINGLE_TV
The decoding path of TLV_TYPE_SINGLE_TV is wrong, since it is not
shifting right the tag before using it. On the other hand, the encoding
path (tlv_encode_one) is doing that, so it is clear there's a bug.

It seems that in order to workaround the bug some IEs in gsm_04_08.h (TS
24.008 and TS 44.018) were defined incorrectly (eg 0x80) while the spec
clearly assigns eg. "8" to it, and makes sure no full byte IEI collides.
Some other IEIs like GSM48_IE_GMM_CIPH_CKSN which are also of the same
type were already correctly defined as 0x08.

Change-Id: I799e35dc8d4d153fa63bf50563a5482cdf4de2d7
2023-03-22 14:23:51 +01:00
Vadim Yanitskiy 25127fb749 isdn: fix identical operands in v110_adapt_IR8000_to_2400()
Change-Id: I7df8b214e813cbd14726d5043f666547353e2947
Fixes: CID#310966
2023-03-17 17:08:23 +07:00
Vadim Yanitskiy 8f6d2f349c tests/v110: assert(user_data_chunk_bits) in test_ra1()
Coverity warns that osmo_v110_sync_ra1_get_user_data_chunk_bitlen() may
return a negative value, which is used as loop boundary.  Even though
this is unlikely, let's add an assert().

Change-Id: I0fc0e0bac74bd96351030432ef1b140b727acb0d
Fixes: CID#310968
2023-03-17 16:35:53 +07:00
Vadim Yanitskiy 0a60e422a8 gsmtap: add missing entries to gsmtap_type_names[]
Change-Id: I67dc578c62f89039f35856da1f29caab4b5db1d8
Fixes: fae779ac5 "GSMTAP: Import changes from Wireshark"
Fixes: f9b1e5556 "gsmtap.h: Introduce new GSMTAP type for LTE NAS messages"
Fixes: 161d42a61 "gsmtap: Add definitions for E1/T1 payload (LAPD, TRAU, FR) in GSMTAP"
2023-03-17 16:30:19 +07:00
Harald Welte b394d6fc85 New osmo-gsmtap-logsend utility
This utility can be used to "pipe" stdin or some file as log lines
via GSMTAP logging.

Change-Id: Ida96e87d84e0c349c5069edc67fec1c3cf19d1ab
2023-03-15 11:53:08 +00:00
Neels Hofmeyr 5761c44609 error log: osmo_sock_init2_multiaddr() v4/v6 mix
Provide some more information for the error case when local and remote
addresses mix v4 and v6.

Change-Id: I0fd12b08e0788ce3af6dc519ff8c82ad196a115f
2023-03-14 20:15:05 +00:00
Neels Hofmeyr e1c4f24cb9 contrib/talloc_count.sh: improve hexadecimal masking
Also mask hexadecimal without leading 0x. But take care to not match on
every letter a-f,A-F in normal words and names.

before:

    10 map_rua(NffffNfNecN-example-com-RUA-N)[N]
    10 map_sccp(NffffNfNecN-example-com-SCCP-N)[N]
    17 map_rua(NffffNcN-example-com-RUA-N)[N]
    17 map_sccp(NffffNcN-example-com-SCCP-N)[N]
    18 map_rua(NffffNeNbN-example-com-RUA-N)[N]
    18 map_sccp(NffffNeNbN-example-com-SCCP-N)[N]
    82 map_rua(NffffNfNdN-example-com-RUA-N)[N]
    82 map_sccp(NffffNfNdN-example-com-SCCP-N)[N]
    85 map_rua(NffffNfN-example-com-RUA-N)[N]
    85 map_sccp(NffffNfN-example-com-SCCP-N)[N]
   224 struct hnbgw_context_map

after:

   224 map_rua(N-example-com-RUA-N)[N]
   224 map_sccp(N-example-com-SCCP-N)[N]
   224 struct hnbgw_context_map

Change-Id: I1b42ce3e67c7ed2d38d3e5c9cbfa90ba185a07b7
2023-03-14 20:12:57 +00:00
Neels Hofmeyr 141dffddf5 fix 'make vty-test' for --disable-external-tests --enable-gb
Change-Id: I80ac270bfb563a769a7746d8fbceac09e267ce03
2023-03-14 18:08:35 +00:00
Neels Hofmeyr 439ffc2a3e fix 'make vty-test' for --disable-gb
Change-Id: Ib6aec784d3b20cd56cb6bfab9ff17da35a282406
2023-03-14 18:08:35 +00:00
Oliver Smith b46cfba995 on_dso_load_select: run after on_dso_load_ctx
Add priorities to ensure on_dso_load_select runs after on_dso_load_ctx.
Otherwise osmo_ctx->global (used via define OTC_GLOBAL) points to NULL
and causes a segfault in osmo_fd_lookup_table_extend.

Use numbers 101 and 102, as "0 to 100 are reserved for the
implementation" and cause an error from GCC.

Fixes: OS#5946
Fixes: c46a15d8 ("select: Optimize osmo_fd_get_by_fd")
Change-Id: Ia2518e82530b93c535f8f5105513e21559b895ba
2023-03-14 15:22:20 +00:00
Pau Espin fc37650381 logging.c: Sanitize calls to osmo_fd_unregister()
It makes no sense to call osmo_fd_unregister() on a negative fd.
Let's also make sure we set fd to negative value after unregistering +
closing, even if the struct is going to be freed afterwards.

Change-Id: I0790a63e603028c11cc475d483c6528e4d9aa9ab
2023-03-14 14:32:54 +01:00
Pau Espin ff666997b2 tests/Makefile.am: Move LDADD to right position
LDADD var contains both local and system libraries. Use it at the right
place (after list of local libs, before list of system libs).

Change-Id: Ifb3686f78432ac877c596004646506c540b23c53
2023-03-14 14:20:21 +01:00
Pau Espin 34537d4de8 tests/Makefile.am: Drop duplicated libosmogb.la in LDADD
Change-Id: I20e815ba5dc473c644e1098f2347b183f215a51a
2023-03-14 14:13:07 +01:00
Pau Espin 6020d139eb tests/Makefile.am: Move system libs at the end of list
Change-Id: Iad6b9e39e3587849ccfd475899cbd610bf7145cd
2023-03-14 14:09:43 +01:00
Pau Espin 6fd7f41672 select.c: osmo_fd_unregister(): Avoid assert hit with old buggy users of the API
Change-Id: If77b84d603a42a216d550d9708eb62f645634a61
2023-03-14 13:13:47 +01:00
Pau Espin 3b450f0233 configure.ac: Fix typo in enable flag description
Change-Id: Ida390c50379a429a4b42434e32954eeb832a11ff
2023-03-14 13:13:40 +01:00
Pau Espin 5ef158fbbb configure.ac: Fix logic enabling osmo_fd fd checks
The logic testing the and setting the define was inverted, which made it
enabled by default.

Take the chance to rename the enable flag to be "ofd" instead of
"bsc-fd" (since anyway the flag was broken).

Change-Id: I81112fa1f6ce1a8e5fe85468241ad385ed8805d3
2023-03-14 13:13:40 +01:00
Pau Espin 25729cf531 select.c: Clarify osmo_fd_unregister() can only be called on registered osmo_fds
Change-Id: I5e397e121f2fe2254c7f4b474e6eefd7aebe7a83
2023-03-14 12:26:37 +01:00
Pau Espin 153519f5fb select.c: Clarify osmo_fd_(un)register() API expectations of registered fd
Those restrictions were implicitly required for a while and most of the
users of this API already followed them, but just a few didn't. All
known users have now been fixed. Let's explicitly document the
restrictions imposed by the API to ease avoiding similar issues in the
future.

Change-Id: I53d95aad15b33dd66aa5c7dd11745a35c4481f33
2023-03-14 12:01:45 +01:00
Pau Espin c46a15d876 select: Optimize osmo_fd_get_by_fd
Optimize osmo_fd_get_by_fd() from O(n) to O(k) by means of allocating
dynamically growing array.

Make use from the fact that the kernel always tries to use the smallest
 possible unused value when allocating a new fd.

Change-Id: I8b71547df8bed84192cb160479fa3debf9b7eade
2023-03-13 15:26:21 +00:00