Commit Graph

712 Commits

Author SHA1 Message Date
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
Vadim Yanitskiy 77a5b0946f gsm0503.h: generate header automatically
Since we have automatic header generation, implemented in the
utils/conv_gen.py, it's time to use this feature!

Change-Id: I21caa4e433b2cc1861611e35350a9671da444c2a
2017-03-06 17:06:45 +00:00
Neels Hofmeyr fca04bba5a fsm: convenience: add inline osmo_fsm_inst_state_name()
Change-Id: If9a6ecc4d6e2beaf716569e9a6053d73488e860b
2017-03-01 23:52:55 +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
Neels Hofmeyr fa5dc93fd0 ports.h: rename CSCN to MSC
See OS#1958

Change-Id: I85aee0f8fdfc9c69d0ba9240988c633d3e707f2d
2017-02-24 19:57:48 +00: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 492e1808b0 logging.h: fixup: add API doc for logging enums recently added
Change-Id: Ic459b04219abe70171c8f80ed09df53d412dcfb2
2017-02-23 17:53:23 +01:00
Neels Hofmeyr 0d6420b302 logging.h: fix backwards compat broken by recent commit
Commit 812ba6dc63
"logging: centrally define ctx and filter indexes"
Removed definitions, which causes older e.g. openbsc and osmo-pcu code trees to
fail to build against a newer libosmocore. Re-introduce the legacy definitions
to redirect to the new ones and re-establish backwards compatibility.

The GPRS_* constants used to be defined in gprs_msgb.h, but since that header
also includes logging.h, rather place the legacy shims in logging.h next to the
other ones.

Change-Id: I455bb1bb474d758af0fd5b6397f7e57260ad739d
2017-02-23 17:53:07 +01:00
Neels Hofmeyr d1c2fc6de1 gsm_04_08.h: add R99 MSCR and CBQ3 to SI3 Ctrl Chan Descr
MSCR and CBQ3 are Release 1999 additions to the Control Channel Description IE
of SI3.

Assuming that no-one is using the spare bits, this will not cause any code
conflicts.

In the R99 struct, spare1 and spare2 are in different places, so rather rename
them to spare_1 and spare_2 to make sure we get a compiler barf *if* anyone
tries to use them with the wrong structure.

Adjust the spec reference to TS 44.018; TS 04.08 Figure 10.5.33 is replaced by
TS 44.018 Figure 10.5.2.11.1 which is right there in the named Section
10.5.2.11, so drop the explicit reference.

Motivation: the R99 Control Channel Description defines MSCR to indicate
whether the MSC is R99+ or not. To use UMTS AKA on GSM networks, we want to
indicate that our libmsc is capable of R99, like OsmoSGSN already does.

CBQ3 is merely added for completeness, no particular use case in mind.

Related: OS#1593
Change-Id: If87e07b5d04e1617155383e14c98d2125fdd0608
2017-02-23 03:39:36 +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 10f5fb49db gsup: add osmo_gsup_message_type_name()
Change-Id: Ic29b588b72893821d73fe90ecc16c6bf78d5a360
2017-02-15 23:26:07 +00:00
Max af4bb17a93 Add CTRL port for OsmoHLR
Change-Id: I1328c89ec8e908bf4b4d2c0a398690278369e0f5
Related: OS#1645
2017-02-14 12:13:32 +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
Neels Hofmeyr 55a43b8013 gsm48: add UMTS AKA res+sync IEIs, msg type and cause val
According to 3GPP TS 24.008 9.2.3a, 9.2.3, 10.5.3.6

Change-Id: I745061ce8eb88aa23080dadcdbfe2d703c362a30
2017-02-02 20:34:16 +01: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
Neels Hofmeyr 4a7f87cdc8 comment: ports.h: more visibly remind to keep docs+wiki synced
It is still too easy to forget syncing, so add another reminder at the end
of the list.

Change-Id: I95191906afa8e6ada31310d0e36de33e3fccf268
2017-01-30 12:57:47 +01:00
Neels Hofmeyr 92fa18e6b8 vty/ports.h: reserve port 4258 for OsmoHLR VTY
Change-Id: I08cb52d9399a27e6876e45da36f434708c4fddef
2017-01-28 04:02:53 +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
Harald Welte 75c0e2f371 utils.h: #include <stdio.h> as we use fprintf()
Change-Id: I911c7f4bcadde414ce0b384e13a3a9a4a953e2fb
2017-01-23 12:20:33 +00:00
Neels Hofmeyr 505a22fc51 linuxlist.h: add llist_count()
After subchan_demux.c in libosmo-abis, osmo-bts/common/vty.c and openbsc's
gtphub_test.c, more places would like to count the llist items (mostly unit
tests). Instead of proliferating numerous local implementations, add here.

NOTE: other than the previous llist_len() implementations, this one returns an
*unsigned* length, which might need some adjusting of current callers.

Call this llist_count() rather than llist_len() to highlight the fact that this
is actively iterating. This also avoids a potential naming conflict when
library versions mismatch.

Change-Id: Ic49adc7a346f5722bf624d7d3b4a735e4220ae15
2017-01-21 01:12:32 +01:00
Max aa1bc012c8 logging: remove code duplication
* make DEBUGP* macro into simple wrappers around LOGP*
* deprecate unused logp() function

Related: OS#71
Change-Id: Ia6c92bd4824c44fc22cc733ce7a88da86e58ed93
2017-01-16 14:12:13 +00:00
Max 8928747a3e CTRL: add write-only helpers
Similar to CTRL_CMD_DEFINE_RO() add helper for control commands which
are not meant to be read, only to set. Similarly, add
CTRL_CMD_DEFINE_WO_NOVRF() for commands which do not perform inbound
data verification.

Change-Id: I66b7990db590c1f8e56326e392e6c1d2eafebd9a
2017-01-16 08:54:17 +00:00
Harald Welte 449324b264 bitvec: Ensure bitvec.h and bitvec.c agree on function argument type
uint32_t may or may not be unsigned int.

Change-Id: I21c96985fcbb72372b6df949301c21f1ebca41f2
2017-01-15 18:04:02 +01: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
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 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 ebcf02de6c gsmtap: Add GSMTAP_TYPE_QC_DIAG
This adds a definition for wrapping Qualcomm DIAG frames into GSMTAP for
transporting them over an IP network.

Change-Id: I1b357b7d11a370685671c7b01e55f4f36dec2f25
2017-01-09 13:19:16 +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
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
Minh-Quang Nguyen 592fcc97c0 Add cause enum for OML fail reports
Add 3GPP TS 12.21 §9.4.43 Probable Cause values of type 03 (Manufacturer
specific values).

Max's note: renamed to make it clear that values are vendor-specific.

Related: OS#1615
Change-Id: Ie9ba4b53fb19a151447aec9ea309284e20613585
2017-01-06 10:21:11 +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
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
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
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
Neels Hofmeyr 42b59c1bf0 fsm api doc: fix typo in doxygen marker '\breif'
Change-Id: I5c57e35b29d50cb409becada6b9b120ce5210ae0
2016-12-20 12:39:32 +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 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
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
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
Harald Welte a65e99331a gsmtap: Add defintions for GSMTAP based remote logging
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
2016-12-09 17:59:58 +01:00