Commit Graph

3165 Commits

Author SHA1 Message Date
Pau Espin 14aadd5b6f vty: tests: Verify incomplete optional parameters are passed to vty funcs
The test shows that in the case were "single0 on" is executed, VTY
function should return complete "single0 one" but it doesn't.

Related: OS#4045
Change-Id: Ib5b9dc07e2b280dc95011b3926afb1d490cadd81
2019-06-14 12:43:19 +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
Kevin Redon 77021c7bec (minor) fix typo in comments
Change-Id: I697af428a2ea9a0ccd3f04ba8ec4664935ae29f8
2019-06-13 18:13:34 +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 d1e220fb67 minor: don't redefine macros
the DEBUG macro name and ARRAY_SIZE macro function are frequently
used in other projects. If these projects also use libosmocore,
the macros will be redefined. This also generates a warning message
during compilation.
Not redefining the macros removes the warning message and possible
(but unlikely) mis-redefinition.

Change-Id: I0ba91eae8eacc5542d1647601b372e417ed1713c
2019-06-13 13:49:30 +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 b8734baa23 protocol/gsm_04_08.h: do not check if unsigned is positive
Change-Id: I6b486b52a3733d5fd5e8ba18acbc9374e2e8bd7e
2019-06-12 11:29:06 +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
Vadim Yanitskiy 8c9befeaee vty_transcript_test.vty: add choice auto-complete tests
This patch is a result of discussion we had in [1]. The key idea
is that libosmovty should properly auto-complete the commands
containing choice, such as the following one:

  multi0 (one|two|three)

[1] If9b0c0d031477ca87786aab5c269d00748e896c8

Right now, sending the following command:

  (osmo-foo-bar)# multi0 th

would basically match the following vector:

  multi0 three

however the resulting argv would be:

  ["multi0", "th"]

Moreover, sending the following command:

  (osmo-foo-bar)# multi0 t

would basically match the following vectors:

  multi0 two
  multi0 three

because both start from 't', so the resulting argv would be:

  ["multi0", "t"]

which is ambiguous!

The expected output is:

  (osmo-foo-bar)# multi0 th
  ok argc=1 three

  (osmo-foo-bar)# multi0 t
  % Ambiguous command.

This is going to be fixed in the follow up patches.

Change-Id: I83c3aef813173952641035862c534ef16384780e
2019-06-06 06:26:30 +00: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
Alexander Couzens 9b20741910 utils: add gsmtap_logread.py a gsmtap log reader
Receive gsmtap logs and feeds it into the python logging
framework. Allows to use generic logging features and
further utilities.

Change-Id: I24478d8e16066c6118e867bdba54c6418c15e170
2019-06-04 08:37:06 +00: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
Vadim Yanitskiy aa0683d9f8 gsm0408/gsm0408_test.c: introduce BCD number encoding / decoding test
So far, both gsm48_encode_bcd_number() and gsm48_decode_bcd_number2()
did not have any unit test coverage. Let's fill this gap by testing
the following scenarios:

  - encoding / decoding of a regular 9-digit MSISDN;
  - encoding / decoding of a MSISDN with optional LHV;
  - encoding / decoding of a long 15-digit MSISDN;
  - encoding / decoding of a MSISDN to a buffer:
    - with exactly matching size,
    - with lower size (truncation);
  - decoding LV buffer with incorrect length,
  - encoding / decoding an empty input buffer.

As it turns out, 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. This is
reflected in the unit test output:

  Decoding HEX (buffer limit=16) '0821436587092143f5'...
    Expected: (rc=0) '123456789012345'
      Actual: (rc=0) '12345678901234'

Moreover, if the output buffer is shorter than decoded number,
gsm48_decode_bcd_number2() silently truncates it and returns 0,
while its description states, that the rc should reflect this.

To be fixed in the follow-up patches.

Change-Id: I4b2c330cf8ffe4427c0bee7d5f3b74be56ecd85d
Related: 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
Vadim Yanitskiy 1d32b7fecd protocol/gsm_12_21.h: fix copy-pasted struct description
Change-Id: Ic6d32c886f6f8f859e382d48f9e1b509000db9ba
2019-05-24 18:35:22 +07: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
Oliver Smith e0c5d700ae Cosmetic: GSUP: fix too long comment line
Change-Id: I60ba8fef8924e58bc73cff5c7ff77ebb76d8bfaa
2019-05-19 07:18:18 +00:00
Daniel Willmann 0a1259ba87 Deprecate usage of osmo_counter_*
There's not many of those around any more, let's try to move them to
osmo_stat_items

Change-Id: If67f64c6ec7a3f3114c962df9db50107d9ea86e2
2019-05-19 07:18:04 +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
Harald Welte 753ae497c7 Revert "Change GSM48_PDISC_* to enum type"
This reverts commit ece1d8509d
which causes build failures due to compile warnings everywhere.

Change-Id: Ic131439ea206a0b0f57968ef701667da73711b51
2019-05-18 11:08:36 +02:00
Max ece1d8509d Change GSM48_PDISC_* to enum type
An enum is more clear than an int and #defines for passing around,
also in case you have a switch () statement, the compiler will issue
warnings for unhandled cases.

Change-Id: Icbbe8786a776081d7643193f154e6270224399e6
2019-05-17 22:59:23 +00:00