Commit Graph

4342 Commits

Author SHA1 Message Date
Max 173bf03fbb Add osmo_sock_get_name_multiaddr_buf()
It's similar to osmo_sock_get_name_buf() but supports multi-homed SCTP sockets
bound to several addresses.

Related: OS#5581
Change-Id: If76595ebd1cf26ba904887a36c4cc14a1b5c4521
2022-10-01 23:28:47 +07:00
Max cd189f7a61 Update multiaddr helper
* use osmo_strbuf instead of plain buffer
* properly handle OOM
* remove default "0.0.0.0" on empty input
* fix missing trailing ')'

Related: OS#5581
Change-Id: Icef53fe4b6e51563d97a1bc48001d67679b3b6e9
2022-10-01 23:22:58 +07:00
Vadim Yanitskiy 395db204b4 include: use '#pragma once' everywhere
Change-Id: Iecc1754caae401aca28444d3e3d0cca04b398f26
2022-09-29 05:44:09 +00:00
Alexander Couzens 71ad530f7e gb: add bssgp2_enc_flush_ll encode FLUSH-LL
Change-Id: I76dc3b08a63cfd78c9f7657fb58c2ddfa9b4b7e2
2022-09-28 18:14:28 +02:00
Neels Hofmeyr 70093f23ad comments: gsm_08_08.h: AMR cfg: explain in much more detail
Change-Id: I1864a6beeeedc301c6dc7e2e0c52a3f94b2fef01
2022-09-25 20:26:21 +02:00
Pau Espin c3b904a87d vty: Allow using hex representations in cmd numeric ranges
Ranges can now be specified in hexadecimal notation. In this case, only
hexadecimal values are accepted (prefixed with "0x").

In order to allow using a hexadecimal value as an input argument, the
command must specify the range in hexadecimal form.
This way all existing commands (decimal) won't get an hexadecimal value
unless they are further extended in the future, avoiding hard to notice
breakage due to use of stroul() without using base=0 or even worse,
using atoi() directly (which only understands decimal and provides no
error checking mechanism).

A command argument can be expanded to accept both decimal and hex in a
range by means of specifying both, example:
"mycmd (<0-255>|<0x0-0xff>)".

Related: OS#5631
Change-Id: Ia2b7fbbf5502c28374c21dbff548232680da27d4
2022-09-15 16:25:56 +02:00
Pau Espin 812766e231 utils.h: protect param with parenthesis in OSMO_BYTES_FOR_BITS()
While at it, drop 8-1 in favour of 7. I don't think it is really more
understandable for readers to see some subtraction there...

Change-Id: I8b21eba9b9aa952f86abe7a6d4cdb1d1a61d9deb
2022-09-08 15:03:44 +02:00
Neels Hofmeyr a7f97b9093 gsm0408_test: do not print errno in expected output
The errno values are platform dependent. Printing them in the expected
output causes failure on some systems that don't match my development
system.

Still check for match with the expected errno value, but don't print the
actual value in gsm0408_test.ok.

Related: OS#4842
Change-Id: I87d125fb4e04b2130f653db1ed76691528e43411
2022-08-23 18:37:20 +02:00
Daniel Willmann d5150a61fc use_count: Return if uc is NULL
The documentation for osmo_use_count_get_put states the return value is
"Negative on range violations or USE_LIST == NULL, the use_cb()'s
return value, or 0 on success"

However, the code in _osmo_use_count_get_put doesn't check if uc is NULL
- instead it would crash in osmo_use_count_find() where it is dereferenced.
Add a check for uc and return -EINVAL if it is NULL.

Change-Id: I792563696860a3100e95cafdd5fe57511819ef56
Related: SYS#5895
2022-08-18 14:13:28 +00:00
Neels Hofmeyr 709da278ca Revert "Add function to guess AF_UNSPEC address"
This reverts commit a4063efa7d.

Reason for revert: It is not possible to guess the IP address
family from uninitialized memory. This function simply glorifies
random noise into an IPv6 address. It makes no sense to have it.

Change-Id: Ifadd614604cf9d0c2ed1a405493c1c3fcb37ae23
2022-08-17 14:05:18 +00:00
Neels Hofmeyr 9e4c2ebf18 Revert "Add osmo_sockaddr_strs_to_str()"
This reverts commit e145e28a91.

Reason for revert:
The function osmo_sockaddr_strs_to_str() should not be part of the
osmo_sockaddr_str API. The implementation of this should live in
the function multiaddr_snprintf() added in patch
Icef53fe4b6e51563d97a1bc48001d67679b3b6e9
and should not use dynamic allocation.

Change-Id: I263dfd68313b896c5b474025fbca13c22ce41cdc
2022-08-17 01:01:16 +00:00
Max e145e28a91 Add osmo_sockaddr_strs_to_str()
This will come in handy for working with multihomes sockets like SCTP.

Related: OS#5581
Change-Id: Ic0d7c08f669994e37a2314555ecac85d28c42c89
2022-08-14 12:21:12 +07: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
Max a4063efa7d Add function to guess AF_UNSPEC address
Sometimes we receive generic "struct sockaddr" with unspecified (AF_UNSPEC)
address family. It's handy to try to guess
the proper address (there're just 2 variants ATM in most practical applications).

Use the added function to relax input checks in osmo_sockaddr_str_from_in*()

Related: OS#5581
Change-Id: I1c90c56ce832f53b65e0d18d3cea94621c02a69a
2022-08-09 08:58:49 +00:00
Max ec87a9494d Ignore osmo-ns-dummy
Change-Id: Id562988942be13b83c552bdaa1ad93e275b3d0ae
2022-08-09 08:55:57 +00: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 862dd36318 tlv.h: Fix TLVP_PRESENT returning a pointer instead of a boolean
I was warned by gcc about comparing a pointer with an integer when using
TLVP_PRESENT with something like:
bool expect = ...;
if (expect != TLV_PRESENT(...))

That's indeed dangerous because TLV_PRESENT is considered to return a
boolean, as opposite to TLV_VAL.

Change-Id: I45cc2745c695e30c37b10f592903ec3775a55492
2022-08-08 20:07:15 +00:00
Pau Espin 6960b6a855 cosmetic: tlv.h: Fix trailing whistespace
Change-Id: Ief318882def539b35ef15c85566f69220e7edbfe
2022-08-08 20:07:15 +00:00
Neels Hofmeyr aafa2b3a67 enrich API doc for gsm0808_speech_codec
Change-Id: Iee52f38c1040b7f7ee37aaa58cfdb0cb6cf33f4d
2022-08-08 18:47:25 +02:00
Alexander Couzens d13faaa968 gprs_ns2: add vty `nse <0-65535> restart sns`
Allow to restart SNS procedure and initiate a SNS-SIZE procedure with Reset.
SGSN side SNS restart will stop answer on ALIVE and is sending NS STATUS
invalid protocol state.
BSS side SNS restart will send a SNS Size procedure to reset the state.

Change-Id: Icb55d8449908d348ab10572eebcf971737fba00d
2022-08-06 17:12:07 +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 061f96d038 tests: Run smscb/gsm0341_test during make check
Some initial testing for that module was writen to apparently do some
manual tests (rand()) but were never added to testsuite.at.
Let's make sure they run during make check (make the test deterministic
by removing rand()).

Change-Id: Icd4feced06afb749de994195c6b338df006749ad
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
Vadim Yanitskiy dd20f7c3c3 {gb,sim,usb}: ensure -no-undefined is present in *_la_LDFLAGS
Make sure that there is no undefined references in shared libraries.

Inspired by GitHub PR#6 [1] by Michael Dickens.  Tweaked by me.

Change-Id: I7ddd6c75935b0f25d78a948f1577656d77a204e3
Related: [1] https://github.com/osmocom/libosmocore/pull/6
2022-08-05 11:48:38 +00:00
Vadim Yanitskiy 8137d9a0f0 logging: add a new category DLCSN1 for libosmo-csn1
This new category is going to be used by CSN.1 codec in libosmo-csn1.

Change-Id: Ie8c0effb764547a0f9cc8c6825e11a6617501e95
2022-08-04 02:32:13 +07:00
Vadim Yanitskiy b3e3a5d215 fsm: osmo_fsm_{event,inst,state}_name(): make *fi pointer const
Change-Id: I98cde213deb5a3bf39eb9f5e5451f40223632844
2022-07-29 00:06:48 +07:00
Pau Espin 0893f0f631 gsm_23_041.h: Define CBS ETWS Warning Type values
Change-Id: I3a5bb9b2c77b8e4a984631d199fc073183691c31
2022-07-25 10:43:45 +02:00
Vadim Yanitskiy b6629ddfc9 gb/gprs_ns: call osmo_timer_del() unconditionally
osmo_timer_del() does check if a timer is active internally.

Change-Id: I3fdfcde33bc6f8a88680ad3f1dde2b6ff8846020
2022-07-22 03:34:04 +07:00
Harald Welte d6a49ce9ad sim/class_tables: Add GET IDENTITY, SUSPEND UICC, EXCHANGE CAPABILITIES
This brings the tables up-to-date with Release 16 of both
ETSI 102 221 + 3GPP TS 31.102 specifications.

Change-Id: I7100f326f45f1f8742363eace0531a4ef3f049c0
2022-07-20 18:33:07 +02:00
Vadim Yanitskiy 342a522991 tests/tdef: assert pointer returned by osmo_tdef_get_entry()
Coverity complains that we do check if osmo_tdef_get_entry() returns
NULL 39 out of 40 times.  Check it in test_tdef_set_and_get() too.

Change-Id: I96041eab2786d850a49cb38a60a368cef2e476d3
Related: CID#274729
2022-07-20 05:11:25 +07:00
Vadim Yanitskiy 76bdbd4b2b fsm: fix state_chg(): pass microseconds to osmo_timer_schedule()
As was demonstrated in [1], osmo_fsm_inst_state_chg_ms() is broken.
The problem is in state_chg(): this function is passing *milli*seconds
to osmo_timer_schedule(), while it expects *micro*seconds.

Change-Id: Ib0b6c3bdb56e4279df9e5ba7db16841645c452aa
Related: [1] I5a35730a8448292b075aefafed897353678250f9
Fixes: I35b330e460e80bb67376c77e997e464439ac5397
Fixes: OS#5622
2022-07-19 15:32:36 +07:00
Vadim Yanitskiy d2964a94c2 fsm: add unit tests verifying state timeout s/ms accuracy
This change adds test_state_chg_Ts() and test_state_chg_Tms() checking
state timeout s/ms accuracy when using osmo_fsm_inst_state_chg() and
osmo_fsm_inst_state_chg_ms() calls, respectively.

test_state_chg_Tms() demonstrates that osmo_fsm_inst_state_chg_ms()
is not working as expected: the timeout fires earlier than expected.

Change-Id: I5a35730a8448292b075aefafed897353678250f9
Related: OS#5622
2022-07-19 06:09:05 +07:00
Vadim Yanitskiy 0578c288ec gb: fix uninitialized ptr access in bssgp_encode_rim_pdu()
Jumping to label 'error' before allocating memory and storing an
address to pointer 'rim_cont_buf' would result in passing garbage
to talloc_free().  Found with clang 14.

Change-Id: I9420615b64d3755fd9131e8561c516c39f83a15b
2022-07-04 20:50:17 +07: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
Vadim Yanitskiy 95fc8ea056 gsm0408_test: add a testcase for gsm48_decode_bearer_cap()
The new testcase contains a Bearer capability IE from Siemens S11E,
which does not use octet 3a (no extension bit set in octet 3).
gsm48_decode_bearer_cap() currently fails to parse it.

Change-Id: Ia19f3f6d80bc09ca3f8d39d35b148a0c0245141f
2022-07-03 06:48:44 +07:00
Vadim Yanitskiy 1a077cb0ca gsm0408_test: do not return early in test_bearer_cap()
Currently, if one of the testcases fails, test_bearer_cap() would
abort and skip the remaining testcases.  Also, a msgb would not
be free()ed making the LeakSanitizer unhappy.

Instead of returning early, jump to the end of loop to ensure that:

* the verdict ('passed' or 'failed') is always printed,
* all remaining testcases are still executed,
* the msgb is free()ed.

Change-Id: I39ac801e59ba56dfe3bcd4603b48f6fbf7cfb21c
2022-07-03 06:07:09 +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
Vadim Yanitskiy 4f41d59f08 fix uninitialized err pointer passed to osmo_bssap_le_dec()
osmo_bssap_le_dec() dereferences value of the given pointer and
checks it against NULL.  The caller must always initialize it.

Change-Id: Id91dc73da1ca71827183564eb68b12c03ba332b3
2022-06-29 11:30:24 +00: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
Harald Welte 0239620bd1 update git URLs (git -> https; gitea)
Change-Id: I22bc1dd5c8a33fbccc8cc6d0d8daf7f558f17f44
2022-06-17 23:20:26 +02:00
Pau Espin 079149e451 vty: command.c: Add assert
a program being developed right now crashed at this point, without
providing any meaningful information on where did it crash.

Change-Id: Ia14f43142e7409f72eb9efd5c9131bea5eed6e82
2022-06-17 20:28:01 +00:00
Neels Hofmeyr 044f0cd64c cosmetic tweak in Makefile.am
Change-Id: I141e502ffbb1a45f9751943d47766bdfbf77484a
2022-06-14 19:45:02 +02:00
Karsten Ohme 6772dd7c01 APDU parsing support for GlobalPlatform
This patch addes support for GlobalPlatform command. Android is using
STORE DATA commands on a logical channel.
simtrace2-cardem-pcsc is failing otherwise e.g. on an Pixel 4 with Android 12.

Change-Id: Ib734fc852e7b63b9efdc414adccbd796a572eb55
2022-06-13 19:09:04 +00: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 f62e01a077 tests/iuup: Showcase IuUP stack not answering subsequent Init msgs
This test shows a bug in IuUP stack which makes it only handle the first
Initialization IuUP message. After it moves to SMpSDU, it stops handling
Initialization messages.
A fix is provided in a follow up patch.

Related: SYS#5995
Change-Id: I72c2c2d88f158f3ef35724fcb73854a1827aaab4
2022-06-13 13:14:28 +02:00