summaryrefslogtreecommitdiffstats
path: root/include/osmocom/core
Commit message (Collapse)AuthorAgeFilesLines
* fsm: convenience: add inline osmo_fsm_inst_state_name()Neels Hofmeyr2017-03-011-0/+4
| | | | Change-Id: If9a6ecc4d6e2beaf716569e9a6053d73488e860b
* logging.h: fixup: shorter names for LOGGING_FILTER_* and LOGGING_CTX_*Neels Hofmeyr2017-02-231-16/+18
| | | | | | | | | | | | | | | My recent logging patch was merged to master a bit too soon. Accomodate the request for naming that matches the general "LOG" prefix instead of "LOGGING". libosmocore will not be backwards-compatible with the few commits from change-id I5c343630020f4b108099696fd96c2111614c8067 up to this one. This and following commits are backwards compatible with those before that short window. See also: * openbsc change-id Ib2ec5e4884aa90f48051ee2f832af557aa525991 * osmo-pcu change-id I4db4a668f2be07f3d55f848d38d1b490d8a7a685 Change-Id: I424fe3f12ea620338902b2bb8230544bde3f1a93
* logging.h: fixup: add API doc for logging enums recently addedNeels Hofmeyr2017-02-231-0/+5
| | | | Change-Id: Ic459b04219abe70171c8f80ed09df53d412dcfb2
* logging.h: fix backwards compat broken by recent commitNeels Hofmeyr2017-02-231-0/+7
| | | | | | | | | | | | | | Commit 812ba6dc63a75c39678dd3fe652768e76bf63183 "logging: centrally define ctx and filter indexes" Removed definitions, which causes older e.g. openbsc and osmo-pcu code trees to fail to build against a newer libosmocore. Re-introduce the legacy definitions to redirect to the new ones and re-establish backwards compatibility. The GPRS_* constants used to be defined in gprs_msgb.h, but since that header also includes logging.h, rather place the legacy shims in logging.h next to the other ones. Change-Id: I455bb1bb474d758af0fd5b6397f7e57260ad739d
* logging: centrally define ctx and filter indexesNeels Hofmeyr2017-02-221-2/+17
| | | | | | | | | | | | | | | | | | | | | | | It is too easy for calling code to use the same filter and context indexes for different filters and structs. For example, openbsc's IMSI filter and libgb's GPRS_BVC filter both fall on index 1 even though there are plenty more indexes to choose from. To alleviate this, have one central definition here, sort of like ports.h does for VTY and CTRL port numbers. Add static asserts to make sure the indexes fit in the available array and bit mask space. Calling code like openbsc.git and osmo-pcu need adjustments and/or should move to using these enum values instead of their local definitions. Taking this opportunity to also prepare for a split of struct gsm_subscriber in openbsc into bsc_subsciber and vlr_subscriber with appropriate separate filter index constants for both subscriber types. Include previous LOG_FILTER_ALL in the LOGGING_FILTER_* enum, and replace its use by (1 << LOGGING_FILTER_ALL). Change-Id: I5c343630020f4b108099696fd96c2111614c8067
* select: add functionality to check socket statePhilipp Maier2017-02-071-0/+2
| | | | | | | | | | | | osmo_fd_register() is used to register socket file descriptors, after registering a socket, there is no way to test if the socket is still registered or actually registered at all. This commit adds a new function osmo_fd_register_check() that can be used to check in advance, if the socket fd is registered, before performing further operations. Change-Id: I48ec7098d6bba586c81bf0d5c9088108e2c081c6
* socket: Introduce function to obtain socket nameHarald Welte2017-01-271-0/+2
| | | | | | | Using this function, one can obtain a human-readable string identifying the host and port names of the socket. Change-Id: Ib5de5c7b9effe1b0a363e4473a7be7fa38ca6ef3
* utils.h: #include <stdio.h> as we use fprintf()Harald Welte2017-01-231-0/+1
| | | | Change-Id: I911c7f4bcadde414ce0b384e13a3a9a4a953e2fb
* linuxlist.h: add llist_count()Neels Hofmeyr2017-01-211-0/+16
| | | | | | | | | | | | | | | After subchan_demux.c in libosmo-abis, osmo-bts/common/vty.c and openbsc's gtphub_test.c, more places would like to count the llist items (mostly unit tests). Instead of proliferating numerous local implementations, add here. NOTE: other than the previous llist_len() implementations, this one returns an *unsigned* length, which might need some adjusting of current callers. Call this llist_count() rather than llist_len() to highlight the fact that this is actively iterating. This also avoids a potential naming conflict when library versions mismatch. Change-Id: Ic49adc7a346f5722bf624d7d3b4a735e4220ae15
* logging: remove code duplicationMax2017-01-161-13/+4
| | | | | | | | * make DEBUGP* macro into simple wrappers around LOGP* * deprecate unused logp() function Related: OS#71 Change-Id: Ia6c92bd4824c44fc22cc733ce7a88da86e58ed93
* bitvec: Ensure bitvec.h and bitvec.c agree on function argument typeHarald Welte2017-01-151-1/+1
| | | | | | uint32_t may or may not be unsigned int. Change-Id: I21c96985fcbb72372b6df949301c21f1ebca41f2
* Always include <osmocom/core/talloc.h> and not <talloc.h>Harald Welte2017-01-151-1/+1
| | | | | | In EMBEDDED builds we don't have a system-wide talloc Change-Id: Icc526016bda45b36e584afee8669996752d6d89c
* gsmtap: Add GSMTAP_TYPE_QC_DIAGHarald Welte2017-01-091-0/+1
| | | | | | | This adds a definition for wrapping Qualcomm DIAG frames into GSMTAP for transporting them over an IP network. Change-Id: I1b357b7d11a370685671c7b01e55f4f36dec2f25
* Add osmo_fsm_find_by_name() and avoid registering FSM with same nameHarald Welte2017-01-071-0/+1
| | | | | | | 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
* Add function to get uninterrupted bit runPravin Kumarvel2017-01-061-0/+1
| | | | | | | | | 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
* fsm: factor out osmo_fsm_inst_term_children() from osmo_fsm_inst_term()Neels Hofmeyr2016-12-241-0/+13
| | | | | | | | | | | | | | | | | | | | 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
* fsm: move LOGPFSMSRC and LOGPFSMLSRC to .hNeels Hofmeyr2016-12-241-0/+13
| | | | | | | | | | | 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
* add CRC16-CCITT to libosmocoreHarald Welte2016-12-231-0/+12
| | | | | | Use the implementation from Linux lib/crc-ccitt.c (GPLv2) Change-Id: I26bb54038f5ab36bbb34da7f5fb8ae6c0c0386a4
* utils.h: add OSMO_STRINGIFY and OSMO_VALUE_STRING macrosNeels Hofmeyr2016-12-211-0/+4
| | | | | | | | | | | | | | 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
* fsm api doc: fix typo in doxygen marker '\breif'Neels Hofmeyr2016-12-201-1/+1
| | | | Change-Id: I5c57e35b29d50cb409becada6b9b120ce5210ae0
* add value strings for enum osmo_fsm_term_cause and use for loggingNeels Hofmeyr2016-12-151-0/+7
| | | | Change-Id: Iaf63d3cadb0d46bf454e3314ebb439240cafd834
* fsm: log caller's source for events and state changes, not fsm.c linesNeels Hofmeyr2016-12-142-10/+58
| | | | | | | | | | | | | | | | | | | | | | | 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
* fsm: add LOGPFSML to pass explicit logging levelNeels Hofmeyr2016-12-141-2/+5
| | | | | | | | | | | | | | 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
* import oap message parsing / encoding from openbsc.git; AGPL->GPLHarald Welte2016-12-111-1/+2
| | | | | | | | | | | | | | | | | | | In the process, also: * Change the license from AGPLv3 to GPLv2-or-later; * correct spelling of 'sysmocom' to lowercase; * add '2016' to the copyright; * rename to osmo_*; * add API docs; * add logging category DLOAP: define id and add to internal_cat; * redirect all oap.c logging to DLOAP. A unit test will follow in a subsequent patch, since it needs a minor tweak for decoding of boolean values. The related openbsc change-id is I2f06aaa6eb54eafa860cfed8e72e41d82ff1c4cf. Tweaked-by: Neels Hofmeyr Change-Id: If5099e60681a215e798b6675f21813f26769c253
* fix: DLGSUP logging category "unusable"Neels Hofmeyr2016-12-111-1/+1
| | | | | | | | | | | | | | | | | | | All DL* categories are typically negative, but DLGSUP isn't, and it's also not in libosmocore's internal_cat array. See: 3b6fb0880c3ab1e23a3d7d738d073b00c2a794c2 This means that a program using DLGSUP has to include DLGSUP in its own logging cat array (typically not needed for DL* categories), which means for osmo-nitb that DLGSUP (11) replaces DMGCP (also 11), and DMGCP becomes unusable. Fix this: make DLGSUP -11 and include in internal_cat. In gsup_test.c, no longer add DLGSUP to the logging categories array. External follow-ups are otherwise needed only in osmo-hlr.git and some pending patches for openbsc (Id3938267fa062e1a997d3704cd678874306f86ee). Change-Id: Id974c7be158e4d60421a98110f5c807aefd31119
* Implement GSMTAP log targetHarald Welte2016-12-091-0/+14
| | | | | | | This target wraps the to-be-logged string (With metadata) into a GSMTAP packet and sends it to the configured destination address. Change-Id: I9a7e72b8c9c6f6f2d76d1ea2332dcdee12394625
* gsmtap: Add defintions for GSMTAP based remote loggingHarald Welte2016-12-091-0/+19
| | | | | | | | | | | Often it is useful to have log statements from the osmocom programs synchronized with protocol traces. So rather than having to open the pcap file with GSMTAP or other protocol data side-by-side with the textual log of one or more network elements, we simply pass the log lines around as GSMTAP messages, which can then be displayed in-order and interspersed with the protocol messages inside wireshark. Change-Id: I33ab530e10ef0311b6f80b731e61894f20b4b3e7
* doc: fsm timer_cb: explain return valueNeels Hofmeyr2016-12-091-1/+2
| | | | Change-Id: Ic6fbe95737862ed8b8de78058989c8b2ae330006
* logging: Extend log_target with call-back for un-formatted log lineHarald Welte2016-12-021-1/+17
| | | | | | | | | | | Some targets might not want to receive only an opaque, pre-formatted string, but rather the unformatted arguments with metadata like sub-system/level/file/line. We solve this by introducing a log_target->output_raw() function pointer. If a target specifies this function, it takes precedence over the regular log_target->output() function. Change-Id: I9dc9205d70dce9581458e7e9dc2d8a92991897bd
* Introduce osmo_strlcpy() function so we can stop using strncpy()Harald Welte2016-11-261-0/+2
| | | | | | | | | | | | | | | | I'm aware of the existing criticism on stlrcpy(), but I think it is still better than what we have now: stnrcpy(), sometimes with Coverity warnings and sometimes with a manual setting of the termination byte. The implementation follows the linux kernel strlcpy() which is claimed to be BSD compatible. We could of course link against libbsd on Linux instead, but I think it's reasonably small and simple to provide our own implementation. Future versions of libosmocore could use some autoconf magic and preprocessor macros to use the system-provided strlcpy() if it exists. Change-Id: Ifdc99b0e3b8631f1e771e58acaf9efb00a9cd493
* msgb: add msgb_push_u{8,16,32}() functionsHarald Welte2016-11-111-0/+30
| | | | | | | Those work analoguous to msgb_put_*() but pre-pend the given value into the msg headroom, rather than appending it to the end. Change-Id: I7de63e9d04c2d2b678f1f20eef37f9be2c4f5ec2
* statsd: Fix compiler warning (int32_t vs. int64_t)Harald Welte2016-11-111-1/+1
| | | | | | | | | Fixes the following compiler warning: stats_statsd.c: In function ‘osmo_stats_reporter_create_statsd’: stats_statsd.c:54:18: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] srep->send_item = osmo_stats_reporter_statsd_send_item; Change-Id: Id36914906e0982f6ac092a311210727de66b343a
* bitcomp: Remove the t4 decoding from libosmocoreHolger Hans Peter Freyther2016-11-101-1/+0
| | | | | | | | | | | | As outlined by mail on the 13th of July the tree based approach to decoding in the PCU is faster by order of magnitude. Instead of having a slow implementation in the library and a quick one in the PCU, let's only have a quick one in the PCU and at some point in the future move it to libosmocore. Execute the plan and remove t4_decode. Change-Id: I021424444625a097560d086c217c81eac4a5ee44
* Add osmo_fsm_unregister() to headerMax2016-11-021-1/+1
| | | | | | | Previously function was defined but not exposed so there were a way to register FSM but no way to unregister it. Change-Id: I2e749d896009784b77d6d5952fcc38e1c131db2b
* msgb: add msgb_talloc_ctx_init(), deprecate msgb_set_talloc_ctx()Neels Hofmeyr2016-09-271-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | So far each and every main() scope creates a msgb talloc context and either passes it to msgb_set_talloc_ctx() or sets tall_msgb_ctx directly (by defining it extern first). Remove some code duplication: add one central function that creates the "msgb" talloc context for all. Most users of msgb employ a talloc_named_const(), but osmo-bts uses a talloc_pool() instead. Offer both ways by means of the pool_size argument, and for both ways make sure the context is called "msgb". Suggest that msgb users should move to this new function: deprecate msgb_set_talloc_ctx(). To be able to do so, include core/defs.h in msgb.h. There's a tradeoff between hiding the msgb talloc context behind API that tries to guess all use cases versus avoiding code dup. This patch opts against code dup and boldly assumes that all future use is covered. Also, the new function suggests to not access tall_msgb_ctx directly, which can be considered a style improvement. It seems that not all main scopes that use msgb actually initialize the msgb ctx. As a fallback for these, explicitly initialize tall_msgb_ctx to NULL. Change-Id: I747fbbf977c4d2c868c8dead64cfc5fd86eb8d4c
* add osmo_gettimeofday as a shim around gettimeofdayNeels Hofmeyr2016-09-221-0/+11
| | | | | | | This allows feeding a custom time for unit tests by overriding osmo_gettimeofday. Change-Id: Ic7a81a6eb51f27fe452962b91f2eae2070d87089
* fix error msg: msgb_put(): say "msgb_put", not "msgb_push"Neels Hofmeyr2016-09-091-1/+1
| | | | Change-Id: I72f31ebad693f98eb088a99b83aeb10cf9acc29e
* core/counter: add osmo_counter_dec()Alexander Couzens2016-08-301-0/+6
| | | | Change-Id: I030140a45afa295c3ebc4d3ccaffd437b984f515
* Mark input string to osmo_talloc_replace_string() as constHarald Welte2016-07-281-1/+1
| | | | | | | This allows us to pass in strings that are 'const', which for the source of a copy should be the normal/regular case anyway. Change-Id: Icee6a5f88babd3a4e30bf0886f0f8d3b865d80ce
* Mark input parameter to bitvec_set_bits() as 'const'Harald Welte2016-06-271-1/+1
| | | | | | | The input data is accessed in a read-only manner, so it should be marked with the const qualifier. Change-Id: I0d6b86289fa647594f3da1f1c0e0168685307a37
* fsm: Introduce default time-out handlingHarald Welte2016-06-271-1/+3
| | | | | | | | | | | If a FSM doesn't specify any timer_cb, simply terminate the FSM by default on time-out. This is a reasonable default for most cases, and avoids copy+pasting a one-line timer_cb function in every FSM. Also, even if there is a timer_cb, let it have a return value to decide if the core should terminate after return from timer_cb or not. Change-Id: I0461a9593bfb729c82b7d1d1cf9f30b1079d0212
* Add octet-aligned/unaligned shift functionsMax2016-06-201-0/+5
| | | | | | | | | The actual code is from OsmoBTS' tch.c by Harald Welte. Add unit tests, doxygen annotation and extra memory safety check. Those functions are used in several BTS implementations but seems generic enough to be generally useful. Change-Id: I2b1901c4161e8035f059585901dca593b661556d
* Add Finite State Machine abstraction codeHarald Welte2016-06-161-0/+135
| | | | | | | | | | This code is supposed to formalize some of the state machine handling in Osmocom code. Change-Id: I0b0965a912598c1f6b84042a99fea9d522642466 Reviewed-on: https://gerrit.osmocom.org/163 Tested-by: Jenkins Builder Reviewed-by: Harald Welte <laforge@gnumonks.org>
* add get_value_string_or_null() to handle unknown itemsNeels Hofmeyr2016-06-131-0/+2
| | | | | | | | | | | | | | | | | Add get_value_string_or_null() to return NULL in case the given value is not found in the list of strings, to be able to cleanly fall back to another list of strings. Absorb the lookup loop from get_value_string(). Context: in osmo-bts, I want to look up an RSL message name in rsl_msgt_names and fall back to rsl_ipac_msgt_names if not found, because the IPAC PDCH ACT and DEACT messages are sent in a standard ABIS_RSL_MDISC_DED_CHAN. In a subsequent commit, get_value_string_or_null() will be used by new rsl_or_ipac_msg_name(). Change-Id: I1fa3907e28d528d2758bc3eae9d19e6c1168f5e5 Reviewed-on: https://gerrit.osmocom.org/230 Reviewed-by: Harald Welte <laforge@gnumonks.org> Tested-by: Jenkins Builder
* Fixing build on Mac OSXBeshr Al Nahas2016-05-281-1/+1
| | | | | | | | | Fix minor syntax error Change-Id: I67f9a1e41fa5b1da3a4b10fc76138e153b767241 Reviewed-on: https://gerrit.osmocom.org/125 Tested-by: Jenkins Builder Reviewed-by: Holger Freyther <holger@freyther.de>
* Fix build for OSXArran Cudbard-Bell2016-05-201-0/+11
| | | | | | | Change-Id: I580a500edcf4812e570be586890abef746083a8c Reviewed-on: https://gerrit.osmocom.org/74 Tested-by: Jenkins Builder Reviewed-by: Holger Freyther <holger@freyther.de>
* logging: Use __BASE_FILE__ instead of __FILE__Harald Welte2016-05-122-5/+5
| | | | | | | | | | | | | | Apparently __FILE__ expands to nasty '../../..' paths when BUILDDIR != SRCDIR. This in turn leads to ugly log lines like: <0000> ../../../../osmo-bts/src/common/rsl.c:1642 (bts=0,trx=0,ts=0,ss=0) Handing RLL msg UNIT_DATA_IND from LAPDm to MEAS REP Where we certainly wouldn't want the "../../../../osmo-bts" part. Change-Id: If6d2de33c3b6bb2943954bbd81eff261dc279d58 Reviewed-on: https://gerrit.osmocom.org/38 Tested-by: Jenkins Builder Reviewed-by: Harald Welte <laforge@gnumonks.org>
* import gprs_gsup_message.[ch] from openbsc as gsup.[ch]Harald Welte2016-05-061-1/+2
| | | | | | | Move those routines from OpenBSC to libosmogsm, so they can be re-used from other programs. I think it was a mistake to add them only inside the openbsc repository in the first place. We need to pay more attention to this in the future.
* Import osmo_{encode,decode}_big_endian() from openbscHarald Welte2016-05-051-0/+4
|
* Update doxygen annotations in libosmocoreHarald Welte2016-05-059-139/+162
| | | | | This adds and improves doxygen API descriptions all over libosmocore, reducing the 'white spots' that don't have any documentation.