Commit Graph

4616 Commits

Author SHA1 Message Date
Vadim Yanitskiy 403dfbc345 ipa: fix a typo in ipa_ccm_rcvmsg_base(): PING -> PONG
Change-Id: I83e7326758e533a008eec28641dae619216ea84a
2023-07-05 00:54:06 +07: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
Daniel Willmann 8b7e7f164f osmo_io: Remove missing functions from map file
Change-Id: I4dbc1cf9b05521325287803f00781001b80945ef
2023-06-30 13:57:05 +02:00
Daniel Willmann e4ecd996d4 osmo_io: Fix write_enable handling in iofd_txqueue
Enable write on first message in both iofd_txqueue_enqueue{,_front}(),
but only if the iofd is not closed.

Change-Id: I75827491bb9fe0c6d1e4a195ac434f049b1a6ba6
2023-06-30 13:55:31 +02:00
Daniel Willmann 181eaa493e osmo_io: Make the test more deterministic between backends
Change-Id: Ibdd26a4aeadfbd6c5039c8a31cc120d3c98be727
2023-06-30 10:43:20 +02:00
Daniel Willmann f89162f8ab osmo_io: Use bitfield for various boolean flags
Change-Id: Ic134e4c8d791c34778202fea98a70bc04007a113
2023-06-29 17:06:23 +00:00
Harald Welte 3ef6120d51 gsmtap_source_free(): Don't crash if NULL is passed
A function called *free() should always support passing a NULL input
value.

Change-Id: If0f6c11ac6ad987368e1d5c63a07fc456f89db2a
2023-06-29 17:05:23 +00:00
Andreas Eversberg e4c7b0adcd ASCI: Add decoding of mobile identity in TALKER INDICATION
gsm48.c provides a function to decode mobile identity from various
messages. TALKER INDICATION is sent by the talking subscriber of a voice
group call to idenitfy the current talker. The mobile identity is
required to distinguish between calling subscriber and other subscribers.

Related: OS#4854
Change-Id: I331fac82e3c15abb01f554b2e70576100f2eea2d
2023-06-28 11:54:55 +00:00
Andreas Eversberg 6e7739f709 Allow 'configure <cr>' at VTY to enter config mode
Similar to HP/Aruba, only the word or abbreviation of 'configure' is
required to enter config mode. This is the default. It is still possible
to add other configuration sources than 'terminal' if implemented in
the future.

Change-Id: I56d5d1bd5526603a397c62542e667c413f4952ca
2023-06-28 11:54:55 +00:00
Andreas Eversberg 72ab3b5200 ASCI: Also display group/broadcast call message names
gsm48_pdisc_msgtype_name* will include group and broadcast call control
message names too.

Change-Id: I1874e61c24cd8e66b74171681d22f0bfe8069158
2023-06-28 11:52:16 +00:00
Daniel Willmann a8a27c2c6f osmo_io: Use LOGPIO instead of LOGP
Change-Id: I4ee256b18544f7ca6bff6b7c6ebcce15546bb1f2
2023-06-26 19:28:54 +02:00
Daniel Willmann acb97765ef osmo_io: Return early on error in osmo_iofd_register()
Change-Id: I2561c82e6bf7e2bb5fd699c899238f9c43ea4d9c
2023-06-26 19:28:47 +02:00
Vadim Yanitskiy f0a1f41cdc gsm0502: cosmetic: use ARRAY_SIZE in gsm0502_fn2ccch_block()
Change-Id: Ideb9907fcb5eff74508f44714e478ec46d435a5d
2023-06-25 15:47:13 +07: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
Vadim Yanitskiy 7d121cbaed coding: fix a copy-paste bug in gsm0503_tch_afs_decode_dtx()
According to 3GPP TS 45.003, section 3.9.2, the convolutional coding
is *not* employed in the case of SID_FIRST.  This is why we're using
sid_first_dummy[] in this function.

The conv[] array is not initialized in the case of AFS_SID_FIRST and
passing it to tch_amr_reassemble() is highly likely a copy-paste bug.
Pass the sid_first_dummy[] instead.

Change-Id: Ic8bfc34ce9d14821fe4e82932325f0c517d443a1
Fixes: CID#272949 "Uninitialized scalar variable"
2023-06-23 16:57:52 +07: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
arehbein 5099d99192 core/osmo_io: Fix reception of partial packets
Always append to 'msg->tail' instead of to 'msg->data'.

Change-Id: I0ab8028c807b4181fddd3c00ea2e037c40cf0813
2023-06-19 15:40:57 +00:00
Daniel Willmann 7052cc6b3b socket: Ensure fd is not negative in osmo_sock_get_name_buf()
Write to str even in case of error because this is already the current
behaviour and it's what osmo_stream_cli_get_sockname() and
osmo_sock_get_name2{,_c}() expect.

Change-Id: I76727993224ef87b475c33360c24966e82e866ec
Fixes: Coverity CID#321044
2023-06-19 15:12:24 +00:00
arehbein c0aa4bdf8f core/osmo_io: Rename variables for readability
Rename msg_len -> received_len, len -> expected_len
so the variable names have a consistent scheme.
For instance,
	extra_len = msg_len - len
becomes
	extra_len = received_len - expected_len

Change-Id: I3d752ce91a1b16c855522f643d10a52ef28a8a84
2023-06-19 12:59:03 +00:00
Andreas Eversberg cb72e74031 lapdm: Do not return an error when enqueuing a frame
If tx_ph_data_enqueue() is called, frames will be written into a queue,
if there is a pending frame or if polling of TX frames is used. In
this case the return value must be 0.

Sending a RSL_MT_UNIT_DATA_REQ from upper layer causes a call to
tx_ph_data_enqueue(). The return code is returned to the sender. The
sender must not get an error returned, if the message is enqueued.

Change-Id: Iaeaf7c66cb3cf5cc81bc8e15d468e8e7704c1407
2023-06-09 15:06:34 +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 0370018eae Add support for receiving Bter UI frames at lapdm.c
Similar to support of sending Bter frame, the same rules apply when
receiving them.

Change-Id: If04115884743455c7bf2b2bc5f7e49e74b6ffb60
2023-06-09 15:06:34 +00:00
Andreas Eversberg 6799741699 Add support for sending Bter UI frames at lapdm.c
Bter frames may be used on downlink of a main DCCH or SACCH channel.
It applies to SAPI 0 and UI frames only. It includes a short layer 2
header with 2 bits only. All other bits are used for the message. The
message size is 23 bytes on main DCCH and 21 bytes on SACCH.
The length of the L3 messsage is used to distinguish between Bter frames
and other (UI) frames.

Note that the L3 message header is different, so that the length of the
UI frame will determine which header is used.

Change-Id: Ia3a25c009d1ff09f83258bdb226a85b81466d7a1
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
Eric Wild 9864efc10b gsm48_rest_octets: fix wrong value
The compiler complains:

gsm48_rest_octets.c:79:11: warning: initializer overrides prior
initialization of this subobject [-Winitializer-overrides]
   79 |         [0x08] = {2,  2},
      |                  ^~~~~~~
gsm48_rest_octets.c:78:11: note: previous initialization is here
   78 |         [0x08] = {2,  1},
      |                  ^~~~~~~

And a quick look at 04.18 confirms:

0 1 0 0 0	2	1
0 1 0 0 1	2	2

Change-Id: I672e2ce53fd07157d15fec350cfbe32a19a52941
2023-06-03 16:28:37 +02: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 9d5d355720 libosmogsm: Avoid executing MILENAGE crypto twice (for UMTS and GSM)
So far, we were executing the cryptographic functions to generate
MILENAGE authentication tuples *twice* for every call to
milenage_gen_vec: Once for UMTS, and another time for GSM.

Let's do this properly: Execute once for UMTS, an then call the
computationally much simpler C2 and C3 functions to compute the
SRES and Kc values from RES, and CK+IK, respectively.

Change-Id: I20ecf6d32974c1ba196bf56deba5b2cd971eaffb
2023-06-02 08:29:55 +00: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 0ea9b91e0f osmo-auc-gen: Convert over to osmo_auth_gen_vec*2 API
This allows the tool to support K/OPc lengths != 128 bit.

Let's add more length checks of command-line arguments while we're
adding those checks for K/OPc.

Change-Id: Iffed02ec0fc9c9a996da6f218d67314e381cbb29
2023-06-02 08:29:55 +00:00
Harald Welte a9c91cc0a1 libosmogsm: Ensure MILENAGE + XOR-3G K length is 128 bit
Since Change-Id Ie775fedba4a3fa12314c0f7c8a369662ef6a40df we are
supporting K-lengths != 128 bit.  However, our existing MILENAGE
and XOR-3G algorithms only support that key length, so let's add
some explicit checks for that.

Change-Id: Iae8b93cf059abda087101cdd01bbcf92d355753b
2023-06-02 08:29:55 +00:00
Harald Welte 5248c47e1f libosmogsm: Add OSMO_ASSERT() to ensure correct algorithm
Let's make sure that nobody ever ends up calling the algo_impl
call-backs with data of a non-matching algorithm.  This should
never happen at all, as all normal users should go through
the auth_core.c:osmo_auth_gen_vec* API, which dispatches based
on algorithm.

Change-Id: I22b504b6cffb4999b2f14772fffcb2f6f02c198c
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 6e529a2c74 coding: gsm0503_tch_{fr,hr}_encode(): add ability to emit BFI
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/HS where FACCH
displaces two speech frames rather than one.  A more elegant
solution is to emit a speech frame with inverted CRC3, causing
the MS receiver to declare a BFI condition to its Rx DTX handler.
Setting all u(k) bits to 0 is one way to produce such an inverted-CRC
speech frame (normal TCH FR/HR CRC3 for an all-zeros frame would be
111), and this method is in fact what sysmoBTS PHY is observed to do.
Add the same ability to gsm0503_tch_{fr,hr}_encode() functions,
indicated by payload length of 0.

Change-Id: Iade3310e16b906efb6892d28f474a0d15204e861
2023-05-27 11:06:57 +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
Mychaela N. Falconia 945f6cec0f coding cosmetic: gsm0503_tch_{fr,hr}_encode(): remove extra spacing
These two functions are structured as switch statements handling
different types of input, but they also have a lot of empty spacing
lines in strange places, making them difficult to read and even more
difficult to add new functionality while maintaining the same style.
Remove those extra spaces.

Change-Id: I595a80898283d0932fb33f582347ec39a9481d1a
2023-05-27 00:41:33 +00:00