Commit Graph

1894 Commits

Author SHA1 Message Date
Harald Welte 3419391422 fsm: Add VTY introspection of osmo_fsm and their instances
Change-Id: I89212e4f149f019099115a85bab353c04170df90
2017-01-07 12:21:11 +00:00
Harald Welte 8808bb49a2 Add osmo_fsm_find_by_name() and avoid registering FSM with same name
This addresses a FIXME in the fsm.c code: osmo_fsm_register() should
fail in case a FSM with the given name already exists.

Change-Id: I5fd882939859c79581eba70c14cbafd64560b583
2017-01-07 12:20:59 +00:00
Harald Welte addeaa39b1 vty: OSMO_ASSERT() if two identical commands are installed
When the caller installs two identical commands at a given VTY node, the
result is that neither of the two commands can ever be executed: The VTY
would always complain about "Ambiguous command.".  Let's fail fast at
program start when two identical commands are intalled.

Change-Id: I85ff4640ebb3d8b75a6a9ab5d2f668edb5b7189e
2017-01-07 12:14:48 +00:00
Max ecbcdf52ec Add OML Failure Event Report support
Add 3GPP TS 12.21 § 8.8.2 Failure Event Report function which pack given
vararg string and parameters into msgb.

Change-Id: I58c198d8ea588432c62520928b08f0b2a7035e93
Related: OS#1615
2017-01-06 18:05:49 +01:00
Max 07352fee09 Add event cause string descriptions
Add human-readable descriptions to event causes from 3GPP TS 12.21 §
9.4.43.

Change-Id: Id173c978616c98b7831fbafb5401064257f1cf73
Related: OS#1615
2017-01-06 11:37:09 +00:00
Pravin Kumarvel 848de8f1df Add function to get uninterrupted bit run
Function bitvec_rl_curbit added to get number of  uninterrupted
bits run in vector starting from the current bit till max number
of bits.
Test case is added to check bitvec_rl_curbit.

Change-Id: Iae153d3639ea6b891c1fc10d7801a435c9492e26
2017-01-06 10:37:42 +00:00
Minh-Quang Nguyen 592fcc97c0 Add cause enum for OML fail reports
Add 3GPP TS 12.21 §9.4.43 Probable Cause values of type 03 (Manufacturer
specific values).

Max's note: renamed to make it clear that values are vendor-specific.

Related: OS#1615
Change-Id: Ie9ba4b53fb19a151447aec9ea309284e20613585
2017-01-06 10:21:11 +00:00
Max dbd3a92f70 Add parsed TLV helpers from OsmoBTS
Add functions to copy and merge parsed TLV structures from OsmoBTS.

Change-Id: Ieaaaed19da9c069fe451faa53d24c5b84d7d5615
2017-01-06 10:21:11 +00:00
Max 0bee65c0d8 Add OML definitions from OsmoBTS
Change-Id: I9c3bc15662949654e7bba6aad5488c69ee7d0c45
Related: OS#1615
2017-01-06 10:21:11 +00:00
Max edc8db21fa Remove direct logging
Drop perror() calls from GSMTAP code: it's application job to do the
proper logging - library code should not write to stdout/stderr
directly.

Change-Id: Ifa149e65d76c6e64fda2946725c16672233aff2e
2017-01-06 10:12:24 +00:00
Vadim Yanitskiy b1edd16e75 gitignore: ignore tests/oap/oap_test
Change-Id: Iccb8c46a721d5389058c5cf36621820bcd861b7b
2017-01-06 10:08:57 +00:00
Harald Welte 53e2672e11 lapd_test: avoid calling memcpy with NULL source
fixes
lapd/lapd_test.c:54:2: runtime error: null pointer passed as argument 2, which is declared to never be null

Change-Id: I7030729f4f4c867adecc7afc15bb5ca9beff0030
2017-01-06 10:03:30 +00:00
Harald Welte 6cfa56ba0c gprs_cipher_core: Use typecase to avoid sanitizer error
This resolves
gprs_cipher_core.c:118:37: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

Change-Id: Ib1866595030ad9d11c886621ce69632462befa3a
2017-01-06 10:03:30 +00:00
Neels Hofmeyr 3faa014805 fsm: term: get parent pointer as late as possible
During FSM instance termination, fetch the parent pointer every time just
before using it, in case the child termination or cleanup callback wish to
change anything about the parent, e.g. to prevent event dispatch.

This patch was created to try and fix a problem that was in the end solved
differently. There is no actual need or use case for this at the moment, but it
generally makes sense to get the parent pointer as late as possible.

Change-Id: I999d7f29ba10281d4005c5163130bb2d80148362
2016-12-24 18:44:41 +01:00
Vadim Yanitskiy 15492bcb26 utils/conv_gen.py: separate code definitions
This change separates the convolutional code definitions from the code
generator logic, allowing us to make further changes in more specific
way. For example, adding some new codes, you change the conv_codes.py
only because such change isn't related to the generator.

Change-Id: I3428561251b7d7a180d1e9b6fcaad50bdbbc37fa
2016-12-24 17:12:49 +00:00
Vadim Yanitskiy 6431adde78 utils/conv_gen.py: use shared tables if possible
This change introduces the memory usage optimization, mentioned
in d2d9760c08. The aim is to make
code generator able to detect, whether the same tables are used
by several convolutional code definitions, and prevent one from
writing these tables multiple times.

For now, the detection process isn't fully automatic, so all
shared polynomials should be placed inside the 'shared_polys'
dictionary, for example:

shared_polys = {
	"xcch" : [
		( G0, 1 ),
		( G1, 1 ),
	],
	"mcs" : [
		( G4, 1 ),
		( G7, 1 ),
		( G5, 1 ),
	],
}

Change-Id: I84760f5cdfdaece376b801d2e6cb2954ee875a3b
2016-12-24 17:12:49 +00:00
Neels Hofmeyr c014f606d0 fsm: factor out osmo_fsm_inst_term_children() from osmo_fsm_inst_term()
osmo_fsm_inst_term() has code for safe child removal, publish that part as
osmo_fsm_inst_term_children(); also use from osmo_fsm_inst_term().

As with osmo_fsm_inst_term(), add osmo_fsm_inst_term_children() macro to pass
the caller's source file and line to new _osmo_fsm_inst_term_children().

Rationale: in openbsc's VLR, I want to discard child FSMs when certain events
are handled. I could keep a pointer to each one, or simply iterate all
children, making the code a lot simpler in some places.

(Unfortunately, the patch may be displayed subobtimally. This really only moves
the children-loop to a new function, replaces it with a call to
_osmo_fsm_inst_term_children(fi, OSMO_FSM_TERM_PARENT, NULL, file, line) and
drops two local iterator variables. No other code changes are made, even though
the diff may show large removal + addition chunks)

Change-Id: I8dac1206259cbd251660f793ad023aaa1dc705a2
2016-12-24 17:11:52 +00:00
Neels Hofmeyr eeacf906dd fsm: move LOGPFSMSRC and LOGPFSMLSRC to .h
LOGPFSM and LOGPFSML are in the header file, put the *SRC variants also there
so users of the osmo_fsm_inst API may conveniently create own functions that
log the caller's source file and line.

Very useful if many action functions call the same event dispatching function,
like foo_fsm_done(), and one needs to know which of the callers to debug.

Change-Id: I39447b1d15237b28f88d8c5f08d82c764679dc80
2016-12-24 17:11:52 +00:00
Neels Hofmeyr c7155df3ec fsm: log calling file+line for error "event for NULL fi"
Change-Id: I1970773440865f1415004bcf0164603468acf90b
2016-12-24 17:11:52 +00:00
Neels Hofmeyr b805cc1992 fsm: doc: add missing file, line args; fix ws + tweak on one line
Change-Id: I6af0d43ab0082e45df676c1d69b26310b59a8031
2016-12-24 17:11:52 +00:00
Neels Hofmeyr cba8eb9b21 fsm_test.c: fix compiler warning: timer cb return type
Change-Id: Ifd7e85cd69b5e7e473000abc1ef7a56748aafc0e
2016-12-24 17:11:52 +00:00
Harald Welte 1514f34dcf serial.c: file descriptor '0' is a valid value
if stdin/stdout/stderr are all closed by our environment, it may very
well be that opening a serial port returns fd == 0.

Change-Id: Ifd9670260883a35da0629369e0d49e467d5b4d72
2016-12-24 17:59:36 +01:00
Harald Welte d2510459a8 serial.c: Fix fd leak in case of fcntl() error paths
Change-Id: I14f934957e1086b803f3a7b9b5e6d602380f0be2
Fixes: Coverity CID 158987
2016-12-24 17:58:13 +01:00
Harald Welte c68ce3b9fe serial.c: Some ports don't support TIOCMBIS for RTS/CTS control
So let's ignore the error we might get from this opreration.

Change-Id: I69dad90403355b6512c3bf4c7fd10dd1dd985f01
2016-12-23 22:59:27 +01:00
Harald Welte 1db37820aa serial: Open devie in non-blocking mode and then switch to blocking
There are some serial ports that apparently block during the open in
some circumstances.  We don't want that.  We want to either open it
immediately, or fail fast.

Change-Id: I626b138574bc50f4f4b09c4d609f3623ff512dff
2016-12-23 22:50:10 +01:00
Harald Welte a0f74f218b add CRC16-CCITT to libosmocore
Use the implementation from Linux lib/crc-ccitt.c (GPLv2)

Change-Id: I26bb54038f5ab36bbb34da7f5fb8ae6c0c0386a4
2016-12-23 22:16:08 +01:00
Harald Welte 5e5954db8b Fix erroneously AGPL licensed file in libosmocore.
libosmocore itself is GPLv2-or-later.  Only the test cases are permitted
to be AGPL licensed.

Change-Id: I62f2eed6305bfa11a64c6d633e08aabeaf9f0b10
2016-12-22 14:58:58 +01:00
Max 126def7105 Integrate Debian packaging changes
debian/control:
* restructure to make it easier to incorporate further changes
* update package descriptions
* move build-depends to a proper place
* update project URL

debian/rules:
* use proper hardening syntax
* strip linker option without explicit shell invocation
* remove useless comment
* add extra cleanup

debian/: package documentation separately

debian/docs: remove empty file

debian/coryright: update to match Debian format

Change-Id: Ia7654d34730e9f269831612bfba70a1338ce29d3
Related: OS#1694
2016-12-22 13:54:32 +00:00
Neels Hofmeyr 7309e19358 fsm: log tweak: upon free, say 'Freeing instance'
Logging 'Release' is a bit ambiguous. At first I tought a subscriber
connection was being released, IMHO 'Freeing instance' better describes that
we are freeing an osmo_fsm_inst.

Change-Id: I5cf99707d2ba5620b2988f777fa39cc806ec0212
2016-12-21 14:38:18 +01:00
Neels Hofmeyr b6d58e8cc0 doc: fix typo for osmo_hexparse
Change-Id: Ifc2b499792fda378c807c678b8e06630cb64d273
2016-12-21 14:38:18 +01:00
Neels Hofmeyr 18080960e1 utils.h: add OSMO_STRINGIFY and OSMO_VALUE_STRING macros
OSMO_STRINGIFY particularly allows putting port numbers from a #define into VTY
doc strings, like:

  #define FOO_PORT 2342
  DEFUN(...,
        "Foo UDP port (default: " OSMO_STRINGIFY(FOO_PORT) ")\n")

OSMO_VALUE_STRING creates value_string items with the string being exactly the
enum value's name. Replaces a similar macro def in fsm.c

Change-Id: I857af45ae602bb9a647ba26cf8b0d1b23403b54c
2016-12-21 10:37:13 +00:00
Max 4e72ee0d0f Catch-up with git version tags
* update debian/changelog
* update TODO-RELEASE
* add comments to Makefile.am and TODO-RELEASE to simplify the process
  in future
* add link to libtool docs to Makefile.am to simplify LIBVERSION
  maintenance

Related: OS#1861
Change-Id: I22c257e357f597519120232d742d6a61289db021
2016-12-21 10:31:17 +00:00
Neels Hofmeyr 06ac9b40ed fsm: term: safer iteration to remove all child FSMs
When terminating child FSMs, restart iteration after every child, to make
sure that we don't terminate a child twice. Terminating one child may emit
events that in turn terminates other children.

I created this patch because at first it looked like the cause of a bug,
which turned out not to be the case. So I have no actual use case of this
situation, but it does generally make sense to me, so submitting this.

Change-Id: I00990b47e42eeb43707a9a42abcd9df52fe5f483
2016-12-20 12:39:32 +01:00
Neels Hofmeyr 42b59c1bf0 fsm api doc: fix typo in doxygen marker '\breif'
Change-Id: I5c57e35b29d50cb409becada6b9b120ce5210ae0
2016-12-20 12:39:32 +01:00
Neels Hofmeyr 2ae5f18692 fsm: explicitly log removal from parent fsm
Since removing an FSM from its parent twice causes a segfault, it is very
interesting to see when that is attempted.

Removing could be made more robust, but logging is interesting for
investigating why an FSM is being removed twice in the first place (currently
the case in openbsc's vlr_lu_fsm).

Change-Id: Idec6b7aa5344f1e903c9d2aa2a3640cab0d70fb0
2016-12-16 13:39:24 +01:00
Neels Hofmeyr 5c5c78aacd add value strings for enum osmo_fsm_term_cause and use for logging
Change-Id: Iaf63d3cadb0d46bf454e3314ebb439240cafd834
2016-12-15 11:35:56 +01:00
Neels Hofmeyr a3953e0536 typo in comment for osmo_fsm_log_addr()
Change-Id: I6f683ed0c864a87bf1232994eb2deaf9b313a244
2016-12-14 18:34:30 +01:00
Neels Hofmeyr 725698a4f1 fsm: log caller's source for events and state changes, not fsm.c lines
When looking at log output, it is not interesting to see that a state
transition's petty details are implemented in fsm.c. Rather log the *caller's*
source file and line that caused an event, state change and cascading events.

To that end, introduce LOGPSRC() absorbing the guts of LOGP(), to be able to
explicitly pass the source file and line information.

Prepend an underscore to the function names of osmo_fsm_inst_state_chg(),
osmo_fsm_inst_dispatch() and osmo_fsm_inst_term(), and add file and line
arguments to them. Provide the previous names as macros that insert the
caller's __BASE_FILE__ and __LINE__ constants for the new arguments. Hence no
calling code needs to be changed.

In fsm.c, add LOGPFSMSRC to call LOGPSRC, and add LOGPFSMLSRC, and use them in
above _osmo_fsm_inst_* functions.

In addition, in _osmo_fsm_inst_term(), pass the caller's source file and line
on to nested event dispatches, so showing where a cascade originated from.

Change-Id: Iae72aba7bbf99e19dd584ccabea5867210650dcd
2016-12-14 18:00:52 +01:00
Neels Hofmeyr 6a13e7f563 fsm: add LOGPFSML to pass explicit logging level
Provide one central LOGPFSML to print FSM information, take the FSM logging
subsystem from the FSM instance but use an explicitly provided log level
instead of the FSM's default level.

Use to replace some, essentially, duplications of the LOGPFSM macro.

In effect, the fsm_test's expected error changes, since the previous code dup
for logging events used round braces to indicate the fi's state, while the
central macro uses curly braces.

Change-Id: If295fdabb3f31a0fd9490d1e0df57794c75ae547
2016-12-14 17:56:48 +01:00
Neels Hofmeyr 886d6fdec6 fix logging: log_set_category_filter() for internal DL* logging cats
In log_set_category_filter(), passing a negative index lead to memory
corruption. Particularly dangerous since the internal logging categories have
negative values.

Fix: apply map_subsys() to interpret negative values as internal logging
categories.

As a side effect, out-of-bounds logging categories will be mapped to DLGLOBAL
instead of being dropped.

Fix the expectations in logging_test to match the fixed bug.

While at it also guard against a NULL logging target.

Change-Id: Ib0725b22bc39498c6b3970a61eb3339cf56d19f1
2016-12-12 16:56:54 +01:00
Neels Hofmeyr a4842afc83 show bug in logging: log_set_category_filter on DL* categories
Add a check to logging_test.c to show a bug: passing an internal DL* category
constant to log_set_category_filter() results in a negative array index and
undefined behavior. A sanitize build should catch this.

The bug is confirmed by the fact that logging_test.err stays the same
(hopefully) although a logging output should appear from this patch. The test
could as well segfault or anything else, it's a bit of a gamble.

This bug will be fixed along with the expectation in a subsequent patch.

Change-Id: Ie2da77c642a84cafc0f528985930697ec167183b
2016-12-12 16:56:54 +01:00
Neels Hofmeyr 748022694c fix logging: out-of-bounds check should end with user categories
To check category bounds, rather use num_cat_user, to redirect all semantically
unknown categories to DLGLOBAL.

Adjust logging_test expectations accordingly: "(d)" is now also shown.

Note: subsys is and needs to be signed, while num_cat* are unsigned. Thus for a
negative subsys, 'subsys >= num_cat_user' practically always yields true. Pay
close attention to signedness and check upper bound only for positive values.

Change-Id: I4a952b759f30d90fbfb81fedcfc56a8092ea18c1
2016-12-12 16:56:50 +01:00
Neels Hofmeyr d1a145e5e7 show bug in logging: out-of-bounds check should end with user categories
In the background osmo_log_info array, the user's logging categories are
enhanced by the library internal ones. So far logging category range checking
only checked for the larger array bounds, although passing a logging category
>= num_cat_user is already semantically unknown and should redirect to
DLGLOBAL.

Add a check to logging_test.c to show that this isn't happening. Instead of
DLGLOBAL, a logging category that happens to be at that index is queried.

The bug is confirmed by logging_test.err only showing "(e)" and not "(d)":
"(e)" is shown because the first category after the user ones happens to be
DLGLOBAL. "(d)" is omitted since it hits a category that's not on debug level.

This bug will be fixed along with the expectation in a subsequent patch.

Change-Id: I397278714018ee9a0ae5101515f31ddddf79c2ec
2016-12-12 16:09:14 +01:00
Neels Hofmeyr ca13574ba4 fix logging: also catch first out-of-bounds logging cat
In map_subsys(), fix the '>' condition to '>=' for array bounds checking.

Also make the bounds checking more strict: after both invocations of
subsys_lib2index(), re-check validity of the array index. If the final index is
still wrong, which should never happen, exit by assertion.

Change-Id: I7ca1a1d47724e40350f1c4dfebe90bad01c965f9
2016-12-12 15:48:08 +01:00
Neels Hofmeyr a280b82f8e show bug in logging: erratic redirection to DLGLOBAL for first invalid category
Add a check to logging_test.c to show a bug: when a logging category value that
is the first out-of-bounds value is passed to the logging system, the internal
map_subsys() fails to redirect to DLGLOBAL due to a flawed conditional. This
results in a too large array index and undefined behavior. A sanitize build
should catch this.

The bug is confirmed by the fact that logging_test.err stays the same
(hopefully) although a logging output should appear from this patch. The test
could as well segfault or anything else, it's a bit of a gamble.

This bug will be fixed along with the expectation in a subsequent patch.

Change-Id: I12bf38b6c1f85e2d7bf5a15f942dfe0beed41eba
2016-12-12 15:47:51 +01:00
Neels Hofmeyr 42240de04c fix logging: redirection to DLGLOBAL for invalid categories
For out-of-bounds logging categories, redirect to the proper DLGLOBAL array
index instead of returning -1.

Adjust test expectation which shows that the bugs tested for are fixed.

Note: there are separate bounds checking problems, left for another patch.

Change-Id: I6ea9a59e005a22e0305454291714fdb9531c346b
2016-12-12 15:47:37 +01:00
Neels Hofmeyr 85b42c4618 show bug in logging: erratic redirection to DLGLOBAL for invalid categories
Add a check to logging_test.c to show a bug: when a logging category value that
is out-of-bounds is passed to the logging system, the internal map_subsys()
function should remap that to DLGLOBAL. But in fact DLGLOBAL is -1 and the
function fails to map this to a proper positive array index, directly returning
-1 instead. This results in a negative array index and undefined behavior. A
sanitize build should catch this.

The bug is confirmed by the fact that logging_test.err stays the same
(hopefully) although a logging output should appear from this patch. The test
could as well segfault or anything else, it's a bit of a gamble.

This bug will be fixed along with the expectation in a subsequent patch.

Note: osmo_log_info->num_cat + 0 is also out-of-bounds, but there is a separate
bug there, so leaving this for another patch.

Change-Id: I161b6550fa204a872bad1abefee1a6155393fafd
2016-12-12 15:47:32 +01:00
Neels Hofmeyr 9adf32fb60 logging test: cosmetic: print target and don't print color
Prepares for upcoming modifications of the logging test to show and fix bugs in
the logging system.

Change-Id: I9461b987adf85d87469a6af55de5f1aa478f6ebb
2016-12-12 14:24:39 +01:00
Neels Hofmeyr 3cc757df18 doc: osmocom-authn-protocol.txt: fix numbering, mark unused sync msgs
Change-Id: Ic1ec5d00de406f9581377ef4b5547782a80f368a
2016-12-11 03:42:58 +01:00
Neels Hofmeyr d981efa976 oap: add encode/decode unit test
Change-Id: I0e14099e2fc18e333a73d38bda059d53a8ca9944
2016-12-11 03:42:58 +01:00