summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* fsm_test.c: fix compiler warning: timer cb return typeNeels Hofmeyr2016-12-241-1/+1
| | | | Change-Id: Ifd7e85cd69b5e7e473000abc1ef7a56748aafc0e
* serial.c: file descriptor '0' is a valid valueHarald Welte2016-12-241-2/+2
| | | | | | | 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
* serial.c: Fix fd leak in case of fcntl() error pathsHarald Welte2016-12-241-2/+4
| | | | | Change-Id: I14f934957e1086b803f3a7b9b5e6d602380f0be2 Fixes: Coverity CID 158987
* serial.c: Some ports don't support TIOCMBIS for RTS/CTS controlHarald Welte2016-12-231-2/+2
| | | | | | So let's ignore the error we might get from this opreration. Change-Id: I69dad90403355b6512c3bf4c7fd10dd1dd985f01
* serial: Open devie in non-blocking mode and then switch to blockingHarald Welte2016-12-231-3/+17
| | | | | | | | 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
* add CRC16-CCITT to libosmocoreHarald Welte2016-12-232-0/+54
| | | | | | Use the implementation from Linux lib/crc-ccitt.c (GPLv2) Change-Id: I26bb54038f5ab36bbb34da7f5fb8ae6c0c0386a4
* Fix erroneously AGPL licensed file in libosmocore.Harald Welte2016-12-221-4/+4
| | | | | | | libosmocore itself is GPLv2-or-later. Only the test cases are permitted to be AGPL licensed. Change-Id: I62f2eed6305bfa11a64c6d633e08aabeaf9f0b10
* Integrate Debian packaging changesMax2016-12-2214-77/+462
| | | | | | | | | | | | | | | | | | | | | | | 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
* fsm: log tweak: upon free, say 'Freeing instance'Neels Hofmeyr2016-12-211-1/+1
| | | | | | | | 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
* doc: fix typo for osmo_hexparseNeels Hofmeyr2016-12-211-1/+1
| | | | Change-Id: Ifc2b499792fda378c807c678b8e06630cb64d273
* utils.h: add OSMO_STRINGIFY and OSMO_VALUE_STRING macrosNeels Hofmeyr2016-12-212-7/+9
| | | | | | | | | | | | | | 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
* Catch-up with git version tagsMax2016-12-2111-17/+51
| | | | | | | | | | | | * 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
* fsm: term: safer iteration to remove all child FSMsNeels Hofmeyr2016-12-201-4/+20
| | | | | | | | | | | | 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
* fsm api doc: fix typo in doxygen marker '\breif'Neels Hofmeyr2016-12-201-1/+1
| | | | Change-Id: I5c57e35b29d50cb409becada6b9b120ce5210ae0
* fsm: explicitly log removal from parent fsmNeels Hofmeyr2016-12-161-0/+3
| | | | | | | | | | | 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
* add value strings for enum osmo_fsm_term_cause and use for loggingNeels Hofmeyr2016-12-152-1/+20
| | | | Change-Id: Iaf63d3cadb0d46bf454e3314ebb439240cafd834
* typo in comment for osmo_fsm_log_addr()Neels Hofmeyr2016-12-141-1/+1
| | | | Change-Id: I6f683ed0c864a87bf1232994eb2deaf9b313a244
* fsm: log caller's source for events and state changes, not fsm.c linesNeels Hofmeyr2016-12-143-27/+103
| | | | | | | | | | | | | | | | | | | | | | | 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-143-12/+12
| | | | | | | | | | | | | | 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
* fix logging: log_set_category_filter() for internal DL* logging catsNeels Hofmeyr2016-12-122-1/+3
| | | | | | | | | | | | | | | | | | 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
* show bug in logging: log_set_category_filter on DL* categoriesNeels Hofmeyr2016-12-121-0/+6
| | | | | | | | | | | | | | 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
* fix logging: out-of-bounds check should end with user categoriesNeels Hofmeyr2016-12-122-0/+6
| | | | | | | | | | | | | 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
* show bug in logging: out-of-bounds check should end with user categoriesNeels Hofmeyr2016-12-122-0/+5
| | | | | | | | | | | | | | | | | | | 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
* fix logging: also catch first out-of-bounds logging catNeels Hofmeyr2016-12-122-1/+4
| | | | | | | | | | 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
* show bug in logging: erratic redirection to DLGLOBAL for first invalid categoryNeels Hofmeyr2016-12-121-0/+1
| | | | | | | | | | | | | | | | 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
* fix logging: redirection to DLGLOBAL for invalid categoriesNeels Hofmeyr2016-12-122-1/+10
| | | | | | | | | | | 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
* show bug in logging: erratic redirection to DLGLOBAL for invalid categoriesNeels Hofmeyr2016-12-121-0/+8
| | | | | | | | | | | | | | | | | | | | 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
* logging test: cosmetic: print target and don't print colorNeels Hofmeyr2016-12-122-4/+5
| | | | | | | Prepares for upcoming modifications of the logging test to show and fix bugs in the logging system. Change-Id: I9461b987adf85d87469a6af55de5f1aa478f6ebb
* doc: osmocom-authn-protocol.txt: fix numbering, mark unused sync msgsNeels Hofmeyr2016-12-111-11/+11
| | | | Change-Id: Ic1ec5d00de406f9581377ef4b5547782a80f368a
* oap: add encode/decode unit testNeels Hofmeyr2016-12-115-2/+273
| | | | Change-Id: I0e14099e2fc18e333a73d38bda059d53a8ca9944
* gsm/oap: more robust: decode presence as clearly either 1 or 0Neels Hofmeyr2016-12-111-4/+4
| | | | | | | Prepares for the unit test, which can now simply check for encode/decode identity. Change-Id: I410ff120d868e8d55df9cb19ba6eefd99749cdf0
* import oap message parsing / encoding from openbsc.git; AGPL->GPLHarald Welte2016-12-119-3/+519
| | | | | | | | | | | | | | | | | | | 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-113-6/+6
| | | | | | | | | | | | | | | | | | | 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
* Fix VTY: add missing doc for 'log gsmtap [HOSTNAME]'Neels Hofmeyr2016-12-111-1/+2
| | | | | | | | | Add missing doc string for the HOSTNAME arg. Added in commit aa00f99be2e4cc64ede20d8c9548b83054696581, this breaks the VTY tests for openbsc and hence breaks our jenkins build jobs. Change-Id: I734b22c950242541322e902887bf779c14ba10fd
* Implement GSMTAP log targetHarald Welte2016-12-096-3/+184
| | | | | | | 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
* Fix msgb_test on 64 bit architecturesHarald Welte2016-12-091-1/+1
| | | | | | | | | | | truncating the unsigned long pointer msg->data to 'int' and then passin git into msgb_resize_area() is unsafe as depending on the 32rd address bit it will be eiether negative or positive. That will in turn change the expected "Sub area is not fully contained in the msg data\n" error message into "Negative sizes are not allowed\n" which is not what the autotest case expects. Change-Id: I87ce13c265704d4ba8724e7dc7ed874c1128e0fa
* cosmetic: gsup comments: write 'Generic' for the G in GSUPNeels Hofmeyr2016-12-092-2/+2
| | | | | | | | The G used to mean GPRS, but the scope is larger now. To satisfy the curious reader, give the G a name in gsup files' header comments. BTW, logging.h and gsup_test.c already mentioned "Generic" before this. Change-Id: I6ac5cf94c215e156ceff6a58da3d9e520ca942d9
* license: gsup: libosmogsm requires GPL, not AGPL; say 'sysmocom'Neels Hofmeyr2016-12-092-6/+6
| | | | | | | | | The copyright in gsup.h differed from the one in gsup.c: gsup.c names the GNU Affero GPL, gsup.h only the GNU GPL. Change both to GPL-v2-or-later. In gsup.c/h's copyright notice, 'sysmocom' should be spelled lower case. Change-Id: Ia5748c275501889b9086aef7d20ccb5c9edb8031
* doc: fsm timer_cb: explain return valueNeels Hofmeyr2016-12-091-1/+2
| | | | Change-Id: Ic6fbe95737862ed8b8de78058989c8b2ae330006
* contrib: add fsm-to-dot.py to draw osmo_fsm dotty graphsNeels Hofmeyr2016-12-091-0/+710
| | | | | | | | Add a first version of a python script that tries to analyze .c source files to draw graphs of osmo_fsm implementations. So far it uses quick-and-dirty regexes. Change-Id: I155f57a608d600f59aedfd27ef66eb9772c124e7
* wqueue: Reject messges if queue is considered fullHolger Hans Peter Freyther2016-12-096-5/+103
| | | | | | | | | | | | | | | | | | The write queue was always meant to not queue more than the max_length messages but the implementation never rejected a message. Begin to log and enforce the queue size limit, add a testcase to verify the code and initialize except_cb as part of a fix for that new test case. Real applications might now run into the queue limit and drop messages where they just queued them before. It is unfortunate but I still think it is good to implement the routine as it was intended. We need to review osmo_wqueue_enqueue once more to see that no msgb is leaked. Change-Id: I1e6aef30f3e73d4bcf2967bc49f0783aa65395ae
* logging: Extend log_target with call-back for un-formatted log lineHarald Welte2016-12-022-2/+21
| | | | | | | | | | | 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
* Revert "gsm0408: add chreq_type for CHREQ_T_PDCH_ONE_PHASE and ↵Neels Hofmeyr2016-12-021-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | CHREQ_T_PDCH_TWO_PHASE" This reverts commit c3c28528de78fd5d50c3a141c2176c0da5dd7075. The reason is that this breaks a static assert in openbsc. See https://lists.osmocom.org/pipermail/openbsc/2016-December/009906.html Enlarging the ctype_by_chreq struct and breaks the static assert for gsm_network->ctype_by_chreq's size: ../../../src/libbsc/gsm_04_08_utils.c:138:1: error: size of array ‘dummyassert_size’ is negative osmo_static_assert(sizeof(ctype_by_chreq) == ^ What this patch lacks is, in openbsc.git: * adjustment of ctype_by_chreq[] according to the new additions in libbsc/gsm_04_08_utils.c * same for reason_by_chreq[], also in libbsc/gsm_04_08_utils.c * enlarge ctype_by_chreq[] in gsm_network to 18, in openbsc/gsm_data.h. Leaving it up to the original authors to follow up and commit a complete patch series in one go.
* gsm0480: add gsm0480_create_ussd_notify() and *_release_complete()Neels Hofmeyr2016-12-013-0/+33
| | | | | | | | | | | Add two functions to create USSD messages. Moves and generalizes code from openbsc. Pending: use the new functions in openbsc. It looks like _release_complete() should also set trans_id and direction flag; but since this is moving code from openbsc that is apparently working, just place a fixme comment and don't change the functionality. Change-Id: Ia80e32c7105359915bfad3cc5621a1c09caf20f0
* gsm0480: code dup: introduce and use gsm0480_l3hdr_push()Neels Hofmeyr2016-12-013-13/+19
| | | | | | | | Add function gsm0480_l3hdr_push() to push a struct gsm48_hdr to the start of a msgb. Use in gsm0480.c and gsm0411_utils.c. Further callers of the new function will follow in openbsc as well as another libosmocore patch for ussd. Change-Id: I54fce6053ab8362015686fe22dbcd38bf1366700
* gsm0408: add chreq_type for CHREQ_T_PDCH_ONE_PHASE and CHREQ_T_PDCH_TWO_PHASEAlexander Couzens2016-12-011-0/+2
| | | | | | For BSC-located pcu the BSC must understand the PDCH chan request. Change-Id: Ice44dcaaf798f93af3652a96c567f8e16a6cf784
* timer: only call the callback if not NULLAlexander Couzens2016-11-281-1/+2
| | | | | | Fix a crash in osmo-sgsn. Change-Id: I04d58d9580708cc0f6d0f4aa17d3e9f2c6235c8e
* ctrl_cmd_parse: Make coverity FORWARD_NULL happyHarald Welte2016-11-261-0/+1
| | | | | | | | | | | | The 'strtok_r' function requires passing a NULL as the first parameter on subsequent calls in order to ensure the code picks up where it left off on a previous call. However, Coverity doesn't quite realize this and points out that if a NULL was passed in as the third argument it would result in a possible NULL deref because the strtok_r function will assign the third argument to the first in the call is NULL. Change-Id: I7a9d08d0d4eae76a5207d285e32a25d1b384a57f Fixes: Coverity CID 135186
* Introduce osmo_strlcpy() function so we can stop using strncpy()Harald Welte2016-11-262-0/+24
| | | | | | | | | | | | | | | | 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