Commit Graph

959 Commits

Author SHA1 Message Date
Harald Welte c733d1421a lapd_core: Use 'struct value_string' for LAPD state names
We don't really use state numbers without bounds check into string
tables since March 2010, when value_string became part of libosmocore.

It's time to catch up, 7 years later...

Change-Id: I1dac7b4cb441a1119cc167112521e8b8aae62e63
2017-03-15 10:24:25 +01:00
Neels Hofmeyr 6d0fd7ba97 build: cosmetic: coding: break a CPPFLAGS line
Matches our general scheme and helps readability of an upcoming patch.

Change-Id: I174086a988b51b6e80f3661609069b69a3d41cc7
2017-03-13 14:49:12 +01:00
Vadim Yanitskiy 3262f820b5 libosmocoding: migrate transcoding routines from OsmoBTS
There are some projects, such as GR-GSM and OsmocomBB, which would
benefit from using one shared implementation of GSM 05.03 code. So,
this commit introduces a new sub-library called libosmocoding, which
(for now) provides GSM, GPRS and EDGE transcoding routines, migrated
from OsmoBTS.

The original GSM 05.03 code from OsmoBTS was relicensed under
GPLv2-or-later with permission of copyright holders (Andreas Eversberg,
Alexander Chemeris and Tom Tsou).

The following data types are currently supported:

 - xCCH
 - PDTCH (CS 1-4 and MCS 1-9)
 - TCH/FR
 - TCH/HR
 - TCH/AFS
 - RCH/AHS
 - RACH
 - SCH

Change-Id: I0c3256b87686d878e4e716d12393cad5924fdfa1
2017-03-07 01:06:38 +07:00
Neels Hofmeyr cb5c4edda9 ctrl_type_vals: fix range check
In ctrl_cmd_parse(), fix missing check for not parseable ctrl type.

Fixup for Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28.

Change-Id: I7f8055225e3ee04b2a723bae07b12c42618963a0
2017-03-06 14:35:54 +00:00
Max 777be2e734 Check for proper lapdm_datalink entity
Previously lapdm_datalink->entity->mode was dereferenced without
checking if correct entity is present. This might lead to
segfault. Check it explicitly before dereferencing, log error and
gracefully return if necessary.

Change-Id: I0361e3731e86712b415a370cab1128d611988f56
Related: OS#1898
2017-03-02 14:10:06 +00:00
Neels Hofmeyr 90fdb08e3e fix: gsm0808.c: unterminated value_string array gsm0808_bssap_names
Change-Id: Ie38bae32372dc41e1902a8f6f0bc550ae515cfb8
2017-03-02 01:48:10 +00:00
Max 2ed3659cac Handle replies in ctrl_cmd_handle()
Previously *_REPLY and ERROR messages were not explicitly handled which
would lead to sending error in response to them which in turn would
prompt other party to send error as well which would result in infinite
cycle.

Handle it explicitly by logging message id and other relevant data.

Change-Id: Id96f3a2fc81fa4549f49556d83f062c6b2f59e28
Related: OS#1615
2017-03-01 16:37:59 +00:00
Max 70c7d4160d Use value_string for ctrl_type
Use value_string for enum ctrl_type instead of custom code. Add
corresponding unit tests.

Related: OS#1615
Change-Id: Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28
2017-03-01 16:37:59 +00:00
Max 9756c4691d Fix client-side ctrl interface helpers
* remove unused ctrl_interface_connect() which is not part of public API
* add default read callback to osmo_ctrl_conn_alloc()

Change-Id: Iaa209e34a849ce0dfe2e29b482c3208ade1a32a4
Related: OS#1615
2017-03-01 16:37:59 +00:00
Holger Hans Peter Freyther a2c5811238 Export comp128 v2 and v3 routines as well
It is in the public header file and allows to easily bind it from
other languages (without having to go through the abstraction).

Change-Id: I0128d529c52ec030cfb87b0aff3c69cadf2c59d2
2017-02-27 16:54:00 +07:00
Harald Welte a1004640ce libosmoctrl: Fix typo in ctrl_interface_connect()
it's osmo_sock_init_ofd(), not osmo_sock_init_ifd()

Change-Id: Ia6a82031a691403f641815862613d99b31a3a159
2017-02-23 21:07:01 +01:00
Max fa9e05e7e8 Expand and expose ctrl connection allocation
Add function for allocating CTRL connection to public headers and
replace call to previous static function with it. Add doxygen docs for
this function.

It's useful if we need to allocate ctrl connection but don't need to
bind to any interfaces: when we act as ctrl client.

Related: OS#1615
Change-Id: I522ed809cbebfd3d7dd08b4ed9137b39ff192e32
2017-02-23 17:30:44 +00:00
Neels Hofmeyr 8b86cd76cf logging.h: fixup: shorter names for LOGGING_FILTER_* and LOGGING_CTX_*
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
2017-02-23 18:08:12 +01:00
Neels Hofmeyr 812ba6dc63 logging: centrally define ctx and filter indexes
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
2017-02-22 16:08:38 +00:00
Neels Hofmeyr 3b8cb39e7c fix osmo_auth_gen_vec_auts: copy rand to auth vector
Related: OS#1593
Change-Id: If943731a78089f0aac3d55245de80596d01314a4
2017-02-22 03:12:51 +01:00
Neels Hofmeyr 3a5ca647c5 gsup decode: fix expectation of AUTS length, should be 14
The wrong expectation caused OsmoHLR to fail on Auth Sync.

Change-Id: I277fb3d407396dffa5c07a9c5454d87a415d393f
2017-02-21 16:19:40 +01:00
Max 32ee5af893 Document ctrl_interface_setup_dynip() function
Change-Id: Ie1d5881dda7a9b797d15e9e1eead8281a994d91e
2017-02-19 08:54:27 +00:00
Neels Hofmeyr 8fcc81db66 fix: gprs_bssgp_vty: logging filter: wrong constant
Setting the BVC log filter to NULL worked only if the NSVC filter was set,
use the proper constant instead.

Change-Id: Ic1cc268ed20700698c93d3ff8bf85cc0f01d3b1b
2017-02-17 16:38:17 +01:00
Neels Hofmeyr 10f5fb49db gsup: add osmo_gsup_message_type_name()
Change-Id: Ic29b588b72893821d73fe90ecc16c6bf78d5a360
2017-02-15 23:26:07 +00:00
Neels Hofmeyr 437ed4ab42 osmo_hexparse: allow whitespace in parsed string, add ws test
This is particularly useful for hex dumps containing spaces found in a log
(e.g. osmo-nitb authentication rand token), which can now be passed in quotes
to osmo-auc-gen without having to edit the spaces away.

Change-Id: Ib7af07f674a2d26c8569acdee98835fb3e626c45
2017-02-14 15:59:22 +01:00
Philipp Maier 6f0f560eab cosmetic: replace fprintf with LOGP
socket.c still uses fprintf to output error messages. This commit
replaces the fprintf with proper LOGP messages.

Change-Id: Ia2993415d5f5c33ccd719af239ff59252d11b764
2017-02-09 16:21:01 +01:00
Vadim Yanitskiy 2c717948d9 utils/conv_gen.py: improve application flexibility
This change makes the conv_gen application more interactive
and flexible, allowing to generate not only code definitions
but also the test vectors and header files in the future.
Moreover, it becomes possible to select exact code family,
such as GSM, GMR etc.

Change-Id: I0b476b00234c17f78b41d695cf3bfd13edb64c28
2017-02-09 06:39:58 +00:00
Harald Welte f12d40f4df fix various compiler warnings (on FreeBSD-11.0)
FreeBSD 11.0 uses clang version 3.8.0 which spits various warnings
during libosmocore compilation.  Let's clean this up a bit.

Change-Id: Ic14572e6970bd0b8916604fabf807f1608fa07e5
2017-02-08 16:49:14 +01:00
Philipp Maier 6b986c2422 lapd_core: Fix MDL-ERROR ind after RELEASE ind
in lapd_t200_cb() The RELEASE INDICATION is transmitted before
the MDL ERROR INIDCATION, this prevents the MDL ERROR INDICATION
from being sent because the RELASE INDICATION close to connection
eraly. This commit puts the messages into the correct order.

Change-Id: Iae74777138fc27828f511e3aa321d1981861f4a5
2017-02-07 13:39:01 +01:00
Philipp Maier d9f6129350 lapd_core: fix program flow
when the lapd core is in state LAPD_STATE_SABM_SENT, and the
retransmission counter exceeds (link down) lapd_t200_cb() will
send an RELASE_INDICATION and an MDL_ERROR_INDICATION to L3.
This action is done before the state is processed. This seems
to be no problem with standard retransmission counts (n200),
but may cause timing problems that lead to deadlock states when
custom timer configurations are in use. (Ericsson RBS).

This commit moves the functions calls for sending the indications
mentioned above to the very end of the if branch to relax the
timing again. (See lapd_t200_cb())

Change-Id: I1c1beb3701b19744a3ce9946abca7767d20a0b6a
2017-02-07 13:39:01 +01:00
Philipp Maier b288853ffa select: add functionality to check socket state
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
2017-02-07 13:39:00 +01:00
Neels Hofmeyr 03ab9a6500 osmo_auth*: fix ordering of function args
milenage_gen_vec() has parameter ordering of (..., auts, rand_auts, rand).

osmo_auth_gen_vec_auts() has (..., rand_auts, auts, rand), but actually feeds
args in the same order, so that its rand_auts becomes auts, and its auts
becomes rand_auts.

Interestingly enough, API user osmo-gen-vec.c also adheres to this misordering
and in turn passes auts for osmo_auth_gen_vec_auts()'s rand_auts and vice
versa, so that it matches milenage_gen_vec().

So both the implementation (milenage_*) and the API user use the same ordering,
just osmo_auth_gen_vec_auts() and osmo_auth_impl{ .gen_vec_auts() } in-between
have the argument names swapped.

Any current user of this API would need to adhere to this swapping or will not
get successful AUTS resolution to a SQN. So the least impact fix is to rename
the args without any actual functional change.

So swap the names rand_auts and auts for osmo_auth_gen_vec_auts() and
osmo_auth_impl{ .gen_vec_auts() }. (Also adjust API doc ordering)

Change-Id: I0dcbd49759fc32d3b8974102dbd1d6703364ebf4
2017-02-06 14:09:31 +00:00
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