Commit Graph

920 Commits

Author SHA1 Message Date
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 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
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
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
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
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
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
Harald Welte c4cfb802df gsm: TS 44.021 modified V.110 frame encoding/decoding support
3GPP TS 44.021 specifies the format for modified V.110 frames as used
on the GSM air (radio) interface.  Implement encoders and decoders for
this modified V.110 format.

Related: OS#1572
Change-Id: I60a2f2690459359437df20cf4da9043fa7c3ad11
2023-03-08 20:43:15 +01:00
Eric Wild 573f2fa1b3 fix _thread order
As per gnu extension doc ->
https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/Thread-Local.html :
".. When used with extern or static, __thread must appear immediately
after the other storage class specifier."

Change-Id: Ied1d3cf3ad2ff424bd0a2682aff29a8939b419b8
2023-03-07 14:27:59 +01:00
Harald Welte c9527763c2 Makefile.am: Make libraries depend on .map files
Without this, an update to the .map file doesn't re-trigger a re-link of
the library.

Change-Id: If0ea6f41730a28b04562d45efa6ca376abaf3f6b
2023-03-06 17:07:48 +00:00
Pau Espin 3e5609ade6 gsm: gsm_gsmtime2fn(): constify param
Change-Id: Ib29d5a8e7dcf50fb086f967857b0afa076573163
2023-03-06 13:59:40 +01:00
Neels Hofmeyr 593d20d637 add gsm0808_amr_modes_from_cfg
Provide the definitions from 3GPP TS 28.062, Table 7.11.3.1.3-2 as
generally usable API.

Likely users:
- upcoming patch to improve conversion between S0-S15 and MultiRate
  config, I900fda192742fa8f6dd54e9131ef1704b14cc41a
- osmo-msc to figure out conversion between SDP AMR mode-set and 3GPP TS
  48.008 Permitted Speech S0-S15.
- osmo-bsc to choose AMR modes for channel activation from cfg /
  permitted speech from MSC.

Related: SYS#5066
Change-Id: Icef7dd626d3d4641c66b8dd87e2047fc0ab547d1
2023-02-28 23:00:45 +00:00
Vadim Yanitskiy 64277a0217 doxygen: fix various typos in commands \param and \returns
Change-Id: If87cec3739449c6a54e24fb2cb81e746d8244da2
2023-02-28 18:48:56 +00:00
Oliver Smith 57d4fae832 gsm0808_enc/dec_channel_type: fix transparent flag
According to 3GPP TS 48.008 3.2.2.11, it is inverted.

0: Transparent service
1: Non-transparent service

Change-Id: I2e5786ad053ee871079b4a8d95caccd6b03b59b6
2023-02-27 13:49:34 +00:00
Vadim Yanitskiy 7184511754 gsm: use OSMO_ASSERT() in osmo_iuup_msgb_alloc_c()
This patch is a preparation for the upcoming change making use of
the built-in static_assert(), which is available since C11.

When using built-in static_assert(), gcc v12.2.1 fails:

iuup.c: In function 'osmo_iuup_msgb_alloc_c':
iuup.c:194:33: error: expression in static assertion is not constant
  194 |         osmo_static_assert(size > IUUP_MSGB_HEADROOM_MIN_REQUIRED, iuup_msgb_alloc_headroom_bigger);
../../include/osmocom/core/utils.h:86:24: note: in definition of macro 'osmo_static_assert'
   86 |         static_assert((exp), "(" #exp ") failed")
      |                        ^~~

This one is not really a *static* assert(), because it operates on the
user supplied argument 'size', which is not guaranteed to be an integer
literal.  Neither it triggers a compilation failure as expected, nor
does it abort at run-time.  It simply does nothing.

Change-Id: I53db679728250e0c60ed277efb18142073ffe9c4
2023-02-27 09:58:46 +00:00
Harald Welte 65e0edc73f convolutional coding for CSD
This patch adds the convolutional code definitions for CSD (circuit
switched data) on TCH/F channels with user bit rates of 2400, 4800, 9600
and 14400 bps.

Related: OS#4396, OS#1572
Change-Id: I412131d7ee2e676402bf8d88394af17c4447b664
2023-02-25 19:37:44 +01:00
Vadim Yanitskiy 7b9b3074a2 gsm/{bsslap,bssmap_le}: zero-initialize structs using memset()
In the unit tests we're using memcmp() to compare decoding results
against the expected results.  This is a reasonable approach, but
there is a pitfall: not only the struct fields are compared, but
also the padding bytes preceding/following them.

When using gcc's extension zero-initializer {} or even the standard
approved { 0 } zero-initializer, padding bytes are not guaranteed
to be zeroed.  Even worse, according to [1], the init behavior is
inconsistent between gcc and clang and optimization levels.

All decoding functions in {bsslap,bssmap_le}.c currently use gcc's
extension zero-initializer {}.  This is not a problem when building
with CC=gcc, but with CC=clang the bssmap_le_test fails due to
mismatch of padding bytes in struct lcs_cause_ie:

  [4] PERFORM LOCATION RESPONSE: ERROR: decoded PDU != encoded PDU
  [5] PERFORM LOCATION RESPONSE: ERROR: decoded PDU != encoded PDU
  [6] PERFORM LOCATION ABORT: ERROR: decoded PDU != encoded PDU

Out of the known struct initialization methods, only the memset()
has consistent behavior and sets all bytes to zero, including the
padding ones.  Using it fixes the bssmap_le_test for CC=clang.

[1] https://interrupt.memfault.com/blog/c-struct-padding-initialization

Change-Id: Ib16964b16eb04315efc416164ed46c15b5dc7254
Fixes: OS#5923
2023-02-25 08:15:11 +00:00
Vadim Yanitskiy 82001ebc2a gsm: ensure completeness of osmo_bts_features_{descs,names}[]
It already happened several times [1][2] that new features were added
to enum osmo_bts_features, but the osmo_bts_features_{descs,names}[]
were left unchanged.  Let's add static_assert()s to prevent this.

Change-Id: I8e3b7d3996e9f3e16c6d4e0d1d406fa538d5e9be
Related: [1] f4f5d54ea2
Related: [2] 18c6a8183f
2023-02-24 17:06:21 +07:00
Vadim Yanitskiy f4f5d54ea2 gsm: add missing features to osmo_bts_features_names[]
Change-Id: I0ff47a79d611cd1c2d23ac5b4d53dca27e402821
Fixes: 812dfbf3a7
2023-02-24 16:28:05 +07:00
Harald Welte 9b7c9ae6ca Rename OSMO_AUTH_ALG_XOR to OSMO_AUTH_ALG_XOR_3G
Let's disambiguate.  Our existing OSMO_AUTH_ALG_XOR was always only
the XOR-3G algorithm.  Now that we recently introduced XOR-2G,
let's rename (with backwards compatibility #define).

Change-Id: I446e54d0ddf4a18c46ee022b1249af73552e3ce1
2023-02-22 09:45:15 +01:00
Harald Welte e93c5e99b6 Implement the XOR-2G authentication algorithm
We've so far only been supporting XOR-3G algorithm as specified
in TS 34.108 (in both 3G and 2G-derivation mode).

However, XOR-3G used for 2G auth is different from the XOR-2G algorithm
as defined in Annex A of TS 51.010-1.  Let's add support for that one,
too.

Change-Id: I0ee0565382c1e4515d44ff9b1752685c0a66ae39
2023-02-21 22:25:04 +01:00
Oliver Smith dcaab85795 gsm0808_dec_channel_type: fix dec of ch_rate_type
According to 3GPP TS 48.008 V16.0.0 § 3.2.2.11, the "Channel and rate
type" fills the whole octet 4, so don't cut it off.

This fixes decoding of e.g. GSM0808_SIGN_FULL_PREF_NO_CHANGE, which I
noticed while writing a test.

Related: OS#5911
Change-Id: Ib5fba18eb82736c4f52f315ae1197159b7090e69
2023-02-21 08:17:42 +00:00
Pau Espin 0158b05337 Move libosmogsm TS 44.060 declarations under include/osmocom/gsm/
Currently there's a big mess where include dir osmocom/gprs/ is used by
both libosmogsm and libosmogb.
Most of the header files under osmocom/gprs/ are actually all the
headers of libosmogb (there's no osmocom/gb/ dir). But a couple files
are actually RLC/MAC (TS 44.060) related are are also stored in there.
Those files have no relation/use in Gb, and are actually interused with
GSM (eg System Information 13 Rest Octets).
Hence, it makes sense to have the RLC/MAC related parts inside
osmocom/gsm/ as they should be in libosmogsm (and they actually are,
see gprs_rlc.h function implemented in src/gsm/gsm48_rest_octets.c).

The fact that some libosmogsm headers were placed in osmocom/gprs
instead of osmocom/gsm already created some issues, like
libosmocore.spec.in putting "%_includedir/%name/osmocom/gprs/" under
libosmogb, which is wrong.

As a first step to fix the mess, we move the 2 RLC/MAC headers currently
under osmocom/gprs/{gprs_rlc,protocol/gsm_04_60}.h under a single header
gsm/protocol/gsm_44_060.h
The two old headers are left existing for backward compatibility and now
simply include the new libosmogsm header, plus a warning asking users to
switch to the new header so we can eventually get rid of them.
This means libosmogb depends on libosmogsm, which is fine and was
already the case beforehand (libosmogb using functions like
gsm48_encode_ra() and linking against it in src/gb/Makefile.am).

Change-Id: I70cc21bf25a7081070738abacb409ed19094c3b2
2023-02-20 12:21:30 +01:00
Matan Perelman 310b107284 gsm0808_enc_channel_type: Add spare byte
Related: OS#5911
Change-Id: I6e05e4989924b2258122113eb134e946e9cf0107
2023-02-20 10:57:54 +00:00
Vadim Yanitskiy 2617815ffc gsm: fix invalid check in gsm48_decode_ssversion()
Change-Id: I648a4b052d0ec7af97d513630aa4279884436dda
Fixes: OS#5910
2023-02-19 16:18:32 +07:00
Oliver Smith f047a4a04a gsm0808_enc/dec_channel_type: support data
Related: OS#4393
Change-Id: Ib7b75c9d86aace329decf20003b68de459021c64
2023-02-13 08:09:48 +00:00
Oliver Smith 81e5a6f7e4 gsm0808_dec_channel_type: add missing len check
Stop iterating if the extension bit (0x80) is set but elem is too short
to read another byte.

Related: OS#4393
Change-Id: Id37109dba0f5d40f4b83f0cef9b1dbd9d6bb2c68
2023-02-09 10:36:55 +01:00
Pau Espin 5f15e4199c Bump version: 1.7.0.119-b31a-dirty → 1.8.0
Change-Id: I5e953cedc041371a9c192f58348b673a787f542e
2023-02-07 11:20:42 +01:00
Max b31a2b5f6d Add SI10 support
Add data structures and checks for System information Type 10.

Related: OS#5783
Change-Id: I3a5da543f083f31e873c67b5ec1b5a439187d8f3
2023-02-04 10:07:28 +00:00
Max bc12728679 SI: add missing header
Previous SI10 patch added function without exposing it via public header.
Let's fix this.

Fixes: 600d4eeab7
Change-Id: Ia7530e9c8a21f6f99f3aac7baea5cbb38763c4f3
2023-01-30 18:52:41 +00:00
Max 600d4eeab7 SI: add RR short PD message types
Related: OS#5783
Change-Id: Ifbd0aabe826298fa4715eb4eb2ff8363e765933d
2023-01-25 09:09:35 +00:00
Max 812dfbf3a7 ASCI: add VBS/VGCS support to BTS features list
Related: OS#5783
Change-Id: I583a170070c192c6c47fae41ce923a7439561b4f
2023-01-25 09:09:35 +00:00
Harald Welte d55a209d1c create libosmoisdn sub-library
There are some parts of libosmogsm which are not really GSM specific,
but rather ISDN bits that were inherited by GSM.  This includes the
I.460 multiplex as well as the core LAPD protocol.

Let's move those bits to its own libosmoisdn library, before we add
more ISDN specific bits to the wrong place.

Backwards-compatibility is created by making libosmogsm depend on
libosmoisdn, and by providing wrapper include files for source
compatibility.

Change-Id: Ib1a6c762322fd5047be3188b1df22408ef06aa50
2023-01-21 22:41:57 +01:00
Pau Espin 88955fb550 Fix all references to config.h
config.h is created in $(top_buildir)/config.h.
Let's make sure all CPPFLAGS add correct -Ipath includes,
and that all code includes the correct file.

Change-Id: Ie9ea38bb009bc715b01cde4d66d181f7bec2e7bd
2023-01-18 19:04:36 +01:00
Pau Espin d4c3dc8d59 Move src/*.{c,h} to src/core/
This way we have all libosmocore.so in an own subdir instead of having
lots of files in the parent dir, which also contains subdirs to other
libraries.
This also matches the schema under include/osmocom/.

Change-Id: I6c76fafebdd5e961aed88bbecd2c16bc69d580e2
2023-01-18 17:14:06 +01:00
Philipp Maier a13d5662b7 gsm_utils: improve gsm_gsmtime2fn()
The function gsm_gsmtime2fn() uses a hack to account for the truncated
modulo implementation of C/C++. libosmocore offers proven modulo
functions, so lets use OSMO_MOD_FLR() instead. Also arrange the formula
so that it looks more like the one in the spec.

Also add better spec references and a final modulo GSM_MAX_FN to
prevent frame number results that exceed the valid range.

Change-Id: Ibf94bca8223f1f7858a6dd67bf27de0ab6feab20
2023-01-12 15:30:24 +01:00
Vadim Yanitskiy 179dec096f gsm48_ie: gsm48_decode_freq_list(): make 'cd' argument const
Change-Id: Ide9110b984d3302aec6b439c563eb10e2dcdec9e
2023-01-02 12:49:15 +00:00
Vadim Yanitskiy 6db830f316 gsm0808: use new gsm0808_enc_speech_codec[_list]2() API
The motivation behind adding and using the new API is explained in
the preceeding change [1].  Whenever any of the encoding functions
fails to encode either a Speech Codec or a Codec List IE, free()
the msgb and return NULL.

Change-Id: I28219b61b9347f0652f9fd0c717f6cdf3c63e8f9
Related: [1] I199ffa0ba4a64813238519178155dfc767aa3975
Related: SYS#6229
2022-12-14 03:24:51 +07:00
Vadim Yanitskiy 5a51331729 gsm0808: add gsm0808_enc_speech_codec[_list]2()
The problem with most of the existing gsm0808_* functions in this file
is that they assert() too much, assuming that their callers always pass
perfectly valid input parameters.  But this is impossible on practice,
as there can be bugs in complex projects using them, liks osmo-bsc.

It was reported by a customer that a heavily loaded osmo-bsc crashed a
few times, dropping more than 100 sites without network coverage for
a few minutes.  As was revealed during the investigaion, it crashed
due to a failing assert at the end of enc_speech_codec():

  OSMO_ASSERT(sc->cfg == 0);

The problem is that somehow osmo-bsc is passing an unexpected sc->cfg
value to gsm0808_create_ass_compl2(), in particular 0x02, while the
given sc->type value (GSM0808_SCT_HR1) implies that there cannot be
any configuration bits on the wire.

The reason why and under which circumstances this can be happening
is not clear yet, but what we agreed on so far is that the library
API should be enforcing correctness of the input parameters in a
less agressive way, rather than aborting the process without
letting it any chance to recover.

Modify the original gsm0808_enc_speech_codec[_list]() functions, so
that a negative value is returned in case of an error.  Rename them
and add backwards compatibility wrappers, because it's public API.

A separate patch making use of the new API follows next.

Change-Id: I199ffa0ba4a64813238519178155dfc767aa3975
Related: SYS#6229
2022-12-14 03:24:51 +07:00
Vadim Yanitskiy c2f1ed1dd0 gsm0808: remove over-defensive assert()s for function parameters
I believe the gsm0808_* API is mature enough to avoid assert()ing
pointers accepted via function parameters.  We can assume the caller
never passes NULL, as we do in almost all public API.

Change-Id: If9b4c92ace68191f5ddcc0a8a340fccbfe0f3dc0
2022-12-14 02:18:21 +07:00
Vadim Yanitskiy 90b64a1d70 gsm0808: remove redundant assert() in enc_speech_codec()
This assert can be dropped because the switch statement above does
not leave any sc->type >= 0x0f for type_extended == false.

Change-Id: Iafb45ed66378f2c9c2480f81371e92c6d1da71a7
2022-12-14 02:08:40 +07:00
Vadim Yanitskiy 061b7ec434 gsm0808: remove unneeded assignment in enc_speech_codec()
Change-Id: Ifc6d109e27cdada0d08d2a8fc1c354f3de04f15c
2022-12-14 02:06:06 +07:00
Vadim Yanitskiy 8e962451fc gsm0808: cosmetic: switch is not a function
Change-Id: I2f58711675c5c9511c4f4fe4bf0d6e6f7dd093b1
2022-12-14 01:13:19 +07:00
Max 2b283b1a1a LAPD: move tx_hist code into static functions
Related: OS#4074
Change-Id: Ibf3b08c8d874416796b94ba3a672a02d614313b1
2022-11-26 13:59:09 +00:00
Pau Espin 6ca0a43294 gsm: constify several readonly params
Change-Id: Ib11bfe57f546a5618f70152b9b75115808e54bf6
2022-11-24 17:09:03 +01:00
Vadim Yanitskiy 8fbaad6903 */Makefile.am: do not mix up AM_CFLAGS with AM_CPPFLAGS
Change-Id: I2c1d5f9c61714f487fbbe60603b2682f2c0a4c6b
2022-11-10 16:07:03 +00:00
Harald Welte e61d459cef Support building with -Werror=strict-prototypes / -Werror=old-style-definition
Unfortunately "-std=c99" is not sufficient to make gcc ignore code that
uses constructs of earlier C standards, which were abandoned in C99.

See https://lwn.net/ml/fedora-devel/Y1kvF35WozzGBpc8@redhat.com/ for
some related discussion.

Change-Id: I84fd99442d0cc400fa562fa33623c142649230e2
2022-11-03 12:44:28 +01:00
Vadim Yanitskiy 19bd12e919 gsm0502: gsm0502_fn_remap(): use GSM_TDMA_FN_SUB() macro
Change-Id: Id77644d945ad195733d4bf68c0d1c5b450b16e58
2022-10-26 18:13:22 +07:00
Vadim Yanitskiy 73aa0e5219 {gsm,gb}/Makefile.am: drop undefined $GCC_FVISIBILITY_HIDDEN
Change-Id: I142cf38e8954720ed66b0c242a5527c96626dcaa
2022-10-20 04:51:40 +00:00
Max 327e5e990d LAPD: use bool for T200 reset flags
Related: OS#4074
Change-Id: I2d1a3dd7938b079a3525c84647f82b7bc6cdfdd6
2022-10-11 20:01:59 +03:00
Max c569526379 LAPD: log unknown format value
Change-Id: I9efd433ed128ae1d9df45591b1a93e10f8a3372c
2022-10-11 19:47:49 +03:00
Max 68588c57ef cosmetic: make linter happy with LAPD code
The weird formatting not only makes it hard to read but caused linter to fail in the follow-up patch.

Change-Id: Ie4e56b4796c1b8f270a692453faccf102c963db5
2022-10-11 19:34:43 +03:00
Keith Whyte 486d98404d Fix Typo in gsm0808_msgt_names[]
Change-Id: I91585d81efd6e18f4b8f9eaeaaaa50412253d93b
2022-10-06 03:16:15 +01:00
Keith Whyte e852544f6c Fix LCLS-CONNECT-CONTROL generation
gsm0808_create_lcls_conn_ctrl() was adding the LCLS-Configuration IE twice.

Correct is LCLS-Configuration followed by LCLS-Connection-Status-Control
(TS 48.008 3.2.1.91)

Change-Id: I455ac7695ad33ef9073bea7d1711508717732607
2022-10-06 01:12:15 +01:00
Pau Espin 18c6a8183f gsm: bts_features: Add missing entries to osmo_bts_features_names
Those features were present in osmo_bts_features_descs but not in
osmo_bts_features_names.

Change-Id: Ic8162e7ab6b657de694e3825e694e9b18c540271
2022-08-09 17:53:17 +02:00
Pau Espin 83287ba41c gsm: rsl: Define new osmocom extension TLV IE to pass Osmux CID
This is similar to what we already do between BSC<->MSC to pass Osmux
CID (GSM0808_IE_OSMO_OSMUX_CID).
We now want to support Osmux between BSC and Osmocom BTS, hence add an
extension IE which will be used in ipaccess CRCX messages to tell the
BTS to use Osmux.

Change-Id: I580fe99c01bc0a844d877994ec6cd954310e265d
2022-08-09 08:35:55 +00:00
Pau Espin 306400786d gsm: Add BTS feature for Osmux
This feature is used by the BTS to signal to the BSC that it supports
using Osmux instead of RTP on the BTS<->BSC(MGW) data plane.

Related: SYS#5987
Change-Id: Ie79bfb6d0a7a8fe2842d2596b3244e7b74a0d5b6
2022-08-09 08:35:55 +00:00
Pau Espin 9eb698a030 cbsp: Fix decoding of Fail List
The decoding pointer was not increased correctly, ending up in reading
by 1 byte offset  for each item in the list.

Change-Id: I16ed9bd65109a7ce32ff43c5789b4544479838e7
2022-08-06 17:00:48 +00:00
Pau Espin 5563bc998f cbsp: Guard against malformed msgb without l1h,l2h being passed
Change-Id: Ie8854c780cfd96e67df10c1fc38c6b99ec07422f
2022-08-06 17:00:48 +00:00
Pau Espin fdb8f81922 cbsp: Return error if decoding any of the cell id lists fail
Change-Id: I5934167f927df0547cb57687e2717489fd1f3719
2022-08-06 17:00:48 +00:00
Oliver Smith c66b35b616 gsm0808_enc_aoip_trasp_addr: add length check
Instead of running into OSMO_ASSERT in msgb_put(), return early if the
msgb is too small. As suggested by Pau in [1].

I would have returned -EMSGSIZE, but the function returns uint8_t.

[1]: https://gerrit.osmocom.org/c/osmo-bsc-nat/+/28582/2#message-a183c463ea20a8d958465ce45a83e62c46214cf6

Change-Id: I632986b99d841abff0f14c6da65f030175f5c4a1
2022-08-05 14:07:55 +00:00
Mychaela Falconia 605c9e63bb gsm48_ie: fix parsing of Bearer capability IE without octet 3a
The testcase in gsm0408_test is still failing because the encoder
produces a different result (with octet 3a present).  There is no
way to tell the encoder to use the implicit coding, and in general
this is not that critical, so we can live with that.

Change-Id: I722c168f01bffa915cb155eac234a796549d3762
2022-07-03 07:01:15 +07:00
Vadim Yanitskiy 384e6a340c gsm48_ie: fix coding style: while is not a function
Change-Id: Id28bf61c5e1dfb6da1c89a5502eb869b67fed6c6
2022-07-03 06:48:56 +07:00
Pau Espin 8f577fbb5c cbsp: avoid potential msgb write overflow in osmo_cbsp_recv_buffered
>>>     CID 273001:  Insecure data handling  (TAINTED_SCALAR)
>>>     Passing tainted expression "needed" to "recv", which uses it as an offset.
1444                    rc = recv(fd, msg->tail, needed, 0);

Fixes: Coverity CID#273001
Change-Id: I17c558254f9c7907b56d61c53c2f597e8e4566cf
2022-07-01 14:22:09 +00:00
Pau Espin 09e5409cef iuup: Explicitly mark default case as unexpected with assert
That code path should not happen since this function is only called for
data frames coming with IUUP_FSM_EVT_IUUP_DATA_IND.
Control frames should come with specific events like
IUUP_FSM_EVT_IUUP_CONFIG_REQ.
Hence, let's add an assert to make sure we early exit if that ever
happens (it shouldn't), instead of carrying on reading uninitialized var
"dt".

Fixes: Coverity CID#272996
Change-Id: Iaeba59bc9ebfe817dbb7528572dc669c010ef14d
2022-06-29 18:19:38 +02:00
Pau Espin a1584d237b Bump version: 1.6.0.132-0239-dirty → 1.7.0
Change-Id: Idb0d20aa4336a69cb100e140fb1fa9e7ac25b984
2022-06-28 17:00:51 +02:00
Pau Espin 3278f0fb3c iuup: Fix Handling of subsequent Initialization msgs
Once the IuUP FSM moved away from Init state, it stopped handling
Initialization messages received from peers and simply ignored them
starting from that point. As a result, if the first IuUP Init ACK it
sent to the peer was lost, the peer would keep retrying with more IuUP
Init and getting no answer.
In any case, it seems possible and desirable that a peer may send an
IuUP Init at a later point, as pointed out vaguely in 3GPP TS 25.415.

sec 6.5.2.1:
"""
Upon reception of a frame indicating that an Initialisation procedure is
active in the peer Iu UP entity, the Iu UP protocol layer forwards the whole
protocol information contained in the INITIALISATION control frame to the
upper layers. It also stores the RAB sub-Flow Combination set (and thus
replaces a possible previous set) in order to control during the transfer of
user data, that the Iu UP payload is correctly formatted (e.g. RFCI matches
the expected Iu UP frame payload total length). The peer Iu UP entity
receiving the INITIALISATION control frame shall choose a version that it
supports among the proposed versions indicated by the sender for which it
has enough initialisation information.
"""

sec B.2.2 "Initialisation State":
"""
After sending a positive acknowledgement of the last INITIALISATION control
frame, the Iu UP instance enters SMpSDU data transfer ready state. Note that
CN does not know if the initialisation ACK was correctly received by the RNC
(and Initialisation procedure successfully completed) until it receives RAB
assignment response, or use data from the RNC. The CN must therefore be able
to continue receiving INITIALISATION control frames by re-entering the
Initialisation state (from Support Mode Data Transfer Ready State), if the CN
has started to send user data before receiving the indication that
Initialisation was successfully completed
"""

sec B.2.3 "Support Mode Data Transfer Ready State":
"""
In case of handover or relocation, Initialisation procedures may have to be
performed and Iu UP instance may have to enter the initialisation state.
"""

Related: SYS#5995
Change-Id: I5cb740702805693cc7f0a550e2e093f9bfdd507c
2022-06-13 13:51:55 +02:00
Pau Espin 8d7bf4b053 iuup: Drop unused events
Those events are not realy used there and they are not even present in
the FSM definition. Let's drop them.

Change-Id: I4beec96ac4bdf047ebf144a8b009b297b47cacdc
2022-06-13 13:13:59 +02:00
Pau Espin 0664a3e60f iuup: Add missing state to bitmask for st SMpSDU_Data_Transfer_Ready
The event is expected since the user of the IuUP stack can send a
CONFIGURE.req to transition to state null. The handling was already
there in the function, but the bit was missing in the FSM definition.

Change-Id: I830835a5b8b98f8b91b866f5280f508098c9ae7e
2022-06-13 13:12:31 +02:00
Pau Espin 0cdd0abd53 cbsp: Add enum and value string for Cause
Change-Id: I35592bb4fff2e7b442d0e0cd537b66687862baf2
2022-06-09 18:17:43 +02:00
Pau Espin 6d6d22ea34 iuup: Fix IPTIs_present not set to 0 if no IPTIs received
Related: SYS#5969
Change-Id: I503dc509ad8619f13cd83ae03261a2297e2b9fc7
2022-05-27 14:30:30 +02:00
Pau Espin 510f4c9d63 iuup: Rework API to support RFCI IDs != RFCI index
The initially merged IuUP API and implementation assumed that RFCI with
ID was always in the position of its ID inside the list of RFCIs. This
was the case for messages sent by ip.access nano3g as well as our own
osmocom implementation. However it was noticed that other nodes from
other vendors actually use other order, as allowed by the IuUP message
format.
Hence, we need to break the assumption and provide explicit ID
information in the list.

NOTICE: This commit breaks API and ABI compatibility with older versions
of libosmogsm, but not with any previous release of libosmocore since
the API is only available in master so far (it was added in
9fe1f9fb0b).
Similary, it's only user (osmo-mgw) only uses the API in master, so
there's no API breakage with older releases.

Related: SYS#5969
Change-Id: Ib21cee2e30bf83dff4e167f79541796007af9845
2022-05-25 14:10:17 +00:00
Vadim Yanitskiy be5e838dbb Use internal <osmocom/core/talloc.h> everywhere
Change-Id: If40e1eefcfa88a2b376becfe057836acdd3a1cc2
2022-04-27 12:42:15 +00:00
Pau Espin b0c2f75665 jenkins: Validate gsm 08.58 IEs are added to tlv_definition
It was recently found that several IEs which were added in the header
file were not actually added to the tlv_definition, and hence the tlv
parser failed to decode them. Let's make sure we don't foget to add new
IEs in the future.

Related: SYS#5915

Change-Id: Id8a679ca43eb0fcc4882780e9a95ec21c7f51972
2022-04-05 17:38:25 +02:00
Pau Espin 388a53a8d7 rsl: Fix tlv_parse of IPAC_DLCX_IND message
The IE was missing in rsl_att_tlvdef.

Related: SYS#5915
Change-Id: Ib637197ef3508ec94aec05d08d4e6aa15ddea055
2022-04-05 17:32:41 +02:00
Vadim Yanitskiy be1338789a bssmap_le: support additional IEs in Perform Location Request
Change-Id: I8775a93cf4089b1752d040e43d2cba6b8997f955
Related: SYS#5891
2022-03-22 18:38:19 +03:00
Pau Espin 3cf475917e gsm0808: Add missing IEs in bss_att_tlvdef
Change-Id: I8660640ce50a6dc20e718c4165ccf779c5f553a4
2022-03-18 17:36:46 +01:00
Pau Espin fffd7c345b gsm0808: Fix decoding of IE GSM0808_IE_LCS_CLIENT_TYPE
Change-Id: I7acafdefd105e330c466df2e17e884327651e348
2022-03-18 17:36:46 +01:00
Pau Espin 28b404fb71 gsm: lapd_core: Change log line NOTICE->INFO
Change-Id: I71f014645b4b487bf91499a1da9ed2d3032d7e40
2022-03-02 19:03:32 +01:00
Neels Hofmeyr a25a6dca25 BSSAP: HO Request Ack: add missing Codec List (BSS Supported)
Related: SYS#5839
Related: I3c0576505a3ceb3cd5cc31dc69c5bc4a86a4ea08 (osmo-bsc)
Change-Id: Iab0a7b4d81592157fc111d1adb9e9f4cb53a94e9
2022-02-28 11:04:08 +00:00
Pau Espin b5551eec33 gsm: [ABI BREAK] Support CellId SAI, change CellId CGI-PS id number
Those are available in 3GPP TS 48.008 version 16.0.0 Release 16, section
3.2.2.17 Cell Identifier. It can be seen that we have a collision
between the osmocom non-standard format and the SAI standard one.

This is because CGI-PS is not really a TS 48.008 Cell Identifier, but only
specified in TS 48.018 and has no ID number assigned. The CGI-PS was
added there because the whole osmo-bsc neighbour configuration works
with CellIds to manage neighbours, so it felt natural to extend the APIs
to also provide means to use CGI-PS format (TS 48.018 even refers 48.008
existance and mentions there's no explicit ID).

At the time this Cell Identifier was added, the firstly available number
(11) was taken, which was of course a really bad idea since newer
versions of the spec can at some point use it, which is the case if one
checks for instance TS 48.008 Release 16 SAI Cell Id.

There no perfect way to fix this bad decision at the time, but the
CGI-PS is only used in osmo-bsc and only for RIM related purposes, so by
changing the ID of CELL_IDENT_WHOLE_GLOBAL_PS, we only break RIM under
some specific CIs being used, and when an osmo-bsc is built against
older libosmocore and then used at runtime against a newer libosmocore
(which should be rare).
Hence, the downside is acceptable, and by moving the new ID number to be
ouside of the spec proto TS 48.008 range (4 bits), we make sure we don't
have the same problem again in the future.

Related: SYS#5838
Fixes: ca33a71ca8
Change-Id: Id25e563febdb7640174540136225f399515a0089
2022-02-16 17:59:23 +01:00
Vadim Yanitskiy 846db1b3c3 gsm_7bit_encode_n(): use regular malloc() instead of calloc()
In general, it's safe not to use talloc API here because those are
internal allocations, and there are no 'return' statements between
calloc() and free().  However, we don't really need to initialize
the heap memory with 0, so let's use the 'normal' malloc().

Change-Id: I6956cbd83b2999dbcf8e2d210134b0a166c33efb
2022-01-29 01:02:32 +06:00
Philipp Maier bdd7df3c83 iuup: do not use illegal characters in state/event names.
The event names contain '.', and there are spaces ' ' in the state
names. This is a problem since states and events can also be monitored
via the CTRL interface. Unfortunately the CTRL interface does not allow
certain reserved characters. So lets rename the states and event names
to make them compatible with the CTRL interface.

Change-Id: Id19973b56f9d7b1e3d0b0d7c7d0be7beba5428fc
Related OS#4149

Change-Id: I5ebc9ab5b1456fee29aa4e254fae862dc053f0aa
2022-01-18 12:04:47 +01:00
Philipp Maier c7c1ff573b gsm23003: fix docstring for osmo_plmn_from_bcd()
The parameters described in the docstrings for osmo_plmn_from_bcd() do not match the actual parameter list.

Change-Id: Ic0999dbe096a98418db7482bd110e20497d8e4a5
2022-01-14 17:14:15 +01:00
Pau Espin 1322755922 iuup: Improve CRC checksum error logging
Change-Id: I14f2ff14af24f20b788d123c0bfb47aeb0333d19
2022-01-10 13:58:45 +00:00
Pau Espin 604eaba2c3 iuup: Submit RNL-STATUS-Initialization.ind upon rx of Init
This allows init-passive users to get the configured sizes for the RFCIs
and other similar information once engotiated with the peer.

Realted: OS#1937
Change-Id: I63ee780b4aa162ea097410b234e73984000c0965
2022-01-07 13:02:56 +00:00
Pau Espin d3b016fec5 iuup: Fix decoding of 1byte-length subflow size fields
Change-Id: I78ae9e7d46d0725ddec05e004ae22ee5da738162
2022-01-05 23:09:17 +00:00
Harald Welte 29814a5374 iuup: Fix signed/unsigned loop counter control flow issue
The use of an unsinged integer as for loop counter variable doesn't
work when counting down and comparing with >= 0.  The existing code
would be an infinite loop if it wasn't for the (data dependent) break
condition:

>>>     CID 243259:  Control flow issues  (NO_EFFECT)
>>>     This greater-than-or-equal-to-zero comparison of an unsigned value is always true. "i >= 0U".
572             for (i = 15; i >= 0; i--) {
573                     if (match_mask & (1<<i)) {
574                             iui->mode_version = i;
575                             break;
576                     }

Change-Id: I019d0f0d8f2b167575a2883a13cca692c96961cf
Closes: CID#243259
2021-12-24 11:35:57 +01:00
Harald Welte 9fe1f9fb0b Introduce CRC and FSM for IuUP (user plane) as used in 3G RTP data
Only support for SMpSDU mode is introduced in this commit.

Not supported explicit list:
- Transparent mode
- ATM/AAL2 based Transport layer
- GTP-U based Transport Layer
- Iu Rate Control procedure
- Time Alignment procedure

APIs are provided to allocate the primitives properly inside the related
msgb. This way primitives can be placed in the headroom, leaving the
data part of the msgb for the IuUP payload, hence allowing re-use of the
msgb and 0 copy of IuUP payload when forwarding data over RNL<->TNL.
Since RNL and TNL primitives relu struct osmo_prim_header, which is not
packed, they cannot be set to packed, and hence proper memory alignment
in the msgb must be done to avoid misaligned accesses (Asan errors about
it otherwise).

Related: SYS#5516
Change-Id: Ibe356fa7b1abaca0091e368db8478e79c09c6cb0
2021-12-22 14:58:31 +01:00
Oliver Smith 04bfb7165b treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I5050285e75cf120407a1d883e99b3c4bcae8ffd7
2021-12-14 12:44:03 +01:00
Pau Espin c7deaf28aa Bump version: 1.5.1.282-ab5e-dirty → 1.6.0
Change-Id: Ia3ac0a36b9e898996f596c6d2787e03cd59bfc11
2021-11-16 13:08:23 +01:00