Commit Graph

64 Commits

Author SHA1 Message Date
Vadim Yanitskiy a08edff80c Revert "fsm.c: Print error message for FSM with allstate_action but no events"
This reverts commit b3f94eb39e, that
unfortunately breaks some projects which call osmo_fsm_register()
on DSO load (i.e. using __attribute__((constructor))) before the
logging is initialized.

Change-Id: Idc6fcce7e946c23d48589b920e309d60aa7b6645
2019-06-16 01:04:15 +07:00
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
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 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
Kevin Redon c9a28a67e6 fix typo in FSM description
Change-Id: I3559e9c0769b708cee0d1b221b60960c62f15bd4
2019-05-09 18:31:13 +02: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 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 2f65bb1b01 Doxygen: fix incorrect / missing parameter description
Change-Id: Ibc63a5d4442a192efab8b5b30e0beb3545642ecc
2019-03-25 15:57:09 +07: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 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
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 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
Philipp Maier af6710f4d4 fsm: fix apidoc of osmo_fsm_state_name()
The api documentation of osmo_fsm_state_name() refers to an FSM
instance, but it really means the state of an FSM.

Change-Id: I88ddd6048426d380c49170e66f57b3843398c046
2018-11-16 17:45:40 +01:00
Neels Hofmeyr 407df02e7c add osmo_fsm_inst_state_chg_keep_timer()
Change-Id: I3c0e53b846b2208bd201ace99777f2286ea39ae8
2018-05-31 21:01:33 +00:00
Philipp Maier 3d4fb59329 fsm: guard action callback
The FSM allows to set individual action callback functions for each
state but it does not allow to leave the action callback pointer
unpopulated. However, there are cornercases where having no callback
function is desirable.

- Check if action callback is popolated before executing it.

Change-Id: I36d221c973d3890721ef1d376fb9be82c4311378
2018-05-15 10:06:22 +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 2bcc873e93 osmo_fsm_inst_find_by_name(): guard against strcmp(NULL)
strcmp() *must not* be passed NULL pointers, or we hit:

../../../src/libosmocore/src/fsm.c:123:8: runtime error: null pointer passed as argument 2, which is declared to never be null
ASAN:DEADLYSIGNAL

(Or, alternatively, a segfault.)

If any of the search string or an FSM instance's name string should be NULL,
simply never match.

Technically, an FSM should never have a NULL name, but a current bug actually
allows this (pass NULL id to alloc), which will be addressed by an upcoming
patch. To test for it, we need to first make sure this here doesn't segfault.

Change-Id: I2e5f82c06d1a4727bd93e955366e3b62b2df1b32
2018-04-09 17:57:15 +02:00
Daniel Willmann 04a2a3231f fsm: Update the name as well if the id is updated and accept NULL
If the name stays the same the log messages will still log with the old
id. Since we can now change the id we need to update the name as well.

NULL as id was allowed before so we should allow that as well.

Change-Id: I6b01eb10b8a05fee3e4a5cdefdcf3ce9f79545b4
2018-03-19 20:28:11 +00:00
Stefan Sperling 888dc7d31a print BIG FAT ERROR message if osmo_fsm lacks event names
Event names are displayed in VTY commands so all FSM should have them.
Print an error message if an FSM is registered without event names.
We could also return an error code, however at present no caller checks
the return value of osmo_fsm_register() so this would be pointless.

Add event names to the test FSM and update expected output accordingly.

Change-Id: I08b100d62b5c50bf025ef87d31ea39072539cf37
Related: OS#3008
2018-02-26 19:00:23 +00:00
Philipp Maier d1f5793b5e fsm: allow graceful exit on FSM termination
The function _osmo_fsm_inst_term() terminates all child FSMs befor
it calls fi->fsm_cleanup(). This prevents the cleanup callback to
perform last actions on the child FSMs (e.g.
osmo_fsm_inst_unlink_parent()).

- Since moving the cleanup callack to the beginning of the function
  would alter the termination behavior and possibly cause malfunction
  in already existing implementation that use OSMO fsm, a new
  optional callback that is called immediately at the beginning of
  the terminatopn process is added.

Change-Id: I0fdda9fe994753f975a658c0f3fb3615949cc8bb
Closes: OS#2915
2018-02-19 08:30:21 +00:00
Daniel Willmann b0c43a6063 fsm: Add a function to change the FSM instance ID later
Sometimes we want to create an FSM instance before we know its name. In
that case we should be able to update the id later.

Change-Id: Ic216e5b11d4440f8e106a297714f4f06c1152945
2018-02-15 18:03:58 +00:00
Harald Welte 6590044337 Revert "fsm: do not terminate child FSMs early"
This reverts commit 5ec91980ac.

More or less like I expected, it creates fall-out.  osmo-msc master builds are failing, as are the open build service builds.  The patch has therefor *not* been sufficiently tested.

Change-Id: I8d961d7bbd91b6a8d7691f24cb67720c3d001c7e
2018-02-09 10:01:31 +00:00
Philipp Maier 5ec91980ac fsm: do not terminate child FSMs early
The function _osmo_fsm_inst_term() terminates all child FSMs befor
it calls fi->fsm_cleanup(). This prevnts the cleanup callback to
perform last actions on the child FSMs (e.g.
osmo_fsm_inst_unlink_parent()).

move the function call to  _osmo_fsm_inst_term_children() below the
call to fi->fsm->cleanup().

Change-Id: Ie89d435417306c6bf897274eabc3ed0a46485c26
2018-02-09 02:25:58 +00:00
Philipp Maier 2a06a491b1 fsm: add functions for unlinking and changing parents
At the moment it is not possible to unlink a child from from
its parent, nor is it possible to assign a new parent to a
child FSM.

- osmo_fsm_inst_unlink_parent():
  Make it possible to unlink childs from a parent.

- osmo_fsm_inst_change_parent():
  Make it possible to change the parent of a child.

Change-Id: I6d18cbd4ada903cf3720b3ad2a89fc643085beef
2018-01-24 12:03:28 +01:00
Philipp Maier 23d3161d4b fsm: fix double llist_del in osmo_fsm_inst_term()
llist_del(&fi->proc.child) is executed always, regardless whether
a parent is configured or not. This may lead into a double llist_del
when the child has been previously unlinked.

- check if fi->proc.parent is set, and only then execute
  llist_del(&fi->proc.child);

Change-Id: I4b33d508c8a11b72fbf30125088a882894d9e6ac
2018-01-17 13:33:27 +00:00
Neels Hofmeyr 19ec7b9483 fsm_tmr_cb: don't set T=0, the fi may no longer exist
When calling the timer_cb, that may have effected an fi termination and
deallocation, e.g. from dispatching events and/or complex choices made.

Current timer_cb implementations expect T to reflect the fired timer number, so
we can't actually set T=0 before calling the timer_cb.

Instead, never reset T to zero, let it always reflect the timer that last
fired. When a new timer starts, T will be set to its new value.

Adding a T arg to the timer_cb() would have been the cleanest solution, so that
fi->T can be set to zero before dispatching the timer_cb. But since we've
already rolled out this FSM API, we should stay backwards compatible.

In the case where the timer returned 1 to request termination, we can assume
that the fi still exists, but to be consistent, don't set T = 0 in that code
path either.

Change-Id: I18626b55a1491098b3ed602df1b331f08d25625a
2017-11-25 17:45:04 +00:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Harald Welte 8c4f5457aa fsm: Enforce FSM and FSM instance names are valid osmocom identifiers
Let's enforce that the names of FSMs and their instances are valid
osmocom identifiers.  This is important as the FSMs are automatically
exported via those names on the CTRL inteface, and we have to make sure
CTRL syntax actually permits them.

Change-Id: I9ef59432f43a3cdb94e4cbb0c44ac3f9b2aac0f2
2017-10-24 16:00:45 +00:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Neels Hofmeyr 87e4550585 doxygen: enable AUTOBRIEF, drop \brief
Especially for short descriptions, it is annoying to have to type \brief for
every single API doc.

Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes
the first sentence of an API doc as the brief description.

Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-06-23 00:18:22 +00:00
Pau Espin 4f8857e50a fsm.c: Fix compilation warning: Use PRIu32 for uint32_t
Change-Id: I4c441b20b250c34656f1e8330d6bb4b1ce2b8423
2017-06-22 18:14:18 +00:00
Harald Welte 96e2a00d7a update/extend doxygen documentation
It's a pity that even with this patch we still are fare away from having
the whole API documented.  However, at least we have a more solid
foundation.  Updates not only extend the documentation, but also make
sure it is rendered properly in the doxygen HTML.

Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
2017-06-12 21:55:54 +00:00
Pablo Neira Ayuso 44f423f117 timer: add osmo_timer_setup()
Add a new function timer function to set up the timer, similar to what
we have in the Linux kernel. This patch also converts existing opencoded
timer setup in the libosmocore tree as initial client of this new
function.

This patch implicitly removes function callback passed by reference that
defeat compile time type validation.

Compile-tested only, but I ran make check that reports success when
testing timer infrastructure.

Change-Id: I2fa49972ecaab3748b25168b26d92034e9145666
2017-05-09 12:10:51 +02:00
Harald Welte 9e83c3d5ca fsm: Re-set fsm_inst->T to 0 after timer expiration
If the user starts the FSM timer with a given timer number during
fsm_inst_state_chg() with a timeout, we should remove that "T" number
after timer expiration.  Otherwise it might be confusing if e.g. the VTY
interface shows FSM instances with a certain timer number assigned, but
that timer is not actually running anymore.

Change-Id: I71167ec1000dc4c6954d851d3b92f6bf12984925
2017-04-16 17:28:23 +02:00
Harald Welte 4585e6755d osmo_fsm: Lookup functions to find FSM Instance by name or ID
Introduce two lookup helper functions to resolve a fsm_instance based on
the FSM and name or ID.  Also, add related test cases.

Change-Id: I707f3ed2795c28a924e64adc612d378c21baa815
2017-04-16 17:28:23 +02:00
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
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
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 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 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