Commit Graph

1032 Commits

Author SHA1 Message Date
Philipp Maier 08177d324a lapd_core: Improve debug output
The debug output of lapd core has no references to the dl objects,
since we have multiple links, seeing which action is for which
object is impossible. This commit adds pointer references (dl=%p)
to each log line.

Change-Id: I3024d1cbd58631e2abac4ce5822528e2e6e15fda
2017-02-03 21:43:38 +00:00
Neels Hofmeyr 8352d31a86 GSUP, OAP, osmo-gen-vec: fix AUTS length to 14, not 16
GSUP transmits AUTS for UMTS authentication procedures, and OAP uses the same
procedures to authenticate. osmo-gen-vec is a utility program that passes AUTS
to our osmo_auth_gen_vec_auts() API.

According to 3GPP 33.102 6.3.3, AUTS = SQN^AK || MAC-S, which are 6 || 8 == 14
bytes. This is confirmed by 24.008 9.2.3a where the TLV has 16 bytes, TL = 2
and AUTS being the V = 14.

It is not harmful for milenage_gen_vec_auts() to pass two more AUTS bytes. But
writing 16 bytes to a GSUP struct is a potential problem when passing in a 14
byte long AUTS buffer to the GSUP API, which then reads past the AUTS buffer.
The API implies the length, so far to be 16, so passing in a 14 byte buffer to
GSUP would require copying to a larger buffer first.

Fix this by using a length of 14 for AUTS everywhere instead.

This constitues an ABI breakage, we may handle it as a "fix before an official
release", otherwise we need a version bump.

The OAP protocol document has also been updated, needs an update in the
osmo-gsm-manuals as well.

Change-Id: If25b173d9ec57ea4c504d860954912b7d82af455
2017-02-02 20:34:16 +01:00
Harald Welte 48f5583347 socket: Introduce function to obtain socket name
Using this function, one can obtain a human-readable string identifying
the host and port names of the socket.

Change-Id: Ib5de5c7b9effe1b0a363e4473a7be7fa38ca6ef3
2017-01-27 10:28:58 +01:00
Max 319f321da5 OML: add external alerts
Add special cause for alerts produced by external processes.

Change-Id: Idd7ee085321f8172c72ecfdba320186049f4d988
Related: OS#1615
2017-01-25 11:49:08 +00:00
Holger Hans Peter Freyther 6030ce844e sim: Link to libtalloc as symbols of it are used here
A DSO should link to the libraries that it is using. Linking to
libtalloc will resolve these warnings:

Change-Id: I4c8d5e80e194b9d9b4fa2424c4a22377ecee9c7a
dpkg-shlibdeps: warning: symbol _talloc_zero used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
dpkg-shlibdeps: warning: symbol _talloc_free used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
dpkg-shlibdeps: warning: symbol talloc_strndup used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
dpkg-shlibdeps: warning: symbol talloc_strdup used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
dpkg-shlibdeps: warning: symbol _talloc_memdup used by debian/libosmosim0/usr/lib/i386-linux-gnu/libosmosim.so.0.0.0 found in none of the libraries
2017-01-24 14:26:11 +01:00
Harald Welte abba1537a7 ipa: Remove unneeded #include statement
Change-Id: I69f2891a2bea6f87f079b6778aa01ee27a25001b
2017-01-23 12:20:34 +00:00
Harald Welte 44c0f63de6 disable various code if building for bare-iron embedded
We don't have file-based I/O nor ethernet devices with mac addresses
when building for OsmocomBB.

Change-Id: I01a9e6d8dbe885dbeac2769b84931a4d44f7a3a5
2017-01-23 12:20:33 +00:00
Max b0a4234c49 Add abis_nm_fail_evt_vrep to libosmogsm.map
Change-Id: If56b521429af497ddd5a47170eb2c085b1fb78ba
2017-01-19 09:07:33 +00:00
Neels Hofmeyr 0aeda1b17f doc: fix doxygen 'utils' group closing brace
osmo_strlcpy() was excluded from the group because the closing brace was above
it.

Change-Id: I6701261f5854342ac4cd4f2da62e49eb40362938
2017-01-18 01:50:39 +00:00
Max 6e8c172476 libosmogsm.map: fix typo
Change-Id: I71413fbe703e459782a235e5b1d8487265de3780
Related: OS#1615
2017-01-17 15:37:06 +00:00
Max ace80bb569 Mark deprecated function as such
Mark abis_nm_debugp_foh() function superseded by macro with the same
name as deprecated.

Change-Id: I2d3ea2b56aff6b687f72f832360b8cb8a24164e9
2017-01-16 08:53:20 +00:00
Neels Hofmeyr df83eced68 doc: clarify osmo_strlcpy() doc
Stating that it 'truncates src' is misleading. Also clarify whether siz
includes the space needed for the terminating NUL.

Change-Id: I01c1a94408b471f7f54576178a60938bf9ee3261
2017-01-15 17:58:29 +00:00
Harald Welte f2899c674e Always include <osmocom/core/talloc.h> and not <talloc.h>
In EMBEDDED builds we don't have a system-wide talloc

Change-Id: Icc526016bda45b36e584afee8669996752d6d89c
2017-01-15 18:04:02 +01:00
Harald Welte 1c67e754b8 configure.ac: Introduce --disable-ctrl
Using --disable-ctrl, one can disable the building of libosmoctrl.

The 'embedded' target will also automaticall disable ctrl.

Change-Id: I6912396338c5b23ae860fef2a55854d6df9a579d
2017-01-15 18:04:02 +01:00
Max 2f0b0c955b Fix compilation warnings: missing includes: gsm0411_utils.c, lapd_core.c, oap_test.c
Change-Id: Id524327b3f44e22e3aa44c5e8e4965b084cb326a
2017-01-13 09:36:25 +00:00
Neels Hofmeyr c32bfd5824 gprs_ns_vty: guard against duplicate VTY elements
The TbfTest in osmo-pcu calls gprs_ns_vty_init() repeatedly, which aborts
because of duplicate VTY elements. Fix this by skipping the VTY init if
it already happened.

Change-Id: I05c7f25a4e873ae76b206819180b8b043b60103e
2017-01-12 22:32:36 +01:00
Max 1251afe254 Add abis_nm_fail_evt_vrep() function
It accept fixed number of arguments including va_list instead of variable
number of arguments in abis_nm_fail_evt_rep() - similar to vprintff() vs
printf().

Related: OS#1615
Change-Id: Ib293dec1c2de9b664584a8456c782ea7b6dd8555
2017-01-11 18:12:32 +01:00
Max 87218edb9a LAPD: improve logging
Log error cause and state names in case of SABM errors.

Change-Id: I2c7fa276e03f8b14ba41cc1fb6e19d0aae77d127
2017-01-10 23:28:40 +00:00
Jean-Francois Dionne d02c8af6cc DTX: fix AMR SID-FIRST detection
Max's note: adjusted test output.

Change-Id: I46477c631bf86345cb757f31d7f2e2935b12adcc
Related: OS#1801
2017-01-10 23:28:12 +00:00
Max 85908a9c2f Add value strings for Probable Cause Type
Add string representation of Probable Cause Type from 3GPP TS 12.21 §
9.4.43.

Change-Id: I9fe14ed3b5398f59dd06a509e4d419e074cc20a7
Related: OS#1615
2017-01-10 17:49:23 +01: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
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
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
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
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
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
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 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 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 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 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 dd97950d26 gsm/oap: more robust: decode presence as clearly either 1 or 0
Prepares for the unit test, which can now simply check for encode/decode
identity.

Change-Id: I410ff120d868e8d55df9cb19ba6eefd99749cdf0
2016-12-11 03:42:58 +01:00
Harald Welte c0f0007292 import oap message parsing / encoding from openbsc.git; AGPL->GPL
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
2016-12-11 03:42:58 +01:00
Neels Hofmeyr 9795cf1b12 fix: DLGSUP logging category "unusable"
All DL* categories are typically negative, but DLGSUP isn't, and it's also not
in libosmocore's internal_cat array.
See: 3b6fb0880c

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
2016-12-11 03:42:58 +01:00
Neels Hofmeyr fd9ec3bc7d Fix VTY: add missing doc for 'log gsmtap [HOSTNAME]'
Add missing doc string for the HOSTNAME arg.

Added in commit aa00f99be2, this breaks the VTY
tests for openbsc and hence breaks our jenkins build jobs.

Change-Id: I734b22c950242541322e902887bf779c14ba10fd
2016-12-11 01:48:26 +01:00
Harald Welte aa00f99be2 Implement GSMTAP log target
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
2016-12-09 17:59:58 +01:00
Neels Hofmeyr 665d48bf15 cosmetic: gsup comments: write 'Generic' for the G in GSUP
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
2016-12-09 16:47:05 +01:00
Neels Hofmeyr 5f460dee3d license: gsup: libosmogsm requires GPL, not AGPL; say 'sysmocom'
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
2016-12-09 16:47:05 +01:00
Holger Hans Peter Freyther c7f52c4c84 wqueue: Reject messges if queue is considered full
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
2016-12-09 11:37:37 +01:00
Harald Welte d7c0a373ff logging: Extend log_target with call-back for un-formatted log line
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
2016-12-02 13:52:59 +01:00
Neels Hofmeyr bc1d758299 gsm0480: add gsm0480_create_ussd_notify() and *_release_complete()
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
2016-12-01 15:54:35 +00:00
Neels Hofmeyr 25774b9839 gsm0480: code dup: introduce and use gsm0480_l3hdr_push()
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
2016-12-01 15:54:34 +00:00
Alexander Couzens ec9bd52628 timer: only call the callback if not NULL
Fix a crash in osmo-sgsn.

Change-Id: I04d58d9580708cc0f6d0f4aa17d3e9f2c6235c8e
2016-11-28 23:23:09 +01:00
Harald Welte edf6fe75b7 ctrl_cmd_parse: Make coverity FORWARD_NULL happy
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
2016-11-26 18:37:57 +00:00
Harald Welte aeecc48c45 Introduce osmo_strlcpy() function so we can stop using strncpy()
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
2016-11-26 16:42:17 +00:00
Harald Welte 1fa78567e4 osmo_gsup_encode(): Make coverity happy by invariant checking
gsm48_encode_bcd_number() can theoretically return a length in excess of
the size of the bcd_buf, but only in case an overly-long IMSI is passed
into the function (which would be illegal in the first place).

Change-Id: If3dc68ee13ff784b487bbc686b777cec9057d537
Fixes: Coverity CID 135216
2016-11-26 13:47:14 +00:00
Harald Welte 4a1cb09a40 telnet_interface: Handle osmo_fd_register() eror return code
Change-Id: I5bc1c2cbb04e363d868355b5ed866b4840f16c61
Fixes: Coverity 57637
2016-11-26 10:24:19 +01:00
Harald Welte 0fc315dd9e osmo_sock_init(): Fix memory leak in error path
We forgot to call freeaddrinfo() in an error path.

Change-Id: Iccbd3beef4c4a70dc443131b909c45e650d8c6a2
Fixes: Coverity CID 135217
2016-11-26 10:24:19 +01:00
Harald Welte 9d862c8998 Fix unchecked return valueof osmo_fd_register()
Change-Id: Ib040a7f94eb1bbec8270b66fd4c2aedef9d5346a
Fixes: Coverity CID 57636
2016-11-26 00:10:07 +01:00
Max 9b4d065ba5 Extend IPA error logging
Output more information in case of IPA protocol errors to make debugging
easier.

Change-Id: I7632d6e679e076bfbec9abc12da4a46cc27ccea1
Related: SYS#3028
2016-11-16 09:29:23 +00:00
Daniel Willmann 55363a9f62 vty: Skip printing non-initialized log categories
Without this patch the vty command show logging vty will cause a segfault if
not all elements of the log_categories array are defined.

Ticket: OW#3053
Sponsored-by: On-Waves ehf
Change-Id: Ieeba649c3bde6c9376d8e32b00b92beb37c08ef2
2016-11-15 22:31:19 +00:00
Harald Welte 6176b6e092 bssgp_rx_paging(): Fix parsing of P-TMSI IE in Paging message
This was actually discovered by the following compiler warning in
gcc-6.2.0:

  CC       gprs_bssgp_bss.lo
gprs_bssgp_bss.c: In function ‘bssgp_rx_paging’:
gprs_bssgp_bss.c:544:2: warning: this ‘if’ clause does not guard...
[-Wmisleading-indentation]
  if (TLVP_PRESENT(&tp, BSSGP_IE_TMSI) &&
  ^~
gprs_bssgp_bss.c:548:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
   *(pinfo->ptmsi) = ntohl(*(uint32_t *)
   ^

This is an actual bug.  If we recevied a BSSGP Paging Request without
P-TMSI, we might crash or report some random memory as P-TMSI to the
caller in the output data structure.

Change-Id: Ib4f307827cd7cccc91c1415a6fb5428d7cf8416d
2016-11-11 14:49:31 +00:00
Harald Welte c4193d30e8 gan: Mark gan_pdisc_vals[] as public / non-static symbol
It is actually listed in libosmogsm.map, but still used to be a static
symbol.  That couldn't have worked.

Change-Id: I6f3f04b683d906674ee7da9bab5762bb00cea916
2016-11-11 14:49:14 +00:00
Harald Welte 684cf32243 bssgp_vty: Remove dead code and compiler warning
gprs_bssgp_vty.c:48:34: warning: ‘gprs_bssgp_timer_strs’ defined but not used [-Wunused-const-variable=]
 static const struct value_string gprs_bssgp_timer_strs[] = {
                                  ^~~~~~~~~~~~~~~~~~~~~

Change-Id: Ia41ccb7b227c41996cdef51dc6779bfc5b5a8d48
2016-11-11 15:24:29 +01:00
Harald Welte 1554f80f5e statsd: Fix compiler warning (int32_t vs. int64_t)
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
2016-11-11 15:24:24 +01:00
Holger Hans Peter Freyther bf173a3df5 bitcomp: Remove the t4 decoding from libosmocore
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
2016-11-10 17:07:45 +00:00
Max 3de97e1926 Add logging and testing for FSM deallocation
osmo_fsm_inst_alloc() logs allocation but osmo_fsm_inst_free() is
silent. Fix this by adding log message for deallocation to make FSM
lifecycle tracking easier. Also make sure it's covered by test suite.

Change-Id: I7e5b55a1fff8e36cf61c7fb61d3e79c1f00e29d2
2016-11-08 19:35:19 +00:00
Max e9e5f8e4e9 Add null-pointer check to osmo_amr_rtp_dec()
Check that RTP payload we're about to decode is not NULL and return
proper error code instead of segfaulting. Add corresponding test case.

Change-Id: Ib6cda9900a41ed16bbfbde9df3de9d38e0a7469b
2016-11-07 15:19:47 +01:00
Max 61281f4c47 Fix typo in osmo_fsm_log_addr()
Previously function parameter was ignored, fsm_log_addr was always set
to false.

Change-Id: I74f06eab2dfa81dbb95e01f0b4b26448fd1b98f8
2016-11-01 10:49:31 +01:00
Philipp Maier 72e43f02c3 gsm0408: Completing GSM 04.08 RR message types
- Add missing message types to be up to date with the
  latest specification release (3GPP TS 04.18)

- Add value strings to translate RR message type identifiers
  into human readable strings. (see gsm48_rr_msg_name() in
  gsm48.h

Change-Id: I3ceb070bf4dc8f5a071a5d43c6aa2d4e84c2dec6
2016-10-27 13:36:42 +02:00
Philipp Maier ada0042c58 COSMETIC: moving rr_cause_name() in gsm48.c
rr_cause_name() is located a far of from
value_string rr_cause_names[] while other value string
functions are located right below their related value
string definitions. This commit moves rr_cause_name()
below rr_cause_names[] as it should be

Change-Id: Ie6c03a6ea02c370d8733db5ba2a709610cd70ce7
2016-10-27 13:36:42 +02:00
Vadim Yanitskiy a6b5216ab4 utils/conv_gen.py: add EDGE MCS 1-9 definitions
Change-Id: Ie1452342f524a8b60f2babc07398a1d9c9e06aa3
2016-10-23 07:38:16 +00:00
Vadim Yanitskiy f3d38c4937 utils/conv_gen.py: add RACH, SCH and TCH/AHS definitions
Change-Id: I0ea7151f4e8119a8798a9e129b951559e56b0d93
2016-10-23 07:38:15 +00:00
Vadim Yanitskiy d2d9760c08 utils/conv_gen.py: generate a single file
Instead of generating every convolutional code into a separate
file (such as conv_xcch_gen.c, conv_cs3_gen.c), it is better to
have a single file, containing all definitions, because as many
convolutional codes we add, as many entries we will have to add
into 'src/gsm/Makefile.am'. This approach increases readability
of the Makefile.am, and also makes us able to share some data
between some convolutional code definitions.

For example: xCCH, RACH, SCH, TCH/F, both CS2 and CS3 may use
the same *_state[][2] and *_output[][2] arrays within a single
file. This optimization is currently WIP.

Change-Id: Ib4e4ee5fdde38429e68e3b2fa50ec03a18f59daa
2016-10-23 07:38:15 +00:00
Alexander Couzens eb604cf44f vty/show asciidoc: counters: improve table headers
add [options=header] to every table header
vty/show asciidoc: rename reference field into "Reference"
vty/show asciidoc: capilize table header field names

Change-Id: Ie991f4db77a60afb86a2a0b35c137586527f6228
2016-10-18 12:19:13 +02:00
Alexander Couzens e052dc285d vty/show asciidoc: add user readable description of the version
Change-Id: Ie0f1b3894361c58386da9defb225979fa0ee6a18
2016-10-18 10:15:23 +00:00
Alexander Couzens 27a35ed47c stats_statsd: use int64_t instead of int for value and delta.
The stats infrastructure use int64_t for values and delta. So the
statsd reporter get call with int64_t.

Change-Id: I33df86de60007a64fa853d6d3af9b609877a8fc6
2016-10-18 09:52:13 +00:00
Alexander Couzens 3e432e1912 vty/osmo_counter: use name if description is NULL
`show stats` shows (null) for osmocom_counters when
description is null.

OpenBSC> show  stats
Ungrouped counters:
 (null):        4

Change-Id: I553b88a6fca688924b1f2b49e8cb17e90f057bb1
2016-10-13 11:04:48 +00:00
Neels Hofmeyr 2b3c228416 gsm/Makefile.am: use proper top_builddir/top_srcdir paths
This fixes the conv*gen.c targets when building in a different directory
than the source tree.

Notably, building in a different dir worked when the generated sources were
already present from a previous build inside the source directory.

Change-Id: I5a9b780ad4ba607ea39854dcf7207ed05f5447bc
2016-10-12 22:50:24 +00:00
Max bc067eb0a2 Add function to send TRAP over Control Interface
Change-Id: Ic0b8d88c4f5c4d42c3f8fb754f8eabf049c9e388
Related: OS#1646
2016-10-12 11:37:49 +00:00
Neels Hofmeyr a95ee5e6e1 fix USSD: SS message type mask should be 0x3f, not 0xbf
See 04.80[1], section 3.4: the highest two bits are used as counter or ignored
and do not contribute to the SS "Miscellaneous message group". Previous mask of
0xbf included the highest bit, fix to 0x3f.

Observed a value of 0xbb that should mean 0x3b="Register" during testing of 3G
USSD requests, which seem to be the first to send a nonzero highest bit to our
code. The erratic mask of 0xbf lead to an unhandled message type of 0xbb.

[1] 3GPP TS 24.080 version 7.2.0 Release 7 / ETSI TS 124 080 V7.2.0 (2006-09)

Change-Id: I299001a9e36c16f55622a0acd5d4a55ca49d0055
2016-10-12 09:26:52 +00:00
Neels Hofmeyr 9c0751fc60 osmo_select_main(): drop useless call to osmo_timers_check()
osmo_timers_check() does nothing more than counting the active timers. It is of
no use to count them when not using the return value in any way.

Change-Id: I8d35ca90a4c16d6f1c7f9793d663e5479783efed
2016-09-28 10:48:46 +00:00
Neels Hofmeyr f45334be29 msgb: add msgb_talloc_ctx_init(), deprecate msgb_set_talloc_ctx()
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
2016-09-27 11:46:38 +02:00
Neels Hofmeyr 38d232ee5d log CTRL bind address and port
Log 'CTRL at 1.2.3.4 5678' from ctrl_interface_setup*. All callers can now drop
any extra 'CTRL at 1.2.3.4 5678' logging.

Change-Id: If449d0514e3d0cc1b346d7452194d931aa090166
2016-09-23 02:39:12 +00:00
Neels Hofmeyr 55dc2edc89 log telnet bind address and port
Log 'telnet at 1.2.3.4 5678' from telnet_init*. All callers can now drop any
extra 'VTY at 1.2.3.4 5678' logging.

Change-Id: I1da7b9076311d9458caea732fc0daace6533a3fd
2016-09-23 02:39:12 +00:00
Neels Hofmeyr 8e2f7e87f4 add osmo_gettimeofday as a shim around gettimeofday
This allows feeding a custom time for unit tests by overriding
osmo_gettimeofday.

Change-Id: Ic7a81a6eb51f27fe452962b91f2eae2070d87089
2016-09-22 07:18:39 +02:00
Neels Hofmeyr 5b34f773e4 remove unused local variable in get_rate_ctr()
Unused after 22886d9e32
"Fix retrieving rate_ctr over control interface"

Change-Id: Ib5411da80c4eb4f905a5ed87c60477eca2cdff42
2016-09-19 14:18:38 +02:00
Neels Hofmeyr 2e38d358b6 remove unused function get_rate_ctr_group()
Unused after 22886d9e32
"Fix retrieving rate_ctr over control interface"

Change-Id: I405367ef6ba5833957778a79dd398ce5ea29307e
2016-09-19 14:18:38 +02:00
Anatoly Orlov 6320934e6a libosmocodec link fix on MacOSX
Fixes the following bug:

  CCLD     libosmocodec.la
Undefined symbols for architecture x86_64:
  "_bitvec_get_bit_pos", referenced from:
      _osmo_fr_check_sid in gsm610.o
  "_bitvec_get_uint", referenced from:
      _osmo_hr_check_sid in gsm620.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libosmocodec.la] Error 1

Change-Id: Id7358b94e274b529a8da38a0b2ef8c892b6dd7a5
2016-09-09 06:35:21 +00:00
Neels Hofmeyr 0318f6b6ca IuPS: add GMM Service Request related constants and value_str
Change-Id: Ie023fc78099932f95cc8f1b3a04fe25dfd14bc35
2016-08-29 13:56:17 +02:00
Neels Hofmeyr b7f191febb fix printf format for commit 'osmo_sock_init(): include host and port in error messages'
Related: CID#143566
Change-Id: I75c542089749a0875d3d1913151fe838d7722ff2
2016-08-29 11:22:39 +02:00
Neels Hofmeyr f0f07d9c9b osmo_sock_init(): include host and port in error messages
For programs like osmo-hnbgw with numerous sockets, the message that some
unspecified connection was refused is not very helpful. Also output the host
and port where an error occured.

Instead of perror, use fprintf(stderr, ..., strerror()) to be able to include a
format string and print host and port as passed to osmo_sock_init().

Change-Id: I8d0343f51310699b78fcb83fd76fd93764acf3dc
2016-08-27 02:01:20 +00:00
Neels Hofmeyr 898e1d878e vty: use VTY_BIND_ADDR_DEFAULT instead of "127.0.0.1"
Change-Id: Ice0688ac9847524cb546f6d41547090b6a3cb3d8
2016-08-20 16:33:47 +02:00
Harald Welte 460f9ef7da fsm: Make sure we call 'onenter' of new state, not old state
Change-Id: I1a0181c25d9debe935e86d97ddffc24675e56a5f
2016-08-01 00:38:36 +02:00
Harald Welte f92e44c539 lapd_core: Fix crash in lapd_dl_flush_hist()
When lapd_dl_flush_hist() was called before we actually had started a
transmit history from lapd_dl_init(), we woul segfault before this
patch.

Change-Id: Ifa677c9b335dd2884b4f3e44699d901957a0500b
2016-08-01 00:27:37 +02:00
Tom Tsou 9a5bbf36b5 egprs: Add CPS tables from TS 04.60
Includes EGPRS coding and puncturing scheme (CPS) tables from 3GPP
TS 04.60. Currently osmo-bts-trx is the only user of CPS table
values, but this may change with gprsdecode and other utilities.

Change-Id: I09fe6514a0e2e51bb3206f8387633f7e0255345f
2016-07-25 18:33:26 +00:00
Neels Hofmeyr 47390764dd rsl: add rsl_act_type_name()
Change-Id: Ie90c76d8aef42d5e2c9be94f4b206d4994e305f8
2016-07-23 15:32:55 +02:00
Neels Hofmeyr fd80f5a042 dyn TS: add definitions for dynamic TCH/F_TCH/H_PDCH
Add:
* GSM_PCHAN_TCH_F_TCH_H_PDCH
* NM_CHANC_OSMO_TCHFull_TCHHalf_PDCH
* RSL_CHAN_OSMO_PDCH
* RSL_ACT_OSMO_PDCH

Related: OS#1776
Change-Id: Ib1a8b11f37af4686d00ac88beba38557aa29edc2
2016-07-23 15:32:55 +02:00
Neels Hofmeyr 505adee93b fix compiler warning: gsup.c: missing braces
osmo_auth_vector's first member is an array, so for a zero initializer, we
should add a second set of array braces.

Change-Id: Iace448caca8152e46244f26c3af250f2035c99eb
2016-07-17 07:44:11 +00:00
Holger Hans Peter Freyther 511b448fe3 bitvec: Force inlining of bitvec_set_bit_pos/bitvec_set_bit
The PCU is using bitvec_write_field a lot but on the
arm-poky-linux-gnueabi-gcc v4.8.1 the calls to set_bit and
set_bit_pos are not inlined. The inlined variant has been
a more quick for the PCU compressed bitmap decompression
testcase.

Used objdump -d to look at the bitvec_write_field before and
after the change. The branch to bitvec_set_bit is gone and a
inlined version has been used.

Change-Id: I0b6b90610f4c17f02e4efa064c3bf1ac2dccb22a
2016-07-16 21:02:41 +00:00
Max 4f169500df Add GEA3 & GEA4 ciphers
Corresponding test code include both official test vectors from the
specs and data from over-the-air tests.

This obsoletes libosmo-crypt-a53 as it was last missing piece
unimplemented in libosmogsm.

Change-Id: I939e4f6b91b4a7c591ef3761fe2d46ed1c2fb2d3
Related: OS#1582
2016-07-11 19:15:24 +00:00
Harald Welte 02a6672885 fsm: delete the timer when changing state
In osmo_fsm_inst_state_chg(), we need to stop any not-yet-expired timer
of the old state before transitioning into the new state.

Change-Id: I2558f9a7027a877ea8263785ed3c8d70d2513996
2016-07-10 15:13:51 +02:00
Harald Welte f3239113db fsm: talloc + copy the 'id' passed into a FSM
The 'id' is used to generate the human-readable name of the FSM.
However, when the FSM creates slave FSMs later, the caller-passed "ID"
mgiht long be gone again (e.g. it was on stack memory).  So let's copy
the 'id' string to a chunk of dynamically-allocated memory at time of
FSM start to ensure we have it later when creating child FSMs.

Change-Id: Ib88a2c02c5c91f17b4ec1e9db57a06d6d66465fb
2016-07-10 15:11:45 +02:00
Harald Welte 673018fed9 fsm: call 'onenter' as last step of a state change
This is useful to allow the user to terinate the fsm from the onenter()
callback.

Change-Id: Ia45a1f3279e702028250e10dc54b2d46a4039905
2016-07-10 15:09:43 +02:00
Max f5f773f013 Add strings with GPRS GMM messages
Change-Id: I48477b733e2da72f59349c00554dd3e080c9f445
Related: OS#1582
2016-07-08 15:08:17 +00:00
Max fdca25dfb8 Add function to check GMM encryptability
Check if particular GMM message can be encrypted according to 3GPP TS
24.008 § 4.7.1.2

Related: OS#1582
Change-Id: I7ad0e03c2c738d174dd6bc3453f332eeb8da1e7d
2016-07-07 12:55:46 +00:00
Max 92ce39f3d1 Add missing osmo_c4 export
Change-Id: Iaf53b31b4fa3860301054e970907ada061360b28
Related: OS#1741
2016-07-07 13:00:43 +02:00
Harald Welte 0ee90f8614 lapd_dl_flush_hist(): Don't flush a non-existant history
If lapd_dl_flush_hist() is called after lapd_dl_exit(), dl->tx_hist has
already been free'd and set to NULL.  Check for this before attempting
to de-reference a NULL pointer.

This bug breaks OpenBSC with any E1 based BTSs using DAHDI.

Change-Id: I117ba3445fa5e8097e21c11c5a6337de6ba46c7d
Related: OS#1760
2016-07-03 20:47:06 +02:00
Max a337b9c37a Add function to check MS GEA capabilities
Add function which parses MS network capability IE value for bits
indicating support for particular version of GEA.

Change-Id: I785cef37dd272a2fab9b172f6e1392f865174e9a
Relates: OS#1582
2016-06-29 16:33:25 +00:00
Max ceae123752 Make C4 function globally available
This function perform 64 -> 128 bit key expansion which useful for
converting between UMTS CK and GSM Kc, A5/3 and A5/4, GEA3 and GEA4
keys.

Change-Id: I5a6c6deef6027cd6af144c9062d4c9166be26904
Related: OS#1582
2016-06-29 16:32:55 +00:00
Max b897c42993 Add strings for GPRS ciphers
Change-Id: I050bda5fb50aad42fe2d72de39f8256b4fb12fb2
Related: OS#1582
2016-06-29 16:32:27 +00:00
Harald Welte 14bf28a43d Mark input parameter to bitvec_set_bits() as 'const'
The input data is accessed in a read-only manner, so it should be marked
with the const qualifier.

Change-Id: I0d6b86289fa647594f3da1f1c0e0168685307a37
2016-06-27 15:19:10 +02:00
Harald Welte f627c0f0af fsm: Introduce default time-out handling
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
2016-06-27 15:17:53 +02:00
Max d826f1771c Fix potential segfault in msg_dequeue
Change-Id: I06e9c5ba3e00c73a4e52d2583ce3492f236275ce
2016-06-23 20:00:33 +00:00
Max e0a7d9e2c2 Add octet-aligned/unaligned shift functions
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
2016-06-20 19:02:56 +02:00
Harald Welte 136e73764e Add Finite State Machine abstraction code
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>
2016-06-16 21:43:45 +00:00
Harald Welte 82f94ef50f Add UMTS AKA related MM/GMM message type and IE definitions
Change-Id: Id45ea2c631ee589a4df1f8213da6f7e7d1bf6616
Reviewed-on: https://gerrit.osmocom.org/305
Reviewed-by: Harald Welte <laforge@gnumonks.org>
Tested-by: Jenkins Builder
2016-06-16 21:43:21 +00:00
Harald Welte db78d2172b gsup.c: Fix encoding of UMTS auth vectors
Encoding auth vectors worked fine for GSM authentication, but didn't
yet include the new IEs for UMTS authentication yet.

Change-Id: I7fa5ba1c950292bd0a9874b3102a27f221ce390d
Reviewed-on: https://gerrit.osmocom.org/302
Reviewed-by: Harald Welte <laforge@gnumonks.org>
Tested-by: Jenkins Builder
2016-06-16 21:25:18 +00:00
Harald Welte f624c33ef2 vty: Fix documentation of 'show asciidoc counters' VTY command
VTY documentations strings follow a certain structure, and we need to
follow that to make the interactive help work.

Change-Id: I0bb0bda68dbbf9995338ec555ff99d73a223162c
Reviewed-on: https://gerrit.osmocom.org/276
Reviewed-by: Harald Welte <laforge@gnumonks.org>
Tested-by: Harald Welte <laforge@gnumonks.org>
2016-06-15 09:39:20 +00:00
Max 22886d9e32 Fix retrieving rate_ctr over control interface
Allow getting either particular
counter (e. g. rate_ctr.per_hour.e1inp.0.hdlc.abort) or entire rate
counter group for a given index (e. g. rate_ctr.per_hour.e1inp.0).

Change-Id: I2b0109536170f7b5388d3236df30b98f457aa98d
Fixes: OS#1730
Reviewed-on: https://gerrit.osmocom.org/274
Tested-by: Jenkins Builder
Reviewed-by: Harald Welte <laforge@gnumonks.org>
2016-06-14 22:21:24 +00:00
Alexander Couzens ad580ba7c4 add vty call show asciidoc: generate a documentation for counters
For each counter group a ascii doc table is generated
containing all single counter with a reference to a section to
add additional information to the counter

Change-Id: Ia8af883167e5ee631059299b107ea83c8bbffdfb
Reviewed-on: https://gerrit.osmocom.org/70
Reviewed-by: Harald Welte <laforge@gnumonks.org>
Tested-by: Harald Welte <laforge@gnumonks.org>
2016-06-14 10:38:17 +00:00
Neels Hofmeyr 0167e3f355 add rsl_or_ipac_msg_name() for both standard and ip.access msg types
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.

Change-Id: Ic9ba721a1469cf51aed97ab0f44a7fe055c94b1f
Reviewed-on: https://gerrit.osmocom.org/231
Reviewed-by: Harald Welte <laforge@gnumonks.org>
Tested-by: Jenkins Builder
2016-06-13 17:46:48 +00:00
Neels Hofmeyr 8d6dcd9bca add get_value_string_or_null() to handle unknown items
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
2016-06-13 17:46:20 +00:00
Neels Hofmeyr 8a3c83ed00 api doc: get_value_string(): mention composition in static buffer
Change-Id: I93dad98711ef69f8a1e196efa029a842a1ff5bd6
Reviewed-on: https://gerrit.osmocom.org/229
Reviewed-by: Harald Welte <laforge@gnumonks.org>
Tested-by: Jenkins Builder
2016-06-13 17:45:52 +00:00
Max ec8f192fec Add functions to detect HR/FR SID frames
Add functions which check if given FR or HR frame (packed in RTP)
contains SID (SIlence Descriptor) and corresponding tests.

Related: OS#22
Change-Id: I4051e3c0d4fb9ee93d7e9e0ef4abaf9f18e227ca
Reviewed-on: https://gerrit.osmocom.org/160
Tested-by: Jenkins Builder
Reviewed-by: Harald Welte <laforge@gnumonks.org>
2016-06-01 10:44:06 +00:00
Max 92db150488 Add helper functions for AMR codec
* add functions to encode/decode various codec paramters from RTP payload with
  AMR frame according to RFC 4867
* those functions are extended version based on code from osmo-bts'
  amr.c by Andreas Eversberg
* add corresponding enum types and strings for logging
* add regression tests

It's useful both to replace manual parsing in osmo-bts with fuctions
covered by test suite and as a debugging helpers for issues related to
AMR.

Change-Id: Ia217679a07d3fbc970f435e20f6eac33d34bd597
Related: OS#1562
Reviewed-on: https://gerrit.osmocom.org/118
Tested-by: Jenkins Builder
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-31 10:11:51 +00:00
Max adef12a349 Add strings with PH primitive names
It's useful debugging helper while troubleshooting L1-related issues.

Change-Id: Id7a6d478fd725c51f54ad746bdf9b9095579ff77
Reviewed-on: https://gerrit.osmocom.org/117
Tested-by: Jenkins Builder
Reviewed-by: Max <msuraev@sysmocom.de>
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-30 21:21:20 +00:00
Ruben Undheim 029f5a1c0d misc: Some spelling errors corrected
Change-Id: Ibfc239b84879556624ca6020ae6a63d102640c94
Reviewed-on: https://gerrit.osmocom.org/114
Tested-by: Jenkins Builder
Reviewed-by: Neels Hofmeyr <nhofmeyr@sysmocom.de>
2016-05-25 19:43:56 +00:00
Holger Freyther 45abec20dd Revert "gsm48: move to hex TMSI representation"
This is a "flag" day change. Old OpenBSC break with new libosmocore
because suddenly there is the 0x in front. I am afraid we need to
find a better solution here. I think we will need to create a
gsm48_mi_to_string variant that takes a mode parameter to enable the
TMSI mode and deprecate the old method.

Right now we should not break old versions of OpenBSC.

This reverts commit 78ad042f94.

Change-Id: I2f61e626f2f9088b492e1b643c3dcc9bce77d52b
Reviewed-on: https://gerrit.osmocom.org/86
Tested-by: Jenkins Builder
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-20 19:42:50 +00:00
Arran Cudbard-Bell cc3694b650 Fix build for OSX
Change-Id: I580a500edcf4812e570be586890abef746083a8c
Reviewed-on: https://gerrit.osmocom.org/74
Tested-by: Jenkins Builder
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-20 16:32:58 +00:00
Vadim Yanitskiy 78ad042f94 gsm48: move to hex TMSI representation
Previously, we traditionally displayed a TMSI in its integer
representation, which is quite unusual in the telecom world.
A TMSI is normally printed as a series of 8 hex digits.

Review at https://gerrit.osmocom.org/57/
Change-Id: Ifd25365bfa3b4ee95b16979740c3229948ce17f2
Reviewed-on: https://gerrit.osmocom.org/57
Tested-by: Jenkins Builder
Reviewed-by: Harald Welte <laforge@gnumonks.org>
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-20 16:26:51 +00:00
Max 764b022fc6 Add function to make Uplink Measurement
It assembles RSL Uplink Measurement IE according to 3GPP TS 08.58
§9.3.25. The function is based on lchan_build_rsl_ul_meas() from OsmoBTS
but optionally includes DTX information.

Change-Id: Ib37107bcc9909e5105ea711de42d3fb1db7e8d9e
Reviewed-on: https://gerrit.osmocom.org/44
Tested-by: Jenkins Builder
Reviewed-by: Harald Welte <laforge@gnumonks.org>
2016-05-17 16:10:31 +00:00
Max fe65fa7e36 Set DTX in Cell Options
* rename field of struct gsm48_cell_options to better match the spec
* add comments with spec references
* add function for setting DTX in cell options struct
* add necessary enum type

Change-Id: I5a8924f57669c951b2e51b663d95f1d360062a54
Reviewed-on: https://gerrit.osmocom.org/39
Reviewed-by: Harald Welte <laforge@gnumonks.org>
Tested-by: Jenkins Builder
2016-05-12 15:56:39 +00:00
Neels Hofmeyr c7bf8d0c84 api doc: auth_core.c: add \returns, cosmetic
Add various missing \returns doxygen entries.

In osmo_auth_3g_from_2g(), also adjust two comment-closing instances to
match common style and add a period to end a sentence.

(The recent addition of osmo_auth_3g_from_2g() raised my attention, and I added
more return value docs while at it.)

Change-Id: Iea71eb666bc061acb6b14215f398bd38d17b3ad3
Reviewed-on: https://gerrit.osmocom.org/33
Tested-by: Jenkins Builder
Reviewed-by: Holger Freyther <holger@freyther.de>
2016-05-10 11:05:27 +00:00
Harald Welte 766da86877 GSUP: Add support for RAND in SendAuthInfo.req
In the autentication re-sync case, we need not only the AUTS from
the MS/UE, but also the RAND that we sent as part of the failed
authentication challenge.
2016-05-06 11:22:05 +02:00
Harald Welte 48dc1a5a64 GSUP: Add OSMO_GSUP_CN_DOMAIN_IE to differentiate CS and PS plane
We're starting to use GSUP for circuit-switched (CS) plane, so we need
to differentiate the two planes somehow from each other.
2016-05-06 11:21:25 +02:00