Commit Graph

449 Commits

Author SHA1 Message Date
Harald Welte 0d67f483e2 logging_vty: Ensure writing well-formed config files
We want to have well-formed config files that print exactly one space
per VTY/config node level, and not two.

Change-Id: Ia75c7067284ea225cffe13ca71bad05a7747ae66
2018-09-25 20:25:30 +02:00
Philipp Maier 8515d035ae gsm0808: add function to convert AMR S15-S0 to gsm0408 settings
Add a function to convert S0-S15 bits to struct gsm48_multi_rate_conf,
which hold the codec settings for AMR.

Change-Id: I973736273c236eee84decf15868190e339c3fed4
Related: OS#3548
2018-09-25 15:32:29 +00:00
Philipp Maier 5f2eb15074 gsm0808: add function to convert amr gsm0408 setings to gsm0808
Add a function to convert struct gsm48_multi_rate_conf, which holds the
codec settings for AMR, to S0-S15 bit representation as defined in
3GPP TS 48.008 3.2.2.49

This resurrects change-id I4e656731b16621736c7a2f4e64d9ce63b1064e98
which was reverted in I9e0d405e303ed86d23703ca6362e958dddb2f861
due to gsm0808_test failing.

The test failure is fixed by properly clearing the struct
gsm48_multirate_cfg prior to running tests (add memset(0)).

Change-Id: Ia782e21c206c15e840226d79b4209d13658ee916
Related: OS#3548
2018-09-19 14:01:10 +00:00
Neels Hofmeyr 28fc078f9c logging vty: add 'logging level set-all <level>'
Add new command to once-off set each and every category to the given log level,
as discussed at length on the openbsc@ mailing list.

Show that it works in logging_vty_test.vty.

Change-Id: I4c3e4f786476cb813fdc0a7c64f30ee04758309d
2018-09-16 23:09:56 +02:00
Neels Hofmeyr dd8c73cc6d Revert "gsm0808: add function to convert amr gsm0408 setings to gsm0808"
This reverts commit 2fd4fe6aa1.

As shown in https://jenkins.osmocom.org/jenkins/view/master/job/master-libosmocore/475/a2=default,a3=default,arch=amd64,label=osmocom-master-debian9/console

This commit breaks gsm0808_test with:

stderr:
--- expout	2018-09-16 22:37:31.382280438 +0200
+++ /n/s/dev/make/libosmocore/tests/testsuite.dir/at-groups/21/stdout	2018-09-16 22:37:31.426281372 +0200
@@ -78,9 +78,9 @@
 Input:
  m4_75= 0   smod=  0
  m5_15= 0   spare= 0
- m5_90= 0   icmi=  0
+ m5_90= 0   icmi=  1
  m6_70= 0   nscb=  0
- m7_40= 0   ver=   0
+ m7_40= 0   ver=   6
  m7_95= 0
  m10_2= 0
  m12_2= 0
@@ -92,9 +92,9 @@
 Input:
  m4_75= 1   smod=  0
  m5_15= 0   spare= 0
- m5_90= 0   icmi=  0
+ m5_90= 0   icmi=  1
  m6_70= 0   nscb=  0
- m7_40= 0   ver=   0
+ m7_40= 0   ver=   6
  m7_95= 0
  m10_2= 0
  m12_2= 0
@@ -106,9 +106,9 @@
 Input:
  m4_75= 0   smod=  0
  m5_15= 1   spare= 0
- m5_90= 0   icmi=  0
+ m5_90= 0   icmi=  1
[...]

Change-Id: I9e0d405e303ed86d23703ca6362e958dddb2f861
2018-09-16 21:02:25 +00:00
Philipp Maier 2fd4fe6aa1 gsm0808: add function to convert amr gsm0408 setings to gsm0808
Add a function to convert struct gsm48_multi_rate_conf, which holds the
codec settings for AMR, to S0-S15 bit representation as defined in
3GPP TS 48.008 3.2.2.49

Change-Id: I4e656731b16621736c7a2f4e64d9ce63b1064e98
Related: OS#3548
2018-09-14 16:24:10 +02:00
Neels Hofmeyr 9540c24058 logging vty: deprecate 'all', introduce 'force-all'
Add 'logging level force-all <level>' and 'no logging level force-all' as new
names for 'logging level all <level>' and 'logging level all everything'.

Resurrect the functionality of 'logging level all everything' -- even if it is
still deprecated because the name is confusing, it is now just an alias for
'no logging level force-all'.

Show in logging_vty_test.vty that we can now again lift the global logging
clamp, both with the new commands as well as with the deprecated ones.
Also show that 'force-all' is written back properly, if set.

Change-Id: I36f17c131cc70ce5a1aef62fd9693097de230cd4
2018-09-13 15:46:55 +00:00
Neels Hofmeyr 7e0686c6b4 logging vty: deprecate the 'everything' keyword
The 'logging level all everything' has not had an effect for some time now. The
plan is to bring back its old functionality, but to keep it deprecated and
rather define a less confusing name.

* Deprecate 'everything'.
* Do not write 'everything' during 'write file' or 'show running-config', which
  we curiously still do until now.

BTW, the reason why we need to compose a complete list of categories for the
deprecated 'everything' command is explained in detail in the commit log for
I3b083f27e3d751ccec258880ae7676e9af959a63

Change-Id: Ib75fedb0572570a61bb34ee729a2af86cf5f16da
2018-09-13 15:46:55 +00:00
Neels Hofmeyr 3a9ff11e57 logging vty: add VTY transcript test
I am setting out to refactor various details about logging. To show the effect,
I am first adding this new test to illustrate the exact effects on the various
osmo programs.

Add logging_vty_test.c as a standalone program that simply defines a few
logging categories and opens a telnet vty to play with.

Add logging_vty_test.vty, as an osmo_verify_transcript_vty.py test script.

Add --enable-external-tests to configure.ac, to enable running
logging_vty_test.vty during 'make check'.

Also allow running 'make vty-test' without the need to first configure with
--enable-external-tests (a flexibility I've missed many times over in the other
osmo source trees).

Add a Makefile.am stub for external CTRL tests, basically a copy-paste from
osmo-msc.git. I doubt that libosmocore will get python driven CTRL interface
testing any time soon, but if so we will know to not run it concurrently.

Change-Id: I948e832a33131f8eab98651d6010ceb0ccbc9a9c
2018-09-12 03:06:37 +02:00
Neels Hofmeyr ec6fdbb128 fix tests linking: don't use system installed libs
Do not link against the system-wide installed libosmo* libs when building the
regression test programs. Always use the locally built ones.

Linking some libosmo libraries causes libtool to pull in other libosmo libs
even though they were not explicitly named. For example, ctrl_test explicitly
links libosmoctrl, but this also has dependencies to libosmovty and libosmogsm:

  ldd src/ctrl/.libs/libosmoctrl.so | grep osmo
    libosmocore.so.11 => /usr/local/lib/libosmocore.so.11 (0x00007f26c26d4000)
    libosmogsm.so.10 => /usr/local/lib/libosmogsm.so.10 (0x00007f26c22bb000)
    libosmovty.so.4 => /usr/local/lib/libosmovty.so.4 (0x00007f26c2171000)

If we omit explicit LDADD of these dependencies in the Makefile.am, libtool
will take the first canonical place to find them, which may just be the already
installed older versions of the same libs, which may or may not be compatible
with the current build. In any case, it is never intended to link installed
libs.

All library dependencies are listed by this quick script:

  cd libosmocore
  for l in $(find . -name "*.so") ; do echo; echo "$l"; ldd $l | grep libosmo; done

  ./.libs/libosmocore.so

  ./coding/.libs/libosmocoding.so
    libosmocore.so.11 => /usr/local/lib/libosmocore.so.11 (0x00007f25fc3c2000)
    libosmogsm.so.10 => /usr/local/lib/libosmogsm.so.10 (0x00007f25fbfa9000)
    libosmocodec.so.0 => /usr/local/lib/libosmocodec.so.0 (0x00007f25fbf9b000)

  ./codec/.libs/libosmocodec.so
    libosmocore.so.11 => /usr/local/lib/libosmocore.so.11 (0x00007fb4c900d000)

  ./ctrl/.libs/libosmoctrl.so
    libosmocore.so.11 => /usr/local/lib/libosmocore.so.11 (0x00007f5df5129000)
    libosmogsm.so.10 => /usr/local/lib/libosmogsm.so.10 (0x00007f5df4d10000)
    libosmovty.so.4 => /usr/local/lib/libosmovty.so.4 (0x00007f5df4bc6000)

  ./gb/.libs/libosmogb.so
    libosmocore.so.11 => /usr/local/lib/libosmocore.so.11 (0x00007f788e536000)
    libosmovty.so.4 => /usr/local/lib/libosmovty.so.4 (0x00007f788e3ec000)
    libosmogsm.so.10 => /usr/local/lib/libosmogsm.so.10 (0x00007f788dfd3000)

  ./vty/.libs/libosmovty.so
    libosmocore.so.11 => /usr/local/lib/libosmocore.so.11 (0x00007f3b7ed21000)

  ./gsm/.libs/libosmogsm.so
    libosmocore.so.11 => /usr/local/lib/libosmocore.so.11 (0x00007fc69472e000)

  ./sim/.libs/libosmosim.so
    libosmocore.so.11 => /usr/local/lib/libosmocore.so.11 (0x00007f2f6412d000)
    libosmogsm.so.10 => /usr/local/lib/libosmogsm.so.10 (0x00007f2f63d14000)

Add all explicit linking of all required library dependencies in all regression
test programs, as shown by above listing.

Example for reproducing a problem:

In libosmocore.a, introduce a new function, and call that from libosmovty code.
For example, I made loglevel_strs non-static in logging.c, and used that in
logging_vty.c. Build and install this in a place where libtool can find it.
Then go back to before this change and rebuild. You will see that linking
ctrl_test (before this patch) then complains about libosmovty requiring the
loglevel_strs symbol which it cannot find in libosmocore.so.

Change-Id: Id084e6e6efd25cd62b1bd7a4fc7c5985c39130c6
2018-09-11 23:21:28 +02:00
Neels Hofmeyr 7c749893bf add osmo_str_tolower() and _toupper() with test
We already have osmo_str2lower() and osmo_str2upper(), but these lack:
* proper destination buffer bounds checking,
* ability to call directly as printf() argument.

Deprecate osmo_str2upper() and osmo_str2lower() because of missing bounds
checking.

Introduce osmo_str_tolower_buf(), osmo_str_toupper_buf() to provide
bounds-safe conversion, also able to safely convert a buffer in-place.

Introduce osmo_str_tolower(), osmo_str_toupper() that call the above _buf()
equivalents using a static buffer[128] and returning the resulting string
directly, convenient for direct printing. Possibly truncated but always safe.

Add unit tests to utils_test.c.

Replace all libosmocore uses of now deprecated osmo_str2lower().

Naming: the ctype.h API is called tolower() and toupper(), so just prepend
'osmo_str_' and don't separate 'to_lower'.

Change-Id: Ib0ee1206b9f31d7ba25c31f8008119ac55440797
2018-09-07 04:28:39 +02:00
Harald Welte 7869baf843 Deprecate ipa_ccm_idtag_parse() with ipa_ccm_id_{get,resp}_parse()
In the past, the function ipa_ccm_idtag_parse() was used to parse
the payload of IPA CCM ID RESP packets.  However, the function was
based on a possible misunderstanding of the message encoding, and
callers actually counted the first (upper) length nibble as part
of the header and passed a pointer to the second
(lower) length nibble of the first TLV into this function.  As such,
it was unfixable, and had to be replaced with a new function called
ipa_ccm_id_resp_parse().  At the same time, we also add
ipa_ccm_id_get_parse() to parse the slightly different format of
the IPA CCM ID GET payload.

We can never be 100% sure what is "correct", as our understanding
of the protocol is entirely based on protocol analysis, without any
official documentation available.

This patch also introduces unit test coverage for both of the new
functions.

Revert "ipa: Add libosmogsm.map entry for ipa_ccm_idtag_parse_off"
This reverts commit 7f31c90b80.

Revert "ipa: Properly parse LV stream of a ID_GET request"
This reverts commit f558ed4bb9.

It introduced a function/behavior that was not originally intended:
The parse of IPA CCM ID GET (8bit length followed by 1 byte tag
and variable-length payload) instead of the IPA CCM ID RESP (16bit
length followed by 1 byte tag and variable-length payload).

Change-Id: I1834d90fbcdbfcb05f5b8cfe39bfe9543737ef8f
2018-08-01 13:38:17 +02:00
Harald Welte 48fd019b43 cosmetic: More context / naming / comment for test_idtag_parsing()
Change-Id: I1ebeba2067549e0dd1541fa84715d44321ff3b43
2018-07-31 20:19:49 +02:00
Harald Welte 6db529aedd import oap_client_test from osmo-sgsn
As oap_client has moved from osmo-sgsn to libosmogsm, it is only fair
that the related unit test shall also be moved here.

Change-Id: I9d64e10b4bacac9b530cf077841bad762fc6d558
2018-07-30 18:24:49 +02:00
Pau Espin 421068e643 tests: codec: ecu_fr: Add buffer with unequal XMAXC values
This buffer verifies that all XMAXC fields must be zero before the
entire buffer is considered as silent by osmo_ecu_fr_conceal().

Change-Id: I14a192d001b5e167437cedbe76a1a3dd84dde35c
2018-07-21 07:40:20 +00:00
Pau Espin bbccca60d6 tests: codec: ecu_fr: Print XMAXC fields
This makes it easy to debug how XMAXC fields are decreased every
iteration in osmo_ecu_fr_conceal().

Change-Id: I678d4be5e0b15b05873b0d3bf5ea5bbee7bef839
2018-07-21 07:40:20 +00:00
Neels Hofmeyr 59f4caf4ef add osmo_sockaddr_to_str_and_uint()
This came from osmo-bsc refactoring patch I82e3f918295daa83274a4cf803f046979f284366
https://gerrit.osmocom.org/#/c/osmo-bsc/+/9671/6/src/osmo-bsc/gsm_data.c@1708

Add regression test in utils_test.c.

Change-Id: I1f2918418c38918c5ac70acaa51a47adfca12b5e
2018-07-20 14:02:21 +00:00
Neels Hofmeyr 1504211fdc utils_test: check stderr to catch sanitizer issues
Recent OS#3407 shows that we should verify stderr to catch sanitizer failures.
(They might not always be ignorable like that one.)

Change-Id: Ic9e437a1cc96ae081e0fd6a9b6e3156987e14c0c
2018-07-20 14:02:21 +00:00
Neels Hofmeyr 6979c54793 utils_test: fix isqrt_test calculation range
Multiplying the uint16_t x by itself seems to default to be calculated in
int32_t range, while it obviously needs uint32_t. This causes sporadic
sanitizer barfs:

    Testing integer square-root
    utils_test.c:445:18: runtime error: signed integer overflow: 60369 * 60369 cannot be represented in type 'int'

The final result is still correct, because it is in fact interpreted as uint32_t.

Cast to uint32_t to make sure the sanitizer doesn't complain.

Related: OS#3407
Change-Id: I83c14e38deaa466d977ee43c9420534ed90f090d
2018-07-20 14:02:21 +00:00
Pau Espin b885ef88c1 tests: ctrl: Test received ERROR messages are handled correctly
Change-Id: I3c8e95aaa1ca222d4cd1395e548f8461bf9d4cd6
2018-07-16 17:56:25 +00:00
Neels Hofmeyr 5314c513f2 vty: fix use-after-free and memleaks in is_cmd_ambiguous()
vty_test: add test against ambiguous cmd causing use-after-free and memory
leaks. Add this test along with the fix, because the new test triggers the
memory use-after-free and leaks, causing build failures.

Add cmd_deopt_with_ctx() to allow passing a specific talloc ctx.

is_cmd_ambiguous(): keep all cmd_deopt() allocations until the function exits.
Add a comment explaining why. Before this, if a command matched an optional
"[arg]" with square brackets, we would keep it in local var 'matched', but we
would free the string it points to at the end of that loop iteration; upon
encountering another match, we would attempt to strcmp against the freed
'matched'. Instead of adding hard-to-read and -verify free/alloc dances to keep
the 'matched' accurately freed/non-freed/..., just keep all cmd_deopt() string
allocated until done.

Needless to say that this should have been implemented on a lower level upon
inventing optional args, but at least this is fixing a program crash.

Related: OS#33903390
Change-Id: Ia71ba742108b5ff020997bfb612ad5eb30d04fcd
2018-07-11 15:47:08 +02:00
Vadim Yanitskiy 94c0031297 Don't enforce Python 2 for utilities
The conv_gen.py utility was tested against both Python 2 and 3,
so there is no need to enforce Python 2. Also, having:

  #!/usr/local/bin/python{2|3}

is a bad idea, because Python may be installed in a different location.

Change-Id: I6007d481047b584db13d6eda70fb99f11f9ddaa1
2018-07-02 20:30:31 +07:00
Vadim Yanitskiy 5a09f75c1e gsm/gsm0480: refactor and expose gsm0480_parse_facility_ie()
This function can be used when there is only a part of GSM 04.80
message available - Facility IE, e.g. when a message is carried
over GSUP/MAP. Let's expose it.

Refactoring includes the following:

  - adding the 'gsm0480_' prefix;
  - correcting inverted return value;
  - cosmetic code style changes.

Change-Id: I623c39ffbe6cdee65eade8435a2faa04d0da193e
2018-06-11 23:50:00 +07:00
Vadim Yanitskiy 52e44121db gsm/gsm0480.c: introduce gsm0480_extract_ie_by_tag()
In some cases, there is no need to parse the whole message,
e.g. during the conversion from DTAP to GSUP/MAP. This
function can be used to extract given IE from a message.

Change-Id: I3989d061903352473305f80712f1a1560d05df3d
2018-06-11 23:45:48 +07:00
Harald Welte 15a5f8de00 Add osmo_isqrt32() to compute 32bit integer square root
Change-Id: I2b96db6e037e72e92317fec874877e473a1cf909
2018-06-06 16:58:53 +02:00
Neels Hofmeyr 407df02e7c add osmo_fsm_inst_state_chg_keep_timer()
Change-Id: I3c0e53b846b2208bd201ace99777f2286ea39ae8
2018-05-31 21:01:33 +00:00
Vadim Yanitskiy 36c7b33ccc GSUP: introduce new messages for SS/USSD payloads
In order to be able to transfer SS/USSD messages via GSUP,
this change introduces the following new message types:

  - OSMO_GSUP_MSGT_PROC_SS_*,

and the following new IE:

  - OSMO_GSUP_SS_INFO_IE

which represents an ASN.1 encoded MAP payload coming to/from
the mobile station 'as is', without any transcoding.

Change-Id: Ie17a78043a35fffbdd59e80fd2b2da39cce5e532
Related: OS#1597
2018-05-31 16:12:14 +00:00
Vadim Yanitskiy 72696040df GSUP: implement TCAP-like session management
Unlike TCAP/MAP, GSUP is just a transport layer without the
dialogue/context. This prevents us from having session based
communication, required e.g. for USSD. But we can emulate
TCAP dialogue by adding additional IEs, which would allow
to relate each message to a particular session.

This change introduces the following IEs:

  - OSMO_GSUP_SESSION_ID_IE,
  - OSMO_GSUP_SESSION_STATE_IE,

which optionally can be used to indicate that the message is
related to a session with given ID, and to manage session
state, i.e. initiate, continue, and finish.

Change-Id: I1cee271fed0284a134ffed103c0d4bebbcfde2a8
Related: OS#1597
2018-05-31 16:11:14 +00:00
Pau Espin dab4db0217 gsm: kasumi: Fix dynamic-stack-buffer-overflow on out buffers not multiple of 64 bits
Fixes following AddressSanitizer report during gea_test run with gcc
8.1.0:

==8899==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffc5f1719bb at pc 0x7fe574adc5fe bp 0x7ffc5f171460 sp 0x7ffc5f171450
WRITE of size 1 at 0x7ffc5f1719bb thread T0
    #0 0x7fe574adc5fd in osmo_store64be_ext ../../include/osmocom/core/bit64gen.h:75
    #1 0x7fe574adc649 in osmo_store64be ../../include/osmocom/core/bit64gen.h:104
    #2 0x7fe574ade936 in _kasumi_kgcore libosmocore/src/gsm/kasumi.c:186
    #3 0x7fe574ae2532 in gea4 libosmocore/src/gsm/gea.c:44
    #4 0x7fe574ae266c in gea3 libosmocore/src/gsm/gea.c:60
    #5 0x7fe574a9b616 in gprs_cipher_run libosmocore/src/gsm/gprs_cipher_core.c:95
    #6 0x56422d3fb2ee in test_gea libosmocore/tests/gea/gea_test.c:29
    #7 0x56422d3fb506 in main libosmocore/tests/gea/gea_test.c:49
    #8 0x7fe5730f406a in __libc_start_main (/usr/lib/libc.so.6+0x2306a)
    #9 0x56422d3fadf9 in _start (libosmocore/tests/gea/.libs/lt-gea_test+0x1df9)

The kasumi_test is updated to calculate the entire array of bits
according to expected result. Before this commit it worked by writing
the entire last 64bit block, and addressSanitizer cannot catch it
because the allocated buffer is 64bit aligned too.

Change-Id: I7b2a0224a3b5527d5a3ad7e17efc73081b63eac1
2018-05-17 12:13:04 +02:00
Pau Espin 16e205bfb2 tests: a5_test: Print wrong buffer correctly on error
Before this patch, osmo_hexdump is called stacked in th esame printf
function. As a result, the first returned buffer is overwriten by the
second, which means the printed buffers will show as the same always.

Change-Id: I364328a59da31537c6c9b969e34edd360b685081
2018-05-16 21:13:58 +02:00
Pau Espin 977afaae34 tests: gea_test: Use correct max size for key in buffer
Expect key sizes for GEA are 64-128 bits.

Change-Id: Iaf81992a2901733b630e3046b0c4bdc1fb9a8ace
2018-05-16 20:09:39 +02:00
Pau Espin c5c955caae tests: bitrev_test: Fix dynamic-stack-buffer-overflow
Fixes following AddressSanitizer report:
==1983==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffc245f47e6 at pc 0x7f3e2deea68c bp 0x7ffc245f4750 sp 0x7ffc245f4740
WRITE of size 1 at 0x7ffc245f47e6 thread T0
    #0 0x7f3e2deea68b in osmo_nibble_shift_right libosmocore/src/bits.c:92
    #1 0x55c01902e1ab in sh_chk libosmocore/tests/bits/bitrev_test.c:215
    #2 0x55c01902ed8f in main libosmocore/tests/bits/bitrev_test.c:305
    #3 0x7f3e2c93006a in __libc_start_main (/usr/lib/libc.so.6+0x2306a)
    #4 0x55c01902c059 in _start (libosmocore/tests/bits/.libs/lt-bitrev_test+0x5059)

This patch can be seen as a follow-up of commit
4fd6023b03, which already fixed the
left-shift case in the same way.

Change-Id: I6e86d0164b7e982bf7b7449d5b3abfb3e1e5da46
2018-05-16 17:10:33 +02:00
Pau Espin cacaa4a161 configure: Check separately for lib implementing dlopen and dlsym
Sometimes the library probiding dlopen is not the same one providing
dlsym.
This is the case when compiling with AddressSanitizer enabled. In this
case, AC_SEARCH_LIBS([dlopen]...) reports no lib is required, but tests
using dlsym still require to link against -ldl.

Change-Id: Ic619b0885688066b60c97caf1e2c7e5402c1d9f7
2018-05-04 19:25:16 +02:00
Neels Hofmeyr 178bf7a409 gsm0808_test: silence deprecation: use gsm0808_create_layer3_2()
Change-Id: Ia0afecafa8862ffbe2af3c86e5552673f0935eb0
2018-04-23 08:42:00 +00:00
Neels Hofmeyr 9a4286b709 gsm0808_test: fix more missing inits (address sanitizer issues)
In recent Iaa20c59f624fbdc69a018cabd0f7e9c5a1389519 I fixed one missing init
issue and didn't notice the N other similar ones right next to it. Also fix the
remaining missing inits.

Fixes:
    ../../../../src/libosmocore/src/gsm/gsm0808_utils.c:187:8: runtime error: load of value 13, which is not a valid value for type '_Bool'
    ../../../../src/libosmocore/src/gsm/gsm0808_utils.c:191:8: runtime error: load of value 119, which is not a valid value for type '_Bool'

Related: OS#3148
Change-Id: Ie8a1a9b3132024135ca70390eae4d21c907b2edc
2018-04-23 08:40:55 +00:00
Harald Welte 542301b067 RSL/LAPDm: Not all RLL message are "transparent"
3GPP TS 48.058 has a very clear definition of which messages are
"transparent" and hence have the T-bit == 1.  This is *not* just
all RLL messages, but basically only RLL_DATA.{ind,req} and
RLL_UNITDATA.{ind,req}.  All other messages are non-transparent.

Change-Id: I9f83654af189d818563d799bf623325b7fee8e70
Closes: OS#3188
2018-04-19 15:09:32 +00:00
Neels Hofmeyr a4399c8891 add gsm0808_cell_{id,id_list}_name() and friends
Provide comprehensive API to obtain string representations of Cell Identifiers
and -Lists.

Change gsm0808_test.c to use the new functions (which simplifies the output a
bit), so that we don't duplicate printing code in gsm0808_test.c, and so that
the not-so-trivial printing code is also tested.

In gsm0808_test, also test gsm0808_cell_id_list_name_buf()'s return value and
truncation behavior.

The rationale for gsm0808_cell_id_list_name(), i.e. printing an entire list of
cell identifiers, is that even though the maximum is 127 elements, a list of
more than a few elements is hardly ever expected in practice (even more than
one element isn't actually expected: either "entire BSS" or a single LAC). It
is thus useful to log the entire list when it shows up in Paging and Handover.

Change-Id: I9b2106805422f96c5cc96ebb9178451355582df3
2018-04-18 02:38:37 +02:00
Neels Hofmeyr c62c934647 test_gsm0808_enc_dec_speech_codec_with_cfg: initialize properly
The uninitialized members of enc_sc sporadically hit address sanitizer failure
during gsm0808_test, like:
../../../../src/libosmocore/src/gsm/gsm0808_utils.c:187:8: runtime error: load of value 13, which is not a valid value for type '_Bool'
../../../../src/libosmocore/src/gsm/gsm0808_utils.c:191:8: runtime error: load of value 119, which is not a valid value for type '_Bool'

How the test survived so long is a mystery to me; as soon as some uninitialized
members would by coincidence not be zero, the test should always have failed at
OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0).

Related: OS#3148
Change-Id: Iaa20c59f624fbdc69a018cabd0f7e9c5a1389519
2018-04-15 23:40:19 +02:00
Neels Hofmeyr db2fa4e0d5 test_gsm0808_enc_dec_cell_id_list_lac(): populate all LACs
Change-Id: I7535166a2827c03a954fe72d5d99217e4f25868f
2018-04-13 05:38:48 +02:00
Neels Hofmeyr 066473fe36 test_gsm0808_enc_dec_cell_id_list_lac(): validate encoded bytes
Change-Id: I81b1ffbe6a5ec566c112492c2cbaf99c018c45bb
2018-04-13 05:38:48 +02:00
Neels Hofmeyr 250e7f7d30 add gsm0808_{enc,dec}_cell_id
Clarify semantics and micro-optimise for the case of single Cell Identifer IEs.
Test in gsm0808_test.c

So far we have gsm0808_enc_cell_id_list2(), but there also exist instances of
single Cell Identifiers (3GPP TS 48.008 3.2.2.17).

It is possible to decode the same using the cell identifier list API, but this
forces the caller to also keep a full struct gsm0808_cell_id_list2 with all its
127 entries around.

E.g. for handover, there are two Cell Identifiers (Serving and Target); I'd
need two full cell id lists for each, and these would be dynamically allocated
for each handover operation, whether it uses them or not.

Related: OS#2283 (inter-BSC HO, BSC side)
Change-Id: I9f9c528965775698ab62ac386af0516192c4b0cc
2018-04-13 05:38:47 +02:00
Neels Hofmeyr a78b22ba20 add tlv_parse2(), capable of multiple instances of the same IE
Allow passing multiple struct tlv_parsed in an array, to allow parsing as many
repeated IEs as are expected by the caller.

From tlv_parse(), call tlv_parse2() with dec_multiple = 1 to yield the previous
behavior. tlv_parse() remains valid API.

An example of multiple IEs is the BSSMAP Handover Request, containing Cell
Identifier (Serving) and Cell Identifier (Target), both defined by 3GPP TS
48.008 3.2.2.17 with identical IE tags; both are mandatory.

Related: OS#2283 (inter-BSC HO, BSC side)
Change-Id: Id04008eaf0a1cafdbdc11b7efc556e3035b1c84d
2018-04-13 05:28:09 +02:00
Neels Hofmeyr 74663d97c6 add gsm0808_cell_id_list_add() to combine two cell identifier lists
This will be used by the upcoming neighbor_ident API in osmo-bsc, where the vty
interface allows composing neihbor BSS cell identifier lists, and we want to
allow adding individual items from individual user commands.

It will also be useful to accumulate cell identifiers in case a subscriber sees
multiple alternative cells from a neighboring BSS, and we want to pass these on
to the MSC in a Handover Required.

Related: OS#2283 (inter-BSC HO, BSC side)
Change-Id: I5781f5fa5339c92ab2e2620489b002829d206925
2018-04-13 05:28:09 +02:00
Neels Hofmeyr a64c45a03e add osmo_fsm_inst_update_id_f()
In the osmo-msc, I would like to set the subscr conn FSM identifier by a string
format, to include the type of Complete Layer 3 that is taking place. I could
each time talloc a string and free it again. This API is more convenient.

From osmo_fsm_inst_update_id(), call osmo_fsm_inst_update_id_f() with "%s" (or
pass NULL).

Put the name updating into separate static update_name() function to clarify.

Adjust the error message for erratic ID: don't say "allocate", it might be from
an update. Adjust test expectation.

Change-Id: I76743a7642f2449fd33350691ac8ebbf4400371d
2018-04-09 17:57:15 +02:00
Neels Hofmeyr 6e8c088472 cosmetic: osmo_fsm_inst_update_id(): don't log "allocate"
On erratic id in osmo_fsm_inst_update_id(), don't say "Attempting to allocate
FSM instance".

Escape the invalid id using osmo_quote_str().

Change-Id: I770fc460de21faa42b403f694e853e8da01c4bef
2018-04-09 17:57:15 +02:00
Neels Hofmeyr 71f76a1f42 fsm: id: properly set name in case of NULL id
Since alloc relies on osmo_fsm_inst_update_id() to set the name, never skip
that.

In osmo_fsm_inst_alloc(), we allow passing a NULL id, and in
osmo_fsm_inst_update_id(), we set the name without id if id is NULL.

Change-Id: I6d6b09a811b82770818f19b189a57d9fc4a8133b
2018-04-09 17:57:15 +02:00
Neels Hofmeyr 975ee6bd44 fsm_test: more thoroughly test FSM inst ids and names
Place id and name testing in its separate section, test_id_api().

Add a test that actually allocates an FSM instance with a NULL id, which is
allowed, but uncovers a bug of an unset FSM instance name. osmo_fsm_inst_name()
falls back to the fsm struct's name on NULL, but osmo_fsm_inst_find_by_name()
fails to match if the instance's name is NULL (and until recently even
crashed). Show this in fsm_test.c with loud comments.

Add test to clear the id by passing NULL.

Add test for setting an empty id.

Add test for setting an invalid identifier (osmo_identifier_valid() == false).

Change-Id: I646ed918576ce196c395dc5f42a1507c52ace2c5
2018-04-09 17:57:15 +02:00
Neels Hofmeyr d8f175cd2a fsm_test: terminate the main loop instead of exit on timeout
In fsm_test.c, we have FSM instance cleanup after the select main loop, but we
exit(0) in the timer cb; hence the final code is never called.

Rather clean up the instance and hence also test that, by using a global flag
to exit the main loop upon timeout.

Adjust expected stderr output.

BTW, in a subsequent commit, I want to move the fsm instance id testing to
below the main loop, to more clearly group the tested bits.

Change-Id: Ia47811ffcc1bd68d2630c86be7ab98fc1f338773
2018-04-09 17:57:15 +02:00
Neels Hofmeyr 04eb56f146 add osmo_quote_str(),osmo_quote_str_buf() and test
Rationale: with osmo_escape_str(), you get the escaped contents of the string,
but not so graceful handling of NULL strings. The caller needs to quote it, and
for NULL strings not quote it.

osmo_quote_str() is like osmo_escape_str() but always quotes a non-NULL string,
and for a NULL string returns a literal NULL, i.e. it should (tm) give the
exact C representation of a string.

That's useful in testing, to show exactly what char* situation we have, without
jumping through hoops like
  if (str)
  	printf("\"%s\"", osmo_escape_str(str, -1));
  else
  	printf("NULL");

Copy the unit test for osmo_escape_str() and adjust. To indicate that the
double quotes are returned by osmo_quote_str(), use single quotes in the test
printf()s.

I considered allowing to pick the quoting characters by further arguments, but
that complicates things: we'd need to escape the quoting characters. Just
hardcode double quotes like C.

Change-Id: I6f1b3709b32c23fc52f70ad9ecc9439c62b02a12
2018-04-09 15:56:14 +00:00
Neels Hofmeyr a829b45c85 use osmo_init_logging2() with proper talloc ctx
Ironically, when deprecating osmo_init_logging() in
I216837780e9405fdaec8059c63d10699c695b360, I forgot to change the callers
within libosmocore itself, i.e. in the various regression tests.

Change-Id: Ia36c248f99353d5baaa2533f46a2f60a8579bdf8
2018-04-06 04:37:50 +02:00