Commit Graph

1804 Commits

Author SHA1 Message Date
Harald Welte b3f94eb39e fsm.c: Print error message for FSM with allstate_action but no events
As suggested by Vadim while reviewing a related fix for ipa_keepalive.c
in libosmo-abis (see https://gerrit.osmocom.org/#/c/libosmo-abis/+/13540/),
it makes sense to print an error message if anyone registers a FSM
that specifies an allstate_action callback but at the same time no
events that would ever end up in that callback.

Change-Id: I9e73f7363ab15a00843e3f0d1e5776f4be7ebc46
2019-06-15 10:54:26 +02:00
Pau Espin 32e6710487 vty: command.c: Fix: single-choice optional args are no longer passed incomplete to vty func
For instance, take command "single0 [one]":
If user executes "single0 on", VTY func will receive argv[0]="one"
instead of argv[0]="on".

Related: OS#4045
Change-Id: I5f4e2d16c62a2d22717989c6acc77450957168cb
2019-06-14 17:44:21 +02:00
Pau Espin 7e1b03f763 vty: command.c: Fix: multi-choice args are no longer passed incomplete to vty func
For instance, take command "multi0 (one|two|three)":
If user executes "multi0 tw", VTY func will receive argv[0]="two"
instead of argv[0]="tw".

Fixes: OS#4045
Change-Id: I91b6621ac3d87fda5412a9b415e7bfb4736c8a9a
2019-06-14 17:44:16 +02:00
Pau Espin 8930ace072 vty: command.c: Get rid of big indentation block
This block will become bigger in forthcoming commits.

Change-Id: Ibc1494014b1e77ce10950f7268a44d2d2091a6f2
2019-06-14 12:42:22 +02:00
Pau Espin c17c6d6ea5 command.c: Improve return check condition in cmd_execut_command_real()
Check against MAX argc is changed to == since it cannot be incremented
twice without passing the check.

Change-Id: Ia330e475989fda863bedcc3cbf94deaf8dd83037
2019-06-14 12:38:44 +02:00
Pau Espin cc794e993c logging: Use reentrant ctime_r instead of ctime
It was noticed that multithreaded processes like osmo-trx can crash upon
using ctime().

Related: OS#4055
Change-Id: I19ebf29a2f1fc855bb7d56766b338c7c3432dfd1
2019-06-13 19:35:11 +02:00
Pau Espin 3aef238980 logging: Check return error from time() call
Related: OS#4055
Change-Id: Ief155a76169426a677256e09d3e91751c4e2529f
2019-06-13 15:34:01 +00:00
Kevin Redon 1af2cd5624 fix isdigit taking unsigned as input
fixes the following error warnings when cross-compiling using:
./configure --enable-static --prefix=/usr/local/arm-none-eabi --host=arm-none-eabi --enable-embedded --disable-doxygen --disable-shared --disable-pseudotalloc --enable-external-tests CFLAGS="-Os -ffunction-sections -fdata-sections -nostartfiles -nodefaultlibs -Werror -Wno-error=deprecated -Wno-error=deprecated-declarations -Wno-error=cpp -mthumb -Os -mlong-calls -g3 -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -Wno-error=format"

utils.c:1002:18: error: array subscript has type 'char' [-Werror=char-subscripts]
 1002 |   if (!isdigit(in[i]))

gsm23003.c:414:34: error: array subscript has type 'char' [-Werror=char-subscripts]
  414 |  if (!mnc_str || !isdigit(mnc_str[0]) || strlen(mnc_str) > 3)

Change-Id: Ia13fd5ee79fc6dc3291c0b99958ab3c01afee17d
2019-06-13 13:49:30 +00:00
Pau Espin 274ac4dcc3 vty: command.c: Get rid of huge indentation block
Huge conditional block inside for loop is negated in this patch
together with a "continue" keyword, similar to what was already done
recently in 4742526645.

Change-Id: I803c4ed38e9ab09bf929528c75a60e6f65da3928
2019-06-12 14:25:11 +00:00
Pau Espin de89099f68 cosmetic: vty: command.c: Use upper case for enum match_type value names
Makes code easier to follow because enum values no longer look like
variables.

Change-Id: Ib6e9592c5962d047869a280c10f9b557fae6f435
2019-06-12 14:25:11 +00:00
Vadim Yanitskiy d9fc6041e7 core/utils: drop meaningless const from return value of osmo_luhn()
Change-Id: I085da06f31a0a6862ae2ba041fafc134cc240f7e
2019-06-12 11:29:06 +00:00
Pau Espin 6df2e44404 vty: command.c: Fix is_cmd_ambiguous() returning always 0
inner block defined variable "enum match_type ret" was being masking
outter block variable "int ret = 0". The ret variable was being given
non zero values only inside the inner block, so that change was done on
the inner variable and not the outer one, which is returned.

Fixes: 5314c513f2
Change-Id: Iec87d7db49a096d07e38ff8a060b923a52bfd6ba
2019-06-11 21:50:17 +02:00
Pau Espin 4742526645 vty: command.c: Get rid of huge indentation block
Huge conditional block inside foor loop is negated in this patch
together with a "continue" keyword.

Change-Id: I9715734ed276f002fdc8c3b9742531ad36b2ef9e
2019-06-11 21:04:11 +02:00
Oliver Smith 186f878266 gsm48_decode_bcd_number2: fix ENOSPC edge case
Return ENOSPC if the decoding buffer is one byte too small, instead of
returning 0 and silently truncating the string. Add a new "truncated"
variable to detect if the loop breaks in the final iteration.

The string is not truncated if there is exactly one 0xf ('\0') higher
nibble remaining. This is covered by the existing test case "long
15-digit (maximum) MSISDN, limited buffer".

Related: OS#4049
Change-Id: Ie05900aca50cc7fe8a45d17844dbfcd905fd82fe
2019-06-07 11:01:51 +02:00
Harald Welte cb5e8312b6 fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements
Instead of copy+pasting the same LOGPFSMSRC("State change to " ...)
with slightly different trailer depending on the FSM timer, let's first
snprintf() to a stack variable and then have a single log statement.

Change-Id: I49528c4ca1fa11aef09c2092615dccca450b847c
2019-06-05 10:01:20 +00:00
Harald Welte 7b74551b93 fsm: Allow millisecond granularity in osmo_fsm built-in timer
So far, the public API of osmo_fsm only allowed integral seconds as
timeout.  Let's change that to milli-seconds in order to cover more
use cases.

This introduces
* osmo_fsm_inst_state_chg_ms()
* osmo_fsm_inst_state_chg_keep_or_start_timer_ms()

Which both work exactly like their previous counterparts without the _ms
suffix - the only difference being that the timeout parameter is
specified in milli-seconds, not in seconds.

The value range for an unsigned long in milli-seconds even on a 32bit
platform extends to about 48 days.

This patch also removes the documentation notice about limiting the
maximum value to 0x7fffffff due to time_t signed-ness.  We don't use
time_t but unsigned long.

Change-Id: I35b330e460e80bb67376c77e997e464439ac5397
2019-06-05 10:01:20 +00:00
Harald Welte 7a56952307 lapd_core: Perform N200 retransmissions, not N200-1
During testing with BTS_Tests_LAPDm.TC_t200_n200() it was discovered
that the existing LAPD[m] implementation always gave up at N200-1
retransmissions, rather than N200 retransmissions.

The first transmission doesn't count, and hence we must have N200
actual re-transmissions.  The Error message is then described as
"T200 expired N200+1 times", i.e. we start T200 one more time after
the last re-transmission and only give up if it expires again (i.e.
no ACK received)

Change-Id: Ic33854ee61311f73b7db55eeef10280349151097
Related: OS4037
2019-06-05 10:01:20 +00:00
Harald Welte 20de6207c2 lapdm: Allow user to specify T200 values; Use correct N200 values
TS 04.06 specifies a N200 re-transmission counter that depends on the
channel type, which we didn't care about at all so far.  Let's have the
caller tell us the channel type so we can internally look up the correct
N200 value for it.

At the same time, permit the user to specify T200 re-transmission timer
values for each SAPI on both DCCH and ACCH, which is required at least
in the BTS as per GSM TS 12.21.  Also, extend the timer resolution of
the API from seconds to milli-seconds, which is more applicable as
particularly on the FACCH the recommended values are in the 200ms range.

Change-Id: I90fdc4dd4720d4e02213197c894eb0a55a39158c
Related: OS#3906
Related: OS#2294
Related: OS#4037
2019-06-05 10:01:20 +00:00
Harald Welte ef7be49a32 gsm0808_utils: Add gsm0808_decode_cell_id_u()
This function parses a single Cell ID list element into a
'union gsm0808_cell_id_u'.  This function is going to be used
by the upcoming CBSP support.

Related: OS#3537
Change-Id: I08b33881667aa32f01e53ccb70d44d5b79c7c986
2019-06-04 11:05:20 +02:00
Harald Welte 171ef826e1 make all library-internal static buffers thread-local
We have a number of library-internal static global buffers which are
mainly used for various stringification functions.  This worked as
all of the related Osmocom programs were strictly single-threaded.

Let's make those buffers at least thread-local.  This way every thread
gets their own set of buffers, and it's safe for multiple threads to
execute the same functions once.  They're of course still not
re-entrant.  If you need re-entrancy, you will need to use the _c()
or _buf() suffix version of those functions and work with your own
(stack or heap) buffers.

Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07
2019-06-04 10:47:30 +02:00
Harald Welte 2e78f900cf lapdm: Don't truncate L3 payload at 200 bytes length
3GPP TS 04.06 is quite clear that the [segmented] L3 payload can be as
long as 251 bytes.  Our libosmocore lapdm implementation truncated
already at 200 bytes :(

Change-Id: I6769986f27dda1d429ed7b2e32c36d34663acba9
Closes: OS#4035
2019-06-02 08:17:59 +00:00
Vadim Yanitskiy b606d76813 socket.c: fix Doxygen doc for osmo_sock_unix_init_ofd()
One typo s/optionall/optionally/, and a few incorrect references.

Change-Id: Iab42aa376b5cf4cf36413fede46e001c6b2d1525
2019-06-01 19:03:07 +07:00
Vadim Yanitskiy f5781c9a88 vty/command.c: cosmetic: add missing curly brackets
Otherwise it's a bit hard to read the code.

Change-Id: I807ec71cfb67976251be844cdb2d2776b1837438
2019-06-01 02:27:16 +07:00
Vadim Yanitskiy 1dc82643c5 gsm48_encode_bcd_number(): clarify optional LHV header initialization
Change-Id: Iafd911dd55691b3715391e3899cd6971245c8d7f
2019-05-29 08:48:46 +00:00
Harald Welte bdf70347fb rest_octets: Remove SI2ter + SI2bis encoders that don't do anything
The library should either provide functions that implement encoding
of those rest octets, or it shouldn't.  Providing a function that
doesn't do anything but pad the buffer is useless.

Change-Id: Ie10684de6a6b2663e2a871fcdb2b275b6ad7a1e7
2019-05-28 20:02:04 +02:00
Harald Welte 86156de20e rest_octets: Implement actual SI6 rest octets encoding
There's very little sense behind introducing a function into
libosmogsm which doesn't implement 90% of the spec.  Let's allow
the caller to provide the various optional bits of information to
the encoder, rather than generating mostly static SI6 rest octets.

Change-Id: Id75005a0c4a02ce7f809692d58b3bd226bc582b2
2019-05-28 20:02:04 +02:00
Harald Welte f85b33f68f rest_octets: Add function to parse SI3 rest octets
Change-Id: I690cf308311f910005a325d50f5d5d825678d2b2
Related: OS#3075
Related: OS#4023
2019-05-28 20:02:04 +02:00
Harald Welte 428d03b919 rest_octets: Suffix encoder functiosn with _encode
... otherwise it's not really clear what they do.

Change-Id: I08e0ca9a8d13c7aa40b9d90f34f0e13adb87d4e0
2019-05-28 20:02:04 +02:00
Harald Welte 2fbb97f97c rest_octets: Fix export of osmo_gsm48_rest_octets
the symbols had an omso_ prefix, while the entry in the .map file
didn't.  As a result, all related symbols were never exported and
hence not usable by any users of the dynamic library.

Change-Id: I8b1ee2405f6338507e9dfb5f1f437c4c2db2e330
2019-05-28 20:02:04 +02:00
Harald Welte c4cfeb75b5 rest_octets: Actually include gsm48_rest_octets.c in Makefile.am
The gsm48_rest_octets.c file was added in Change-Id
I47888965ab11bba1186c21987f1365c9270abeab, but it never actually
ended up being compiled as it wasn't listed in the makefile :/

Change-Id: I0355115c2645f236c9e32cf7a563cf51a857e8a3
Relsted: OS#3075
2019-05-28 20:02:04 +02:00
Harald Welte 1276c17bd6 rest_octets: Use correct symbols names for range encoder
As gsm48_rest_octets.c is not listed in the Makefile.am, it's
never actually compiled and we never noticed that it's calling
functions by symbol names that don't exist :/

Change-Id: I7b1e436f70e0c60979261db87606f38271ec47d3
Related: OS#3075
2019-05-28 20:02:04 +02:00
Harald Welte 912d96db9f gsm48_rest_octets: Fix license: GPLv2+ instead of AGPLv3+
libosmo{core,gsm,vty} code is GPLv2+.  The rest octet code originated in
osmo-bsc.git and was moved here without changing the license. That was a
mistake, it always was meant to be under GPLv2-or-later after moving to
libosmocore.git.

Original copyright is mine.  For contributions by sysmocom, I as the
managing director can approve the license change.

This means only Holger needs to ACK this.

Change-Id: Ief3009dc28dd83e1e26a7101af2eed2341684a87
2019-05-28 18:01:35 +00:00
Vadim Yanitskiy e4799f5603 gsm48_decode_bcd_number2(): return -EINVAL if LV has too big length
Change-Id: Ie07b2e8bc2f9628904e88448b4ee63b359655123
2019-05-28 06:50:41 +07:00
Vadim Yanitskiy 7194087457 gsm48_decode_bcd_number2(): fix: return -ENOSPC on truncation
The documentation of gsm48_decode_bcd_number2() clearly states that
the output truncation is a erroneous case, so it should actually
return negative in such cases. Let's return -ENOSPC.

Change-Id: I75680f232001ba419a587fed4c24f32c70c3ad2b
2019-05-28 06:50:41 +07:00
Vadim Yanitskiy 2cd1dda631 gsm48_decode_bcd_number2(): fix output truncation
Thanks to the new unit test for BCD number encoding / decoding, it was
discovered that gsm48_decode_bcd_number2() does not properly handle
encoded LV if the output buffer size is equal to the original MSISDN
length + 1 (\0-terminator): one digit is lost.

For example, decoding of 15-digit long MSISDN to a buffer of size
16 (15 digits + 1 for \0) would give us only 14 digits.

The problem was that 'output_len' was being decremented before
checking the remaining buffer length and writing a digit to it.
As a result, the maximum length was always one byte shorter.

Change-Id: I61d49387fedbf7b238e21540a5eff22f6861e27a
Fixes: OS#4025
2019-05-28 06:50:41 +07:00
Harald Welte 581a34da60 tdef: Fix license: GPLv2+ instead of AGPLv3+
libosmo{core,gsm,vty} code is GPLv2+.  The tdef code originated in
osmo-msc.git and was moved here without changing the license. That
was a mistake, it always was meant to be under GPLv2-or-later after
moving to libosmocore.git.

Copyright is with sysmocom, so I as the managing director can
approve the license change.

Change-Id: Ie483ff6f6ea0a56c477649677b4b163c49df11d7
2019-05-27 23:26:45 +02:00
Harald Welte c53afd95c5 oap_client: Fix license: GPLv2+ instead of AGPLv3+
libosmo{core,gsm,vty} code is GPLv2+.  The OAP code originated in
osmo-msc.git and was moved here without changing the license. That
was a mistake, it always was meant to be under GPLv2-or-later after
moving to libosmocore.git.

Copyright is with sysmocom, so I as the managing director can
approve the license change.

Change-Id: I08311fa8214c15f8df8945b9894226608cf96f15
2019-05-27 23:26:45 +02:00
Harald Welte a8d7ebb6fb rsl: Add osmocom-specific extensions to RSL channel numbers for CBCH
We don't really *need* it in libosmocore as such, but the lack of
having all osmocom extensions listed here lead to using overlapping
definitions: 0x18 was used for dynamic PDCH on the Abis side, but also
for CBCH on the L1SAP side.  Let's list them all here to increase
visibility in case anyone wants to extend this further...

Related: OS#4027
Change-Id: I93e557358cf1c1b622f77f906959df7ca6d5cb12
2019-05-27 17:20:38 +02:00
Harald Welte 7023aa0af9 lapdm_rslms_recvmsg: Fix memory leak in error path
The caller of lapdm_rslms_recvmsg() (e.g. osmo-bts/src/common/rsl.c)
assumes the message ownership is transferred.  However, in one of the
two error paths, msgb_free() was not called and hence we had a memory
leak.

Also clarify the msgb ownership transfer in a comment.

Related: OS#3750
Change-Id: Id60cb45e50bfc89224d97df6c68fcd2949751895
2019-05-19 12:19:02 +02:00
Harald Welte 8006f5393e TLV: Add one-shot TLV encoder
So far, the TLV code contained two types of functions
* tlp_parse() to parse all TLVs according to definition into tlvp_parsed
* various helper functions to encode individual TLVs during message
  generation

This patch implements the inverse of tlv_parse(): tlv_encode(), which
takes a full 'struct tlv_pared' and encodes all IEs found in it.  The
order of IEs is in numerically ascending order of the tag.

As many protocols have different IE/TLV ordering requirements, let's add
a tlv_encode_ordered() function where the caller can specify the TLV
ordering during the one-shot encode.

Change-Id: I761a30bf20355a9f80a4a8e0c60b0b0f78515efe
2019-05-19 07:33:32 +00:00
Harald Welte 5f46605aee pseudotalloc: turn talloc_steal() into #define
Any non-anciant version of talloc implements talloc_steal()
as a #define using the _talloc_steal_loc() symbol.  Let's be
more compatible.

This fix is relevant to using osmo_fsm inside the osmo-ccid-firmware
builds for Cortex-M4.  In this situation, for some strange reason,
libosmcoore is compiled using src/pseudotalloc/talloc.h, but later then
linked against the real libtalloc.

Change-Id: I1ee7f5e9b1002cff37bb8341ad870e1da5f1f9ff
2019-05-18 11:08:40 +02:00
Sylvain Munaut 35f8ba0b7f codec/ecu: Add a bit of precision about the actual frame format used
Change-Id: I9620088e449c31e966ecb9ec5ddf283b949c5a4a
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2019-05-15 17:34:13 +02:00
Oliver Smith cdac620579 gsm_23_003: add GSM23003_MSISDN_{MIN,MAX}_DIGITS
Add the constant, so it can be used in create-subscriber-on-demand
related patches. ITU-T Rec. E.164 6.1 states that maximum international
number length should be 15. I did not find a source for a minimum
length, but I've added the constant and set it to 1 for consistency
(based on the existing osmo_msisdn_str_valid() function).

Related: OS#2542
Change-Id: Idc74f4d94ad44b9fc1b6d43178f5f33d551ebfb1
2019-05-15 08:52:50 +00:00
Pau Espin 18506c850c gsm0808: Introduce Osmocom extensions to announce Osmux support
IE GSM0808_IE_OSMO_OSMUX_SUPPORT (T, 1 byte) is sent in AoIP appended to
BSSMAP RESET in order to announce the peer that its MGW supports handling
Osmux streams upon call set up.

IE GSM0808_IE_OSMO_OSMUX_CID (TV, T 1 byte & V 1 byte) is sent in AoIP
during call set up:
* MSC->BSC Assignment Request
* BSC->MSC Assignemnt Complete

The 1 byte value contains the local Osmux CID, aka the recvCID aka CID where the
peer sending the Assign Req/Compl will look for Osmux frames on that
call. Hence, the peer receiving this CID value must use it to send Osmux
frames for that call.

As a result, a given call leg BSC<->MSC can have one different Osmux CID
per direction. For example:
* MS => MGW_BSC ==CID 0==> MGW_MSC
* MS <= MGW_BSC <=CID 1=== MGW_MSC

This allows for setups with 256 call legs per BSC on scenarios where NAT
is not a problem, where MSC can have a pool of 256 CID per MGW_BSC (or
remote peer).

Related: OS#2551
Change-Id: I28f83e2e32b9533c99e65ccc1562900ac2aec74e
2019-05-13 17:54:44 +02:00
Max 38176d297d NS: log address:port on error
Change-Id: If2dc533a6dc150254f5d44b672f04bb728e7e927
2019-05-10 13:36:18 +02:00
Harald Welte ea9ea52bbb osmo_sock_get_name_*: Ensure string is returned in error case
osmo_sock_get_name_buf():
In case the getsockname() call is failing for some weird reason,
we shouldn't return an uninitialized, non-zero-terminated string
buffer to the caller, as most callers will be too lazy to test the
return value.

This holds even more true for users of the internal
osmo_sock_get_name2() and osmo_sock_get_name2_c() functions which indeed
very much ignore the return value of osmo_sock_get_name_buf().

Change-Id: I2d56327e96b7a6783cca38b828c5ee74aed776ae
2019-05-10 13:36:08 +02:00
Harald Welte ea8272c3b6 Revert "Print error message if application fails to call rate_ctr_init()"
This reverts commit 9685a48c7b which has
caused massive fall-out among (particularly) unit tests in osmo-{msc,bts,pcu}.

Change-Id: Iede72e86451d94cf678045992cb71f6b1bf16896
2019-05-10 11:52:58 +02:00
Harald Welte e87693c820 gsm0808_utils: Introduce gsm0808_msgb_put_cell_id_u()
This function is doing the bulk work of encoding a given Cell
ID List item.  gsm0808_enc_cell_id_list2() is modified to be a
wrapper / loop around the new function.

The purpose of this is to expose Cell ID List Entry encoding
so that the upcoming CBSP protocol encoder can re-use this code.

Related: OS#3537
Change-Id: I6cc567798e20365e6587e6b2988e834306d8c80c
2019-05-10 07:09:59 +00:00
Harald Welte 9685a48c7b Print error message if application fails to call rate_ctr_init()
Change-Id: Ie8093b66b7e27cf863d2558fe21b2c6e0f3fcdfd
Closes: OS#3580
2019-05-10 07:09:51 +00:00
Harald Welte 37db7d3ea6 Fix osmo_quote_str_c() for strings larger than 32 bytes
As Neels pointed out, we shouldn't pass a constant value of 32
to osmo_quote_str_buf2().

Change-Id: Id9bde14166d6674ce4dda36fa9f4ae9217ce5cc2
2019-05-10 07:09:29 +00:00
Omar Ramadan 76bbcbc19e Add MO-FALLBACK-VALUE SGsAP IE
In testing against a particular EPC, the SGsAP-SERVICE-REQUEST
can contain a MO fallback value TLV with T 0xF1

Change-Id: Ia2460af9673818d375e28c67f1631b5f7eacdaeb
2019-05-10 07:07:34 +00:00
Kevin Redon c9a28a67e6 fix typo in FSM description
Change-Id: I3559e9c0769b708cee0d1b221b60960c62f15bd4
2019-05-09 18:31:13 +02:00
Harald Welte 6d3135ce50 deal with rate_ctr_group_alloc() returning NULL
Change-Id: I47d6623b9eca704e3c2537cfb5799a4c0749a7bc
Related: #3701
2019-05-08 22:18:21 +00:00
Pau Espin 1fcdd0d1b8 Bump version: 1.0.1.143-cc72c → 1.1.0
Change-Id: I351411ca5913c8b40f23287ec7c9ebfe11bd2bb0
2019-05-07 18:36:51 +02:00
Alexander Couzens cc72cc45a4 add osmo_stat_item_inc/osmo_stat_item_dec to set it relative
Change-Id: Id2462c4866bd22bc2338c9c8f69b775f88ae7511
2019-05-07 13:20:57 +00:00
Neels Hofmeyr 73b943e88d add gsm0808_create_handover_request_ack2 to add AoIP RTP addr
osmo-bsc so far omits the AoIP Transport Layer Address from its Handover
Request Acknowledge message, which breaks inter-BSC Handover for AoIP.
Allow fixing that.

One quirk I really don't like about this: I would prefer to directly use struct
sockaddr_storage as a member of the struct gsm0808_handover_request_ack. Even
though struct sockaddr_storage appears in various function signatures, the
gsm0808.c actually also gets built on embedded systems that lack arpa/inet.h
(for me indicated by the ARM build job on jenkins). Compiling gsm0808.c works
only because the actual coding of struct sockaddr_storage is implemented in
gsm0808_util.c, which (apparently) does not get built on embedded and hence,
even though there are undefined references to e.g.
gsm0808_enc_aoip_trasp_addr() it works.

Related: I4a5acdb2d4a0b947cc0c62067a67be88a3d467ff (osmo-bsc)
Change-Id: Ia71542ea37d4fd2c9fb9b40357db7aeb111ec576
2019-05-05 16:25:28 +00:00
Neels Hofmeyr cc26a8b6c3 osmo_gsup_decode(): properly check IMSI, avoid deprecation
In osmo_gsup_decode(), call gsm48_decode_bcd_number2() to avoid deprecation
warning, and also actually check the return value to detect invalid IMSI IEs.

Change-Id: Iaded84d91baad5386c8f353c283b6b9e40a43b05
2019-05-05 16:23:41 +00:00
Neels Hofmeyr 83d4531fa4 gsm48_decode_bcd_number2(): allow avoiding deprecation
gsm48_decode_bcd_number() is marked as deprecated, so
gsm48_decode_bcd_number2() will cause deprecation warnings as long as it calls
gsm48_decode_bcd_number(). Hence move the code to gsm48_decode_bcd_number2().

Change-Id: I81925e9afb3451de9b8a268d482f79ee20ca14d6
2019-05-05 16:23:41 +00:00
Neels Hofmeyr b3868e1410 gsm48_decode_bcd_number2(): fix input len check
The input_len argument for gsm48_decode_bcd_number2() includes the BCD length
*and* the length byte itself, so add the missing +1.

Also clarify the API doc for the input_len argument.

Change-Id: I87599641325c04aae2be224ec350b1a145039528
2019-05-05 16:23:41 +00:00
Neels Hofmeyr 63053001d3 add vty_is_active()
For async callbacks it is useful to determine whether a given VTY pointer is still valid.

For example, in osmo-msc, a silent call can be triggered by VTY, which causes a
Paging. The paging_cb then writes to the VTY console that the silent call has
succeeded. Unless the telnet vty session has already ended, in which case
osmo-msc crashes; e.g. from an osmo_interact_vty.py command invocation. With
this function, osmo-msc can ask whether the vty pointer passed to the paging
callback is still active, and skip vty_out() if not.

Change-Id: I42cf2af47283dd42c101faae0fac293c3a68d599
2019-05-03 16:15:24 +02:00
Neels Hofmeyr 8212fc6a7d add gsm48_decode_bcd_number2() from osmo-msc
gsm48_decode_bcd_number() is unable to provide proper bounds validation of
input and output data, hence osmo-msc's vlr.c introduced a static
decode_bcd_number_safe() a long time ago. Move to libosmocore.

I need to use the same function to decode an MSISDN during inter-MSC Handover,
instead of making it public in osmo-msc, rather deprecate the unsafe function
and provide a safer version for all callers. Mark the old one deprecated.

Change-Id: Idb6ae6e2f3bea11ad420dae14d021ac36d99e921
2019-05-03 16:15:24 +02:00
Neels Hofmeyr f7e9c51bdc BSSMAP: add messages for inter-BSC and inter-MSC Handover
Change-Id: I9dac375331f6bea744769e973725d58e35f87226
2019-05-03 16:15:23 +02:00
Neels Hofmeyr 302aafc3e2 BSSMAP: tweaks
Change two instances of Speech Version values to enum gsm0808_permitted_speech.
It is often not trivial to find the right values for a uint8_t member, giving
the enum name makes it a lot easier/safer to use.

In gsm0808_create_handover_required(), use msgb_tv_put() so that the enum's
storage size doesn't matter. (Already used for handover_performed)

Fix typo in doc of gsm0808_create_handover_required().

Change-Id: I6387836bab76e1fa42daa0f42ab94fc14b70b112
2019-04-26 20:36:39 +02:00
Oliver Smith affbb20646 GSUP: add inter-MSC handover related msgs and IEs
Based on a draft created by Neels, which is the result of reading a MAP
trace of two MSCs negotiating inter-MSC handovers, and of reading the
TS 29.002, TS 29.010 and related specs:
https://lists.osmocom.org/pipermail/openbsc/2019-January/012653.html

I figured out that the "Handover Number" mentioned in the specifications
is the same as the MSISDN IE that we already have, so we can use that
instead of creating a new IE (example usage in tests/gsup/gsup_test.c).

Create a new OSMO_GSUP_MSGT_E_ROUTING_ERROR message type, which the GSUP
server uses to tell a client that its message could not be forwarded to
the destination (see [1]). MAP has no related message.

[1]: Change-Id: Ia4f345abc877baaf0a8f73b8988e6514d9589bf5 (osmo-hlr.git)

Related: OS#3774
Change-Id: Ic00b0601eacff6d72927cea51767801142ee75db
2019-04-26 20:36:39 +02:00
Vadim Yanitskiy 3d6ffd8c9c bitcomp.c: fix missing Doxygen group closing tag
Change-Id: I01f837ac4c8644c0851c77c3f42eb44353cef0d7
2019-04-25 02:23:52 +07:00
Vadim Yanitskiy ff04a85812 application.c: drop wrong \references of osmo_init_ignore_signals()
Change-Id: Ib08e15dd5d811662de46a1dfdb676b9a5b66b529
2019-04-25 02:23:52 +07:00
Neels Hofmeyr 9838c9070f GSUP: add Message Class IE
osmo-msc and osmo-hlr have distinct subsystems handling incoming GSUP messages.
So far we decide entirely by message type which code path should handle a GSUP
message. Thus no GSUP message type may be re-used across subsystems.

If we add a GSUP message to indicate a routing error, it would have to be a
distinct message type for subscriber management, another one for SMS, another
one for USSD...

To allow introducing common message types, introduce a GSUP Message Class IE.

In the presence of this IE, GSUP handlers can trivially direct a received
message to the right code path. If it is missing, handlers can fall back to the
previous switch(message_type) method.

Change-Id: Ic397a9f2c4a7224e47cab944c72e75ca5592efef
2019-04-13 21:38:58 +00:00
Vadim Yanitskiy 469147480a gsm/gsm_utils.c: indicate intentional fall-through
Change-Id: Ica7d2d1884b745fe30234d6c50d93828c4930680
Fixes: CID#57700
2019-04-12 22:42:46 +07:00
Vadim Yanitskiy b7344d08df gb/gprs_ns_sns.c: fix incorrect sizeof() calculation
Calling sizeof() on a pointer would result in getting size of the
pointer (usually 4 or 8 bytes) itself, but not the size of the
memory it points to.

Change-Id: I83f55a9638b75d9097d37992f7c84707791f10f6
Fixes: CID#194266
2019-04-12 22:16:18 +07:00
Vadim Yanitskiy 4f619c202c Fix incorrect buffer size calculation
Calling sizeof() on a pointer to dynamically allocated memory would
result in getting size of the pointer (usually 4 or 8 bytes) itself,
but not the size of allocated memory.

Change-Id: I8ffda4dea2b7f9b4b76dfeecad1fab6384c5a62c
Fixes: CID#197629, CID#197628, CID#197627
Fixes: CID#197626, CID#197625, CID#197624
2019-04-12 21:48:11 +07:00
Neels Hofmeyr b480b74192 add identifier sanitation for setting FSM instance ids
We often compose FSM instance IDs from context information, for example placing
an MSISDN string or IP:port information in the FSM instance id, using
osmo_fsm_inst_update_id_f(). This fails if any characters are contained that
don't pass osmo_identifier_valid(). Hence it is the task of the caller to make
sure only characters allowed in an FSM id are applied.

Provide API to trivially allow this by replacing illegal chars:
- osmo_identifier_sanitize_buf(), with access to the same set of illegal
  characters defined in utils.c,
- osmo_fsm_inst_update_id_f_sanitize() implicitly replaces non-identifier
  chars.

This makes it easy to add strings like '192.168.0.1:2342' or '+4987654321' to
an FSM instance id, without adding string mangling to each place that sets an
id; e.g. replacing with '-' to yield '192-168-0-1:2342' or '-4987654321'.

Change-Id: Ia40a6f3b2243c95fe428a080b938e11d8ab771a7
2019-04-12 01:00:16 +02:00
Neels Hofmeyr ecef7ec3c3 add osmo_{escape,quote}_str_buf2() for standard args ordering
To be able to append an escaped or quoted string using
OSMO_STRBUF_APPEND_NOLEN(), the function signature must have the buf and len as
first args, like most other *_buf() functions.

Add osmo_escape_str_buf2() and osmo_quote_str_buf2() to match this signature.

A recent patch [1] has changed the return value of osmo_escape_str_buf() to
char*, removing the const. However, the functions may return const strings,
hence re-add the const. The new signatures always return the non-const buffer.

To avoid code duplication, implement osmo_quote_str_buf() and
osmo_escape_str_buf() by calling the new functions.

I decided to allow slight changes to the behavior for current osmo_escape_str()
and osmo_escape_str_buf(), because impact on callers is minimal:

(1) The new implementation uses OSMO_STRBUF_*, and in consequence
osmo_quote_str() no longer prints an ending double quote after truncated
strings; Before, a truncated output was, sic:
  "this string is trunca"
and now this becomes, sic:
  "this string is truncat
I decided to not keep the old behavior because it is questionable to begin
with. It looks like the string actually ended at the truncation boundary
instead of the reason being not enough space in the output buffer.

(2) The new osmo_escape_str_buf2() function obviously cannot pass-thru an
unchanged char* if no escaping was needed. Sacrifice this tiny optimization
feature to avoid code duplication:
- it is an unnoticeable optimization,
- the caller anyway always passes a string buffer,
- the feature caused handling strings and buffers differently depending on
  their content (i.e. code that usually writes out strings in full length
  "suddenly" truncates because a non-printable character is contained, etc.)
I considered adding a skip_if_unescaped flag to the osmo_quote_str_buf2()
function signature, but in the end decided that the API clutter is not worth
having for all the above reasons.

Adjust tests to accomodate above changes.

[1] 4a62eda225
    Ibf85f79e93244f53b2684ff6f1095c5b41203e05

Change-Id: Id748b906b0083b1f1887f2be7a53cae705a8a9ae
2019-04-12 01:00:16 +02:00
Neels Hofmeyr d79ccc65f7 add osmo_str_startswith()
Move from a static implementation in tdef_vty.c to utils.c, I also want to use
this in osmo-msc.

The point is that the telnet VTY allows unambiguous partly matches of keyword
args. For example, if I have a command definition of:

    compare (apples|oranges)

then it is perfectly legal as for the vty parser to write only

    compare app

One could expect the VTY to then pass the unambiguous match of "apples" to the
parsing function, but that is not the case.

Hence a VTY function implementation is faced with parsing a keyword of "app"
instead of the expected "apples".

This is actually a very widespread bug in our VTY implementations, which assume
that exactly one full keyword will always be found. I am now writing new
commands in a way that are able to manage only the starts of keywords.

Arguably, strstr(a, b) == a does the same thing, but it searches the entire
string unnecessarily.

Change-Id: Ib2ffb0e9a870dd52e081c7e66d8818057d159513
2019-04-11 05:36:36 +00:00
Neels Hofmeyr 04cb09cbf1 make osmo_sockaddr_str_is_set() NULL-safe
Obviously a NULL pointer should return false instead of segfaulting.

Change-Id: Iac025cf4d556cbed99f3924cd9ca05a05881cd9a
2019-04-11 05:36:36 +00:00
Neels Hofmeyr 1f9cc01861 fsm: support graceful osmo_fsm_inst_term() cascades
Add global flag osmo_fsm_term_safely() -- if set to true, enable the following
behavior:

Detect osmo_fsm_inst_term() occuring within osmo_fsm_inst_term():
- collect deallocations until the outermost osmo_fsm_inst_term() is done.
- call osmo_fsm_inst_free() *after* dispatching the parent event.

If a struct osmo_fsm_inst enters osmo_fsm_inst_term() while another is already
within osmo_fsm_inst_term(), do not directly deallocate it, but talloc-reparent
it to a separate talloc context, to be deallocated with the outermost FSM inst.

The effect is that all osmo_fsm_inst freed within an osmo_fsm_inst_term()
cascade will stay allocated until all osmo_fsm_inst_term() are complete and all
of them will be deallocated at the same time.

Mark the deferred deallocation state as __thread in an attempt to make cascaded
deallocation handling threadsafe.  Keep the enable/disable flag separate, so
that it is global and not per-thread.

The feature is showcased by fsm_dealloc_test.c: with this feature, all of those
wild deallocation scenarios succeed.

Make fsm_dealloc_test a normal regression test in testsuite.at.

Rationale:

It is difficult to gracefully handle deallocations of groups of FSM instances
that reference each other. As soon as one child dispatching a cleanup event
causes its parent to deallocate before fsm.c was ready for it, deallocation
will hit a use-after-free. Before this patch, by using parent_term events and
distinct "terminating" FSM states, parent/child FSMs can be taught to wait for
all children to deallocate before deallocating the parent. But as soon as a
non-child / non-parent FSM instance is involved, or actually any other
cleanup() action that triggers parent FSMs or parent talloc contexts to become
unused, it is near impossible to think of all possible deallocation events
ricocheting, and to avoid running into freeing FSM instances that were still in
the middle of osmo_fsm_inst_term(), or FSM instances to enter
osmo_fsm_inst_term() more than once. This patch makes deallocation of "all
possible" setups of complex cross referencing FSM instances easy to handle
correctly, without running into use-after-free or double free situations, and,
notably, without changing calling code.

Change-Id: I8eda67540a1cd444491beb7856b9fcd0a3143b18
2019-04-11 05:36:36 +00:00
Neels Hofmeyr 3b414a4adc fsm: add flag to ensure osmo_fsm_inst_term() happens only once
To prevent re-entering osmo_fsm_inst_term() twice for the same osmo_fsm_inst,
add flag osmo_fsm_inst.proc.terminating. osmo_fsm_inst_term() sets this to
true, or exits if it already is true.

Update fsm_dealloc_test.err for illustration. It is not relevant for unit
testing yet, just showing the difference.

Change-Id: I0c02d76a86f90c49e0eae2f85db64704c96a7674
2019-04-11 05:36:36 +00:00
Vadim Yanitskiy ed8e263096 gsm_utils.c: fix Doxygen description for gsm_get_octet_len()
Change-Id: Id6fd2cd33be1cb7cd7ff6a43bfcfb1f368304522
2019-04-11 00:24:55 +00:00
Vadim Yanitskiy 3d81147dea vty/talloc_ctx_vty.c: use REG_NOSUB flag of regcomp()
We don't need to know position of matches: just yes or no.
This change would save some computation power.

Change-Id: Id55ffe64cc1a35dd83f61dbb0f9828aa676696f9
2019-04-11 00:24:55 +00:00
Vadim Yanitskiy bd6968a1ca vty/talloc_ctx_vty.c: allocate walk_cb_params on stack, not heap
There is no need to allocate struct 'walk_cb_params' dynamically.

Change-Id: I96f25f1ddb36b19b12055deaeeb6f58e59180e72
2019-04-11 00:24:55 +00:00
Harald Welte 179f35702e Add _c versions of functions that otherwise return static buffers
We have a habit of returning static buffers from some functions,
particularly when generating some kind of string values.  This is
convenient in terms of memory management, but it comes at the expense
of not being thread-safe, and not allowing for two calls of the
related function within one printf() statement.

Let's introduce _c suffix versions of those functions where the
caller passes in a talloc context from which the output buffer shall
be allocated.

Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b
2019-04-10 22:42:32 +00:00
Neels Hofmeyr 0e8df1c7e4 add osmo_use_count API
Provide a common implementation of use counting that supports naming each user
as well as counting more than just one use per user, depending on the rules the
caller implies.

In osmo-msc, we were originally using a simple int counter to see whether a
connection is still in use or should be discarded. For clarity, we later added
names to each user in the form of a bitmask of flags, to figure out exactly
which users are still active: for logging and to debug double get / double put
bugs. This however is still not adequate, since there may be more than one CM
Service Request pending. Also, it is a specialized implementation that is not
re-usable.

With this generalized implementation, we can:

- fix the problem of inadequate counting of multiple concurrent CM Service
  Requests (more than one use count per user category),
- directly use arbitrary names for uses like __func__ or "foo" (no need to
  define enums and value_string[]s),
- re-use the same code for e.g. vlr_subscr and get fairly detailed VLR
  susbscriber usage logging for free.

Change-Id: Ife31e6798b4e728a23913179e346552a7dd338c0
2019-04-08 13:47:17 +00:00
Neels Hofmeyr 0c7826e9bd add osmo_sockaddr_str API
For handling RTP IP addresses and ports, osmo-mgw, osmo-bsc and osmo-msc
so far have their own separate shims and code duplication around
inet_ntoa(), htons(), sockaddr conversions etc. Unify and standardize
with this common API.

In the MGW endpoint FSM that was introduced in osmo-bsc and which I
would like to re-use for osmo-msc (upcoming patch moving that to
osmo-mgw), it has turned out that using char* IP address and uint16_t
port number types are a convenient common denominator for logging,
MGCP message composition and GSM48. Ongoing osmo-msc work also uses this
for MNCC.

This is of course potentially useful for any other IP+port combinations
besides RTP stream handling.

Needless to say that most current implementations will probably stay
with their current own conversion code for a long time; for current
osmo-{bsc,msc,mgw} work (MGW endpoint FSM) though, I would like to move
to this API here.

Change-Id: Id617265337f09dfb6ddfe111ef5e578cd3dc9f63
2019-04-08 13:47:17 +00:00
Philipp Maier e8461e486e gsm_utils: fix use buf_len instead of sizeof in osmo_dump_gsmtime_buf
The function osmo_dump_gsmtime_buf gets a pointer *buf and a parameter
buf_len. The pointer *buf is a string buffer and the function places an
\0 at the end of the buffer before it exists. However it uses
sizeof(buf) as part of the index calculation, which is incorrect. Lets
correct this by using buf_len instead.

Change-Id: Id24263aa7c9a53544f1639b6ceb09ce5615d5114
2019-04-08 12:16:03 +02:00
Harald Welte 4a62eda225 Add _buf() functions to bypass static string buffers
We have a number of static buffers in use in libosmo*.  This means
the related functions are not usable in a thread-safe way.  While
we so far don't have many multi-threaded programs in the osmocom
universe, the static buffers also prevent us from calling the same
e.g. string-ify function twice within a single printf() call.

Let's make sure there's an alternative function in all those cases,
where the user can pass in a caller-allocated buffer + size, and make
the 'classic' function with the static buffer a wrapper around that
_buf() variant.

Change-Id: Ibf85f79e93244f53b2684ff6f1095c5b41203e05
2019-04-03 18:03:14 +02:00
Harald Welte 98ed3393cd osmo_escape_str_buf: Always copy, don't return input string pointer
osmo_escape_str_buf() used to have the somewhat odd semantics that
if no escaping was needed, it would return the original pointer without
making any copy to the output buffer.  While this seems like an elegant
optimization, it is a very strange behavior and it works differently
than all of our other *_buf() functions.  Let's unify the API and
turn osmo_escape_str_buf() into a strlcpy() if no escaping is needed.

Change-Id: I3a02bdb27008a73101c2db41ac04248960ed4064
2019-03-29 16:42:25 +00:00
Pau Espin 3cb68518fc ipa: Fix ipa_ccm_id_resp_parse on big endian systems
Change-Id: Iedc46ab53a4f76bbd98741c065fad3d9042a34a4
2019-03-28 12:22:36 +00:00
Pau Espin deeab473a0 ipa: Document ipa_ccm_idtag_parse_off and fix ipa_ccm_idtag_parse
ipa_ccm_idtag_parse_off is broken, and can only be used with
len_offset=1 on ID Request messages, otherwise won't work correctly.
Modify ipa_ccm_idtag_parse to at least parse those correctly, and
document the limitations.

Those two functions are already deprecated and only used in openbsc by 3
callers:
* ipa_ccm_idtag_parse in ussd_read_cb(): Broken, that function can only
work for Requests and it's used to parse a Response.
* ipa_ccm_idtag_parse_off in forward_sccp_to_msc (NAT): Broken, it can
only be used to parse Requests and it's used to parse a Response.
Furthermore, len_offset=2 is passed which makes no sense and most
probably it fails always, or can even make the program crash.
* ipa_ccm_idtag_parse_off in (answer_challenge): This one is fine and
could actually be replaced with ipa_ccm_id_get_parse after this commit
is merged.

Change-Id: I6efc852dfc041192f554e41a58290a0f63298021
2019-03-28 12:22:36 +00:00
Vadim Yanitskiy b9baf02c12 src/gsmtap_util.c: fix possible memleak in gsmtap_source_init()
In gsmtap_source_init() we dynamically allocate a gsmtap_inst struct,
but don't free it if the subsequent call to osmo_fd_register() fails.

Change-Id: I970b493f3a64fbe9c3f68fcfba5097ee3ff72960
2019-03-28 10:07:59 +00:00
Max 548caef269 BSSGP: use variable for NSEI
Handle NSEI the same way as BVCI is handled: assign it to variable
instead of repetitive calls to msgb_nsei() - this simplifies log update
in follow-up patches and makes code slightly easier to read.

Change-Id: I919a717ca22646849d6ec7f62c677c536db0ed31
2019-03-28 09:00:20 +00:00
Vadim Yanitskiy ccf7c7c887 logging_gsmtap.c: document all params of log_target_create_gsmtap()
Change-Id: Id7bd6b4fb4be571af351f77aa4a59b9e1076434f
2019-03-27 08:56:21 +01:00
Vadim Yanitskiy bc29b2660f Doxygen: fix documentation of osmo_timer_setup()
This change fixes the following Doxygen warnings:

  timer.c:69: warning: argument 'callback' of command @param is not
              found in the argument list of
              osmo_timer_setup(struct osmo_timer_list *timer,
                               void(*cb)(void *data), void *data)
  timer.c:69: warning: argument 'pointer' of command @param is not
              found in the argument list of
              osmo_timer_setup(struct osmo_timer_list *timer,
                               void(*cb)(void *data), void *data)
  core/timer.h:70: warning: The following parameters of
                   osmo_timer_setup(struct osmo_timer_list *timer,
                   void(*cb)(void *data), void *data)
                   are not documented:
                     parameter 'cb'
                     parameter 'data'

Change-Id: If5668f40a7bfde2f4f22329a071c8c6eff23b99e
2019-03-27 08:56:21 +01:00
Vadim Yanitskiy ed3a3c6f1d src/rate_ctr.c: drop some incorrect \ref references
rate_ctr.c:411: warning: unable to resolve reference
                  to `handle_group' for \ref command
  rate_ctr.c:208: warning: unable to resolve reference
                  to `talloc' for \ref command

Change-Id: I24a80ff6cf11ce0455529515d1ecb9900f0271a8
2019-03-27 08:56:21 +01:00
Vadim Yanitskiy c761044ecb Doxygen: fix documentation of rate_ctr_for_each_counter()
Doxygen was confused by duplicated documentation for both
definition and declaration of rate_ctr_for_each_counter().
Moreover, both variants contained some mistakes.

Let's avoid this duplication and keep the only (corrected) one.

Change-Id: Icca2d4a95bd5f96ae85a86909ec90fb8677cacf3
2019-03-27 08:56:21 +01:00
Vadim Yanitskiy b8d06fb6b3 src/msgb.c: fix Doxygen documentation for msgb_printf()
This change fixes the following Doxygen warnings:

  src/msgb.c:479: warning: argument 'msg' of command @param is not
                  found in the argument list of
                  msgb_printf(struct msgb *msgb, const char *format,...)
  core/msgb.h:708: warning: The following parameters of
                   msgb_printf(struct msgb *msgb, const char *format,...)
                   are not documented:
                     parameter 'msgb'
                     parameter 'format'

As a bonus, it dot-terminates all sentences.

Change-Id: Ib708664336eef06f748d408ae02a13c754b6647a
2019-03-27 08:56:21 +01:00
Vadim Yanitskiy 73e66b3eef src/logging.c: fix syntax errors in Doxygen documentation
This change should fix the following warnings:

  logging.c:956: warning: unable to resolve reference to `talloc'
                 for \ref command
  logging.c:203: warning: argument 'in' of command @param is not
                 found in the argument list of
                 log_level_str(unsigned int lvl)
  logging.c:194: warning: argument 'in' of command @param is not
                 found in the argument list of
                 log_parse_level(const char *lvl)
  logging.c:708: warning: argument 'print_catname' of command
                 @param is not found in the argument list of
                 log_set_print_category(struct log_target *target,
                                        int print_category)
  logging.c:687: warning: argument 'print_filename' of command
                 @param is not found in the argument list of
                 log_set_print_filename2(struct log_target *target,
                                         enum log_filename_type lft)
  logging.c:729: warning: argument 'print_catname' of command
                 @param is not found in the argument list of
                 log_set_print_level(struct log_target *target,
                                     int print_level)
  logging.c:893: warning: argument 'in' of command @param is not
                 found in the argument list of
                 log_target_destroy(struct log_target *target)

Change-Id: I85f6c70216b7574b49b90bb1469869a47f721713
2019-03-27 08:56:21 +01:00
Oliver Smith 27f7b0da6f Revert "ipa_ccm_idtag_parse*: Fix reported length value"
This reverts commit 1261db1505.

The patch broke openbsc's external tests, and currently it is unclear
whether it is just an error in the test or if openbsc makes wrong
assumptions about the length value. Let's revert the patch to unblock
the master-openbsc jenkins job.

Related: OS#3851
Change-Id: I9adea35ff6de36c1611c7f85dde1b15bc1c0e786
2019-03-25 14:43:52 +00:00
Vadim Yanitskiy 2f65bb1b01 Doxygen: fix incorrect / missing parameter description
Change-Id: Ibc63a5d4442a192efab8b5b30e0beb3545642ecc
2019-03-25 15:57:09 +07:00
Oliver Smith 9f2814283e Revert "signal.c: Make non-exported tall_sigh_ctx static"
This reverts commit cff2242e68.

The patch broke openbsc:
../../src/libcommon/libcommon.a(talloc_ctx.o): In function `talloc_ctx_init':
/build/openbsc/src/libcommon/talloc_ctx.c:50: undefined reference to `tall_sigh_ctx'

See also:
https://lists.osmocom.org/pipermail/openbsc/2019-March/012843.html

Change-Id: Ib4cb31427a1cad063bc9f1a10b9c3182b314a9f2
2019-03-22 13:25:01 +01:00
Harald Welte cff2242e68 signal.c: Make non-exported tall_sigh_ctx static
As indicated in the commitlog of
Id58ca18eb826b8f4183a7cf0dbb2b38cba702a09,
the symbol was never exported in a header file, so it should be safe
to mark it as static.

Change-Id: I7132ffe9a7efcab226cc639d1b2357f7115bcadf
2019-03-21 16:02:39 +00:00
Harald Welte 8c58af139d signal.c: Fix osmo_signal_talloc_ctx_init()
This function is broken ever since it was added back in 2018 in commit
Id58ca18eb826b8f4183a7cf0dbb2b38cba702a09

Rather than allocating from the user-supplied 'root_ctx', it is
allocating from the context that it's trying to create (which is
NULL at that time, rendering the entire operation more or less
a no-op.  For sure you will not see osmo_signal structures never in
any talloc report.

Change-Id: I922d26815a3baa5be74bd3ee89d498555882d62f
2019-03-21 16:02:31 +00:00
Harald Welte 1688699c3f select: Rename BSC_FD_* constants to OSMO_FD_*
The naming of these constants dates back to when the code was private
within OpenBSC.  Everything else was renamed (bsc_fd -> osmo_fd) at
the time, but somehow the BSC_FD_* defines have been missed at the
time.

Keep compatibility #defines around, but allow us to migrate the
applications to a less confusing naming meanwhile.

Change-Id: Ifae33ed61a7cf0ae54ad487399e7dd2489986436
2019-03-21 16:02:01 +00:00
Vadim Yanitskiy a3226f7b9d src/signal.c: cosmetic: use talloc_zero()
Change-Id: I55c6249b0c4c82d5a181001e945ff2eca6e9ca36
2019-03-20 20:42:06 +07:00
Harald Welte fa90cfd8d2 gprs_ns_sns: Properly initialize sockaddr_in in gprs_nsvc_create_ip4()
When putting together a sockaddr_in, we must not only set the IP
address and port, but also set the address family to AF_INET.  And
while at it, let's zero-initialize the entire 'struct sockdadr_in'.

Change-Id: I1c8d8fe7f79a2ec737baa7800247269c3271983e
2019-03-20 08:32:30 +01:00
Harald Welte c0dfc9d885 socket: osmo_sock_get_name() Use "const void *" as talloc context
Change-Id: Ie6877277cddb0a9e049449c260afe3314ba65050
2019-03-19 14:04:00 +00:00
Vadim Yanitskiy 54f5f4da59 vty/tdef_vty.c: drop redundant comparison
The amount of arguments is already being checked a few lines before:

  /* If any arguments are missing, redirect to 'show' */
  if (argc < 3)
    return show_timer(self, vty, argc, argv);

so we cannot reach the expression NULL inside this statement:

  group_arg = argc > 0 ? argv[0] : NULL;

Change-Id: Ice59d1a46c2080cd02060e3410706c502db4ce0b
Fixes: CID#190873 Logically dead code (DEADCODE)
2019-03-19 13:44:58 +00:00
Harald Welte 1261db1505 ipa_ccm_idtag_parse*: Fix reported length value
IPA CCM is using a somewhat weird TLV encoding scheme:
* 16bit length (of tag and value)
* 8bit tag
* value

Our existing code mapping the CCM to 'struct tlv_parse' used the plain
length value without accounting for the one-byte tag.

This patch ensures we only report the length of the "value" part,
excluding the tag.

Change-Id: I435aaa33605bd48635715a2c81aa2d231c1abf51
2019-03-19 13:41:49 +00:00
Max fb6f43ee0c rate_ctr_group_free(): guard against empty or NULL input
Change-Id: I859a91ee4400b3685c05971f8c66bceca6758724
2019-03-19 12:57:10 +00:00
Harald Welte 24e67f86dd gprs_ns_sns: Use "correct" remote IP address for local IP endpoint
we cannot use "nsi->nsip.remote_ip", as this address is not set
when SNS is in use.  We can only have a valid nsi->nsip.remote_ip
if there's only a single NS-VC inside the NS Instance, as this would
connect() the UDP socket to the remote IP/port, breaking any possibility
to have multiple NS-VCs to different SGNS-side IP addresses.

Closes: OS#3845
Change-Id: Ic094621eb01d7458063f531289d5eeadf52bf330
2019-03-16 18:34:58 +01:00
Harald Welte 94c9b449cf gprs_ns: Don't use initial IP/port for anything but SNS
Section 6.2.1 of 3GPP TS 48.016 states:
> A pre-configured endpoint shall not be used for NSE data or signalling
> traffic (with the exception of Size and Configuration procedures) unless
> it is configured by the SGSN using the auto-configuration procedures.

However, in the current SNS implementation, the initial IP/Port over
which we perform the SNS-SIZE + SNS-CONFIG are treated as one of the
normal NS-VCs. Specifically, we also perform the NS-ALIVE procedure on
it, which is clearly wrong.

Let's explicitly create the "initial" NS-VC with data and signalling
weight of 0, and ensure we never start the alive timer or send any
non-SNS PDUs on this connection as long as SNS was not used to change
either of the two weights to non-zero.

While at it, also safeguard against processing any incoming non-SNS
messages on such a all-zero-weight connection.

Change-Id: I16a91a07e5914d123b2ea2f8413b94e7cd518628
Closes: OS#3844
2019-03-16 18:34:52 +01:00
Harald Welte 1e072cca4e gprs_ns.c: Update comment: IP SNS has recently been implemented
Change-Id: I8b98621a582a23d0483a5340b4aca7e0bc096e6d
2019-03-16 13:00:44 +01:00
Neels Hofmeyr 9e6f5f10bd osmo_gsm48_classmark_a5_name(): fix 'no-cm3' label
Change-Id: Id84021858dfb2f7d6a7cf81ae73bd94cd47f6776
2019-03-14 03:43:10 +00:00
Karl Koscher 76f025eae8 Fix build on non-glibc systems
Change-Id: Id5d577522a4889e152158f7e93ee1c99d3a21003
2019-03-11 13:19:46 -07:00
Philipp Maier 94d79fdeef gsm0808_utils: fix gsm48 multirate to S-bit converter
The function gsm0808_sc_cfg_from_gsm48_mr_cfg() is used to convert a
gsm48 multirate struct into a set of S-bits (S0 to S15). However, the
conversion function currently does not take into account that bit S1
actually stands for four rates at once (Config-NB-Code = 1). Lets make
sure that S1 is only set when the multirate configuration permits all
four required rates.

Change-Id: I6ad531d4e70c2252e32e2bbaca8e14a7ec6d9840
Related: SYS#4470
2019-03-11 09:08:31 +01:00
Philipp Maier 3713af8655 gsm0808_utils: fix gsm48 multirate configuration generator
The function gsm0808_sc_cfg_from_gsm48_mr_cfg() takes an S15 to S0
bitmask and converts that bitmask into an AMR multirate configuration
struct.

Unfortunately the current implementation implements 3GPP TS 28.062,
Table 7.11.3.1.3-2 wrongly in some aspects. Lets fix this.

- Fix wrong interpretation of the bitpatterns
- 5,15K is invalid and must never be selected
- Make sure that no more than 4 rates are selected in the active set
- Extend unit-test

Change-Id: I6fd7f4073b84093742c322752f2fd878d1071e15
Related: SYS#4470
2019-03-11 09:08:31 +01:00
Neels Hofmeyr 3a5045302f add gsm0808_cell_id_from_cgi(), gsm0808_cell_id_to_cgi()
CGI to Cell ID: for example, for Paging, osmo-msc has a CGI for a subscriber
and needs to send out a Cell Identifier IE. Makes sense to add this conversion
here.

Cell ID to CGI: for a Layer 3 Complete, a subscriber sends the current cell in
the form of a Cell Identifier, which we store as a CGI, if necessary enriched
with the local PLMN.

Add enum with bitmask values to identify parts of a CGI, for the return value
of gsm0808_cell_id_to_cgi(). Can't use enum CELL_IDENT for that, because it
doesn't have a value for just a PLMN (and is not a bitmask).

Change-Id: Ib9af67b100c4583342a2103669732dab2e577b04
2019-03-08 05:25:07 +01:00
Neels Hofmeyr d4b79c8772 fsm: add osmo_fsm_inst_state_chg_keep_or_start_timer()
During FSM design for osmo-msc, I noticed that the current behavior that
keep_timer=true doesn't guarantee a running timer can make FSM design a bit
complex, especially when using osmo_tdef for timeout definitions.

A desirable keep_timer=true behavior is one that keeps the previous timer
running, but starts a timer if no timer is running yet.

The simplest example is: a given state repeatedly transitions back to itself,
but wants to set a timeout only on first entering, avoiding to restart the
timeout on re-entering.

Another example is a repeated transition between two or more states, where the
first time we enter this group a timeout should start, but it should not
restart from scratch on every transition.

When using osmo_tdef timeout definitions for this, so far separate meaningless
states have to be introduced that merely set a fixed timeout.

To simplify, add osmo_fsm_inst_state_chg_keep_or_start_timer(), and use this in
osmo_tdef_fsm_inst_state_chg() when both keep_timer == true *and* T != 0.

In tdef_test.ok, the changes show that on first entering state L, the previous
T=1 is now kept with a large remaining timeout. When entering state L from O,
where no timer was running, this time L's T123 is started.

Change-Id: Id647511a4b18e0c4de0e66fb1f35dc9adb9177db
2019-03-07 23:10:21 +01:00
Neels Hofmeyr 5734bff3b0 represent negative T-timers as Osmocom-specific X-timers
fi->T values are int, i.e. can be negative. Do not log them as unsigned, but
define a distinct timer class "Xnnnn" for negative T values: i.e. for T == -1,
print "Timeout of X1" instead of "Timeout of T4294967295".

The negative T timer number space is useful to distinguish freely invented
timers from proper 3GPP defined T numbers. So far I was using numbers like
T993210 or T9999 for invented T, but X1, X2 etc. is a better solution. This way
we can make sure to not accidentally define an invented timer number that
actually collides with a proper 3GPP specified timer number that the author was
not aware of at the time of writing.

Add OSMO_T_FMT and OSMO_T_FMT_ARGS() macros as standardized timer number print
format. Use that in fsm.c, tdef_vty.c, and adjust vty tests accordingly.

Mention the two timer classes in various API docs and VTY online-docs.

Change-Id: I3a59457623da9309fbbda235fe18fadd1636bff6
2019-03-06 00:51:15 +01:00
Neels Hofmeyr 8aa691f30b api doc: tweak gsm0808_cell_id_matches_list() doc
Change-Id: Ide94558d1c31356483252b83e04b061b4ee4d3bf
2019-03-05 23:49:02 +00:00
Neels Hofmeyr 6d57c57276 fix api doc typo for osmo_plmn_name2()
Change-Id: Ic2652c7e4ffe1e707022168ac6c0da7c88ae7f45
2019-02-26 22:43:19 +00:00
Neels Hofmeyr 050f2d3259 log: fsm: allow logging the timeout on state change
Add a flag that adds timeout info to osmo_fsm_inst state change logging.

To not affect unit testing, make this an opt-in feature that is disabled by
default -- mostly because osmo_fsm_inst_state_chg_keep_timer() will produce
non-deterministic logging depending on timing (logs remaining time).

Unit tests that don't verify log output and those that use fake time may also
enable this feature. Do so in fsm_test.c.

The idea is that in due course we will add osmo_fsm_log_timeouts(true) calls to
all of our production applications' main() initialization.

Change-Id: I089b81021a1a4ada1205261470da032b82d57872
2019-02-26 20:57:58 +00:00
Harald Welte 047f3872f5 NS: Add support for GPRS NS IP Sub-Network-Service (SNS)
The NS implementation part of the Gb implementation libosmogb
so far implemented a rather classic dialect of Gb, with lots of
heritage to FR (Frame Relay) transports.  At least since Release 6
of the NS specification, there's an IP Sub-Network Service (SNS),
which
* permits for dynamic configuration of IP endpoints and their NS-VCs
* abandons the concept of a NSVCI on IP transport
* forbids the use of RESET/BLOCK/UNBLOCK procedures on IP transport

This commit introduces BSS-side IP-SNS support to libosmogb in a
minimally invasive way.  It adds a corresponding SNS FSM to each NS
instance, and implements the new SIZE/CONFIG/ADD/DELETE/CHANGE_WEIGHT
procedures very closely aligned with the spec.

In order to use the SNS flavor (rather than the classic one),
a BSS implementation should use gprs_ns_nsip_connect_sns() instead
of the existing gprs_ns_nsip_connect().

This implementation comes with a set of TTCN-3 tests in
PCU_Tests_RAW_SNS.ttcn, see Change-ID
I0fe3d4579960bab0494c294ec7ab8032feed4fb2 of osmo-ttcn3-hacks.git

Closes: OS#3372
Closes: OS#3617
Change-Id: I84786c3b43a8ae34ef3b3ba84b33c90042d234ea
2019-02-26 12:18:30 +01:00
Harald Welte 35042a2919 NS: Factor out gprs_nsvc_start_test() and use it
This function performs  sending a NS-ALIVE PDU and starting Tns-Test,
let's use it in all places where we used to do that.

As part of this, also fix a bug where the sendto() return value (number
of bytes sent) would actually propagate up all the way to
gprs_ns_rx_reset() return value, which in turn affects the test results
on stdout.

Change-Id: I4d303117f77fabb74bbb91887b9914a81c2a084a
2019-02-26 12:18:30 +01:00
Harald Welte 17a642d8ff gprs_ns: Add code for SNS-SIZE and SNS-CONFIG encoding
Modern NS specifications contain a SNS (Sub Network Service) for
negotiating IP/port/weight parameters of NS-over-IP links dynamically.

This patch adds message encoding routines for SNS-CONFIG, SNS-SIZE
and their respective acknowledgements.

Related: OS#3372
Change-Id: I5c47e1c3c10deb89a7470ee2c03adfc174accc93
2019-02-26 11:17:44 +00:00
Max 5ec0cf5475 LCLS: add string dump helpers
Add functions to dump LCLS (without GCR) and GCR. Dumping entire struct
results in inconveniently long string hence the separate functions. Both
use talloc functions so they expect caller to take care of providing
proper allocation context and freeing memory.

Change-Id: Ic3609224c8f3282d667e75f68bc20327e36eb9e6
2019-02-26 09:16:38 +00:00
Harald Welte 47cf21f74f NS: Add missing NS Cause strings
When I added the definitions for the IP-SNS in commit
f030b210e8 back in 2010, I forgot to update
the string definitions in ns_cause_str[].  Let's fix that

Change-Id: I419ccc482d99b01263a60aede83dacd2d9de56ab
2019-02-23 14:12:34 +01:00
Harald Welte dc802810df NS: Don't print information about FR/GRE if not enabled!
Change-Id: I9209ee4ba5ebfc4f96b4c1d42840e1906455bae7
2019-02-23 11:34:31 +01:00
Harald Welte 52a8375025 select: Call log_reset_context() before calling file descriptor callbacks
Make sure to clear any log context before processing the next incoming message
as part of some file descriptor callback.  This effectively prevents "context
leaking" from processing of one message into processing of the next message as part
of one iteration through the list of file descriptors here.

Change-Id: I3644c7bc1a9cec5858eb0faf94efc8c3ba7f5d8d
Closes: OS#3813
2019-02-21 16:38:49 +01:00
Harald Welte 9ef2e15dc1 gprs_ns: Add missing NSVCI IE to NS-BLOCK-ACK message
According to Section 9.2.4 of 3GPP TS 48.016, the NS-BLOCK-ACK PDU has a
mandatory NSVCI IE which we so far were missing.

Change-Id: Ie7205e99d57f1e42d941f1be2460d8c9f46aadfe
Closes: OS#3808
2019-02-19 23:45:10 +01:00
Harald Welte 9612fcb955 gprs_ns.c: cosmetic whitespace fixes
Change-Id: Ic19f65bdc5527ad5a69d0a92320ce5f672bf4d2b
2019-02-19 23:45:10 +01:00
Harald Welte 4091f929a1 gprs_ns: Use gprs_ns_tx_alive() instead of gprs_ns_tx_simple()
If we use gprs_ns_tx_alive() we will get logging for free.

Change-Id: I53d410d13540d389096c40425e1fa2eb7460b16b
2019-02-19 23:45:10 +01:00
Harald Welte 6a469e13e3 bssgp_tx_bvc_unblock(): Fix log message
We're transmitting a BVC-UNBLOCK but the log states the opposite:
BVC-BLOCK.  Let's fix that.

Change-Id: I70fa7336402d193513f89fcf3068b0b21925702d
2019-02-19 12:29:14 +00:00
Pau Espin 10f07da804 rsl: Support PDCH in rsl_chan_nr_str
During log review lack of support  for PDCH was spotted:

scheduler.c:593 Configuring multiframe with PDCH trx=0 ts=4
rsl.c:1159 (bts=0,trx=0,ts=4,ss=0): chan_nr=UNKNOWN on TS4 type=0x00 mode=SIGNALLING
rsl.c:741 (bts=0,trx=0,ts=4,pchan=TCH/F_TCH/H_PDCH as PDCH) (ss=0) PDTCH Tx CHAN ACT ACK

Wireshark shows:
1100 0... = C-bits: PDCH (24)
.... .100 = Time slot number (TN): 4

Change-Id: If6ed96c9eb0431eb24e2135634def61e0ea506ea
2019-02-18 18:02:59 +01:00
Harald Welte d1365e1a81 gsm0808: comment about difference of gsm0808_create_clear_command()
This single function has a quite different behavior than the other
gsm0808_ functions in terms of how the resulting msgb l3h
pointers are set.  Let's document that to avoid more confusion.

Change-Id: I0367760a588fc968c5a2dea46001ef1ee7965c8c
2019-02-18 13:34:02 +00:00
Harald Welte 10ba47dd37 Fix BSSMAP length generated by gsm0808_create_clear_command2()
In Change-Id Id8a75e1da2d5f520064666e4ee413d1c91da6ae3 we recently
introduced adding the "CSFB INDICATOR" IE to the CLEAR COMMAND,
but we did so with a wrong length value.

Change-Id: I4d07d25fb03ca0f89fd7b94226c54309c77a010a
Closes: OS#3805
Related: OS#2778
2019-02-18 13:11:03 +00:00
Neels Hofmeyr ee91040cec fix osmo_gsm48_classmark* libosmogsm.map entries
When the initial patch was tweaked from osmo_classmark_* to
osmo_gsm48_classmark_* naming, the libosmogsm.map entries were forgotten to be
changed as well.

Change-Id: I53a41b5e965a529d3c146ee85102f7f1725c6014
2019-02-15 04:02:37 +01:00
Neels Hofmeyr a0331edcef get_value_string(): guard against NULL
get_value_string() conveniently prints the value number to a static buffer if
it is unknown in a value_string array. Do the same if the value_string array
pointer itself is NULL.

If a value string array is user supplied and might be NULL, one could add a
separate NULL check around it; but by making get_value_string() itself guard
against NULL, another static char buffer to print the value number is avoided.

Change-Id: Ie640e9258a959da8f4f9089478de993509853997
2019-02-15 03:01:54 +00:00
Max 450f5ac910 Enable remote SIM protocol log level
It's defined in logging.h for quite some time but is not actually
enabled alongside with other internal logging categories.

Change-Id: I0e7a2add6293a072752900608c8ba34cc3850f31
2019-02-14 19:19:57 +01:00
Vadim Yanitskiy 6b4895ff53 gsm/gsm0480: introduce gsm0480_create_release_complete()
In OsmoMSC, it's required to be able to specify a particular GSM 04.07
transaction ID for GSM 04.80 Release complete message instead of the
hard-coded value, that is used gsm0480_create_ussd_release_complete().

Let's finally deprecate gsm0480_create_ussd_release_complete(), and
introduce a new function without USSD prefix, as this message
is also used in other "structured" supplementary services.

Change-Id: Ie3ac85fcef90a5e532334ba3482804d5305c88d7
2019-02-08 08:31:42 +00:00
Philipp Maier 74c4c4e91a gsm0808: Add CSFB indication IE to BSSMAP CLEAR COMMAND
When a call that was established in a CSFB context ends the CLEAR
COMMAND that is send from the BSC to the MSC should contain a CSFB
indication IE, which consists of just the IE byte itsslef. This
additional IE tells the BSC to include other CSFB related IEs into the
RR Release message.

Change-Id: Id8a75e1da2d5f520064666e4ee413d1c91da6ae3
Related: OS#3778
2019-02-05 15:11:36 +00:00
Neels Hofmeyr 0fd615fd7b add osmo_tdef API, originally adopted from osmo-bsc T_def
Move T_def from osmo-bsc to libosmocore as osmo_tdef. Adjust naming to be more
consistent. Upgrade to first class API:
- add timer grouping
- add generic vty support
- add mising API doc
- add C test
- add VTY transcript tests, also as examples for using the API

From osmo_fsm_inst_state_chg() API doc, cross reference to osmo_tdef API.

The root reason for moving to libosmocore is that I want to use the
mgw_endpoint_fsm in osmo-msc for inter-MSC handover, and hence want to move the
FSM to libosmo-mgcp-client. This FSM uses the T_def from osmo-bsc. Though the
mgw_endpoint_fsm's use of T_def is minimal, I intend to use the osmo_tdef API
in osmo-msc (and probably elsewhere) as well. libosmocore is the most sensible
place for this.

osmo_tdef provides:

- a list of Tnnnn (GSM) timers with description, unit and default value.
- vty UI to allow users to configure non-default timeouts.
- API to tie T timers to osmo_fsm states and set them on state transitions.

- a few standard units (minute, second, millisecond) as well as a custom unit
  (which relies on the timer's human readable description to indicate the
  meaning of the value).
- conversion for standard units: for example, some GSM timers are defined in
  minutes, while our FSM definitions need timeouts in seconds. Conversion is
  for convenience only and can be easily avoided via the custom unit.

By keeping separate osmo_tdef arrays, several groups of timers can be kept
separately. The VTY tests in tests/tdef/ showcase different schemes:

- tests/vty/tdef_vty_test_config_root.c:
  Keep several timer definitions in separately named groups: showcase the
  osmo_tdef_vty_groups*() API. Each timer group exists exactly once.

- tests/vty/tdef_vty_test_config_subnode.c:
  Keep a single list of timers without separate grouping.
  Put this list on a specific subnode below the CONFIG_NODE.
  There could be several separate subnodes with timers like this, i.e.
  continuing from this example, sets timers could be separated by placing
  timers in specific config subnodes instead of using the global group name.

- tests/vty/tdef_vty_test_dynamic.c:
  Dynamically allocate timer definitions per each new created object.
  Thus there can be an arbitrary number of independent timer definitions, one
  per allocated object.

T_def was introduced during the recent osmo-bsc refactoring for inter-BSC
handover, and has proven useful:

- without osmo_tdef, each invocation of osmo_fsm_inst_state_chg() needs to be
  programmed with the right timeout value, for all code paths that invoke this
  state change. It is a likely source of errors to get one of them wrong.  By
  defining a T timer exactly for an FSM state, the caller can merely invoke the
  state change and trust on the original state definition to apply the correct
  timeout.

- it is helpful to have a standardized config file UI to provide user
  configurable timeouts, instead of inventing new VTY commands for each
  separate application of T timer numbers.

Change-Id: Ibd6b1ed7f1bd6e1f2e0fde53352055a4468f23e5
2019-02-04 18:52:16 +01:00
Neels Hofmeyr c1aa178c8b vty api: add vty_out_va()
Provide a va_list type vty_out() variant, to be able to pass on variable
arguments from other function signatures to vty_out().

This will be used by Ibd6b1ed7f1bd6e1f2e0fde53352055a4468f23e5 for osmo_tdef.

Change-Id: Ie6e6f11a6b794f3cb686350c1ed678e4d5bbbb75
2019-02-04 16:43:57 +00:00
Neels Hofmeyr 8d04f95d96 vty telnet: consistently never change nodes upon CTRL-C
Remove any special node exiting from the VTY CTRL-C handling.

From a curious VTY transcript test glitch, I noticed weird behavior by the VTY
telnet shell: usually, when the user hits CTRL-C, that means to cancel the
current command line and present a fresh, clean prompt. However, only on the
CONFIG_NODE and CFG_LOG_NODE, a CTRL-C also exits the current node and moves up
by one level. This behavior is unexplainable and makes zero sense.

No other nodes exit on CTRL-C:
- on the ENABLE node, a CTRL-C stays on the ENABLE_NODE and doesn't exit to the
  VIEW_NODE.
- any sub-nodes of the CONFIG_NODE stay unchanged, e.g. 'network' or 'bts' /
  'trx', etc.

There is no apparent special meaning of CTRL-C on CONFIG_NODE nor CFG_LOG_NODE
to justify this odd choice.

Particularly, the vty transcript tests using osmo_verify_transcript_vty.py rely
on sending CTRL-C to clear the command prompt, so that we can properly test
sending '?' to the VTY during transcripts. In a live session, a '?' prints
available options and then updates the prompt with identical command arguments.
In a transcript test, that doesn't make sense, because each time the transcript
writes out a new command to run. Consider e.g. a transcript test like:

	tdef_vty_test(config)# timer ?
	  tea       Tea time
	  test      Test timers
	  software  Typical software development cycle

	tdef_vty_test(config)# timer tea ?
	  [TNNNN]  T-number, optionally preceded by 't' or 'T'.

To be able to issue a fresh command after '?', osmo_verify_transcript_vty.py
explicitly sends a CTRL-C to clear the command buffer. Hence there we rely on
predictable behavior of CTRL-C.

More particularly, the upcoming osmo_tdef_vty transcript tests are apparently
the first that want to test '?' behavior on the CONFIG_NODE's root level and
fall on their face, because of the implicit exit that happens only there.

Change-Id: I4f339ba61f1c273fa7da85caf77ba116ae2697b1
2019-02-04 16:43:57 +00:00
Neels Hofmeyr 9ea9dd0d5f vty: enable tab-completion for optional-multi-choice args
In cmd_complete_command_real(), detect and strip square braces from
multi-choice arguments, to enable tab-completion for commands like

 > list
 cmd [(alpha|beta)]
 > cmd <TAB>
 alpha beta
 > cmd be<TAB>
 > cmd beta

Change-Id: I8c304300b3633bb6e9b3457fcfa42121c8272ac0
2019-02-04 16:43:57 +00:00
Neels Hofmeyr b55f4d2df2 vty: enable optional-multi-choice syntax: [(one|two)]
Since very recently we sensibly handle commands like

  cmd ([one]|[two]|[three])

as optional multi-choice arguments. In addition, support the more obvious
syntax of

  cmd [(one|two|three)]

Internally, the tokens are mangled to [one] [two] and [three], which is how the
rest of the code detects optional args, and makes sense in terms of UI:

  > cmd ?
  [one]
  [two]
  [three]

(i.e. optional arguments are always shown in braces in '?' listings)

Before this patch, commands defined with a syntax like [(one|two)], would lead
to an assertion (shows as "multiple") during program startup.

Change-Id: I952b3c00f97e2447f2308b0ec6f5f1714692b5b2
2019-02-04 16:43:57 +00:00
Neels Hofmeyr c197809deb vty: enable optional-multi-choice syntax: ([one]|[two])
Add basic optional multi-choice argument support.

The VTY detects optional arguments by square braces.

 > cmd ?
 [optional-arg]
 > cmd optional-arg
 ok
 > cmd
 ok

However, within multi-choice args, these braces were so far not treated as
optional:

 > list
 cmd2 ([one]|[two]|[three])
 > cmd2
 % Command incomplete

In preparation for I952b3c00f97e2447f2308b0ec6f5f1714692b5b2 which will enable
the more obvious syntax of

  cmd [(one|two)]

for reasons of internal implementation, first support a syntax of

  cmd ([one]|[two])

The internal vty implementation always needs square braces around each option.
There is currently no good way to prevent developers from defining braces
inside multi-arguments, so it is easiest to allow and handle them:

 > list
 cmd2 ([one]|[two]|[three])
 > cmd2
 ok

The VTY doesn't guard against a mix like

 cmd (one|[two])

With this patch, a multi-choice command is treated as optional iff the first
element is in square brackets. The remaining elements' square brackets have no
effect besides confusing the user. This is not explicitly checked against.

In general, I would prefer to check all of these details, but the current VTY
code with its endless code duplication and obscure string mangling just doesn't
provide that luxury. There are numerous worse errors hidden in there.

Change-Id: I9a8474bd89ddc2155c58bfca7bd038d586aaa60a
2019-02-04 16:43:57 +00:00
Oliver Smith d6ff9c8315 GSUP: deprecate osmo_gsup_get_err_msg_type()
Replace osmo_gsup_get_err_msg_type() with a wrapper to
OSMO_GSUP_TO_MSGT_ERROR(). This macro assumes, that all error messages
are (request message | 0x000001). Add a big comment header for
osmo_gsup_message_type, describing this already implicitly followed rule
and therefore making it explicit.

With this change, we don't need to maintain the request -> error message
mapping in osmo_gsup_get_err_msg_type() anymore.

Related: Iec1b4ce4b7d8eb157406f006e1c4241e8fba2cd6 (osmo-gsm-manuals)
Change-Id: I46d9f2327791978710e2f90b4d28a3761d723d8f
2019-02-04 10:42:12 +00:00
Neels Hofmeyr 89991fdb7c osmo_fsm_inst_state_chg(): clamp timeout_secs to <= ~68 years
During testing of the upcoming tdef API, it became apparent that passing very
large timeout values to osmo_fsm_inst_state_chg() wraps back in the number
range, and might actually result in effectively very short timeouts instead.

Since time_t's range is not well defined across platforms, use a reasonable
maximum value of signed 32 bit integer. Hence this will be safe at least on
systems with an int32_t for struct timeval.tv_sec and larger.

Clamp the osmo_fsm_inst_state_chg() timeout_secs argument to a maximum of
0x7fffffff, which amounts to just above 68 years:
float(0x7fffffff) / (60. * 60 * 24 * 365.25) = 68.04965038532715

(In upcoming patch Ibd6b1ed7f1bd6e1f2e0fde53352055a4468f23e5, this can be
verified to work by invoking tdef_test manually with a cmdline argument passed
to enable the range check.)

Change-Id: I35ec4654467b1d6040c8aa215049766089e5e64a
2019-01-31 17:40:24 +01:00
Neels Hofmeyr bd5a1dc84f osmo_fsm_inst_state_chg(): set T also for zero timeout
Before this patch, if timeout_secs == 0 was passed to
osmo_fsm_inst_state_chg(), the previous T value remained set in the
osmo_fsm_inst->T.

For example:

  osmo_fsm_inst_state_chg(fi, ST_X, 23, 42);
  // timer == 23 seconds; fi->T == 42
  osmo_fsm_inst_state_chg(fi, ST_Y, 0, 0);
  // no timer; fi->T == 42!

Instead, always set to the T value passed to osmo_fsm_inst_state_chg().

Adjust osmo_fsm_inst_state_chg() API doc; need to rephrase to accurately
describe the otherwise unchanged behaviour independently from T.

Verify in fsm_test.c.

Rationale: it is confusing to have a T number remaining from some past state,
especially since the user explicitly passed a T number to
osmo_fsm_inst_state_chg(). (Usually we are passing timeout_secs=0, T=0).

I first thought this behavior was introduced with
osmo_fsm_inst_state_chg_keep_timer(), but in fact osmo_fsm_inst_state_chg()
behaved this way from the start.

This shows up in the C test for the upcoming tdef API, where the test result
printout was showing some past T value sticking around after FSM state
transitions. After this patch, there will be no such confusion.

Change-Id: I65c7c262674a1bc5f37faeca6aa0320ab0174f3c
2019-01-29 10:25:26 +00:00
Neels Hofmeyr 7740d26d7e add osmo_classmark_* API
osmo-bsc and osmo-msc implement identical Classmark structures. It makes sense
to define once near the gsm48 protocol definitions.

Also move along some generic Classmark API from osmo-msc.

Change-Id: Ifd27bab0380f7ad0c44c719aa6c8bd62cf7b034c
2019-01-29 00:59:32 +01:00
Neels Hofmeyr 0423b61aa8 add osmo_hexdump_buf() and test
Add osmo_hexdump_buf() as an all-purpose hexdump function, which all other
osmo_hexdump_*() implementations now call. It absorbs the static
_osmo_hexdump(). Add tests for osmo_hexdump_buf().

Rationale: recently during patch review, a situation came up where two hexdumps
in a single printf would have been useful. Now I've faced a similar situation
again, in ongoing development. So I decided it is time to provide this API.

The traditional osmo_hexdump() API returns a non-const char*, which should
probably have been a const instead. Particularly this new function may return a
string constant "" if the buf is NULL or empty, so return const char*. That is
why the older implementations calling osmo_hexdump_buf() separately return the
buffer instead of the const return value directly.

Change-Id: I590595567b218b24e53c9eb1fd8736c0324d371d
2019-01-28 23:58:53 +00:00