Commit Graph

1111 Commits

Author SHA1 Message Date
Vadim Yanitskiy 80f4ff9368 core/utils.h: drop duplicate '<stdbool.h>' include
Change-Id: I0979ddda91c4c0aa080b714cf2a698d7634f5091
2018-09-05 02:57:25 +07:00
Harald Welte b99ed7ff18 Add RSPRO support to IPA and logging definitions
Change-Id: Iee79f5273f32cb9ce4bd7a984e7f0625542e776f
2018-09-03 14:21:54 +02:00
Keith Whyte 3cdaa8d525 Add CC_CAUSE value_string array
Adds a value_string array for GSM 04.08 Call Control
cause values

Change-Id: I296f208581ce2550805f9d96e20f7319e1199023
2018-09-02 12:33:54 +02:00
Neels Hofmeyr 77ae45d22f log: add 'last' option to 'logging print file'
Allow printing the source file information *after* the log information.

Add target->print_filename_pos, log_set_print_filename_pos() and enum
log_filename_pos, and the optional 'last' keyword to the 'logging print file'
vty command. (An enum in case we want to add other positions later.)

Rationale: on log lines, the logging context is usually printed first in the
logging text. Without the source file information, this logging context pretty
much aligns in an easily readable way. When adding the source file information,
each line's logging context info is shifted right by a pretty much random
amount and it is hard to spot recurring logging contexts.

One solution is to switch off source file info, of course, but that's not an
option when actively hacking on bugs and new features.

For example, it is unnecessarily hard to spot lchan FSM related log lines in
this osmo-bsc log snippet:

DRSL NOTICE mgw_endpoint_fsm.c:603 mgw-endpoint(conn0){WAIT_MGW_RESPONSE}: Freeing instance
DRSL NOTICE fsm.c:381 mgw-endpoint(conn0){WAIT_MGW_RESPONSE}: Deallocated
DMSC NOTICE mgw_endpoint_fsm.c:603 SUBSCR_CONN(conn0){CLEARING}: Received Event FORGET_MGW_ENDPOINT
DCHAN DEBUG lchan_rtp_fsm.c:741 lchan(0-0-1-TCH_F-0){WAIT_RLL_RTP_ESTABLISH}: Received Event LCHAN_EV_RTP_RELEASED
DCHAN DEBUG lchan_rtp_fsm.c:520 lchan_rtp(0-0-1-TCH_F-0){ROLLBACK}: Freeing instance
DCHAN DEBUG fsm.c:381 lchan_rtp(0-0-1-TCH_F-0){ROLLBACK}: Deallocated
DCHAN DEBUG lchan_rtp_fsm.c:520 lchan(0-0-1-TCH_F-0){WAIT_RLL_RTP_ESTABLISH}: Received Event LCHAN_EV_RTP_RELEASED
DCHAN DEBUG lchan_fsm.c:1232 lchan(0-0-1-TCH_F-0){WAIT_RLL_RTP_ESTABLISH}: state_chg to WAIT_RF_RELEASE_ACK
DRSL NOTICE handover_fsm.c:762 handover(interBSCin_conn0){WAIT_RR_HO_DETECT}: Terminating (cause = OSMO_FSM_TERM_REGULAR)
DRSL NOTICE handover_fsm.c:762 handover(interBSCin_conn0){WAIT_RR_HO_DETECT}: Freeing instance
DRSL NOTICE fsm.c:381 handover(interBSCin_conn0){WAIT_RR_HO_DETECT}: Deallocated
DCHAN DEBUG lchan_fsm.c:1196 lchan(0-0-1-TCH_F-0){WAIT_RF_RELEASE_ACK}: state_chg to BORKEN
DCHAN DEBUG lchan_fsm.c:354 lchan(0-0-1-TCH_F-0){BORKEN}: (type=TCH_F) Clearing lchan state
DLMGCP DEBUG mgcp_client.c:741 Tx MGCP msg to MGCP GW: 'DLCX 3 2@mgw MGCP 1.0'
DLMGCP DEBUG mgcp_client.c:743 Sending msg to MGCP GW size: 66
DRLL NOTICE mgcp_client_fsm.c:422 MGCP_CONN(to-BTS){ST_DLCX_RESP}: Received Event EV_DLCX_RESP

Placing the source file info behind the log text makes it much easier to
follow, while the source file info is still available:

DRSL NOTICE mgw-endpoint(conn0){WAIT_MGW_RESPONSE}: Freeing instance (mgw_endpoint_fsm.c:603)
DRSL NOTICE mgw-endpoint(conn0){WAIT_MGW_RESPONSE}: Deallocated (fsm.c:381)
DMSC NOTICE SUBSCR_CONN(conn0){CLEARING}: Received Event FORGET_MGW_ENDPOINT (mgw_endpoint_fsm.c:603)
DCHAN DEBUG lchan(0-0-1-TCH_F-0){WAIT_RLL_RTP_ESTABLISH}: Received Event LCHAN_EV_RTP_RELEASED (lchan_rtp_fsm.c:741)
DCHAN DEBUG lchan_rtp(0-0-1-TCH_F-0){ROLLBACK}: Freeing instance (lchan_rtp_fsm.c:520)
DCHAN DEBUG lchan_rtp(0-0-1-TCH_F-0){ROLLBACK}: Deallocated (fsm.c:381)
DCHAN DEBUG lchan(0-0-1-TCH_F-0){WAIT_RLL_RTP_ESTABLISH}: Received Event LCHAN_EV_RTP_RELEASED (lchan_rtp_fsm.c:520)
DCHAN DEBUG lchan(0-0-1-TCH_F-0){WAIT_RLL_RTP_ESTABLISH}: state_chg to WAIT_RF_RELEASE_ACK (lchan_fsm.c:1232)
DRSL NOTICE handover(interBSCin_conn0){WAIT_RR_HO_DETECT}: Terminating (cause = OSMO_FSM_TERM_REGULAR) (handover_fsm.c:745)
DRSL NOTICE handover(interBSCin_conn0){WAIT_RR_HO_DETECT}: Freeing instance (handover_fsm.c:745)
DRSL NOTICE handover(interBSCin_conn0){WAIT_RR_HO_DETECT}: Deallocated (fsm.c:381)
DCHAN DEBUG lchan(0-0-1-TCH_F-0){WAIT_RF_RELEASE_ACK}: state_chg to BORKEN (lchan_fsm.c:1196)
DCHAN DEBUG lchan(0-0-1-TCH_F-0){BORKEN}: (type=TCH_F) Clearing lchan state (lchan_fsm.c:354)
DLMGCP DEBUG Tx MGCP msg to MGCP GW: 'DLCX 3 12@mgw MGCP 1.0' (mgcp_client.c:741)
DLMGCP DEBUG Sending msg to MGCP GW size: 67 (mgcp_client.c:743)
DRLL NOTICE MGCP_CONN(to-BTS){ST_DLCX_RESP}: Received Event EV_DLCX_RESP (mgcp_client_fsm.c:422)

Implementation: for 'last', insert source file info only when an '\n' is found
at the end of the log line composition buffer, so that LOGP()...LOGPC()
constructs also print source file info only when a log line actually ends.

Change-Id: I393907b3c9e0cc1145e102328adad0a83ee13a9f
2018-08-27 20:52:04 +02:00
Philipp Maier 73196e77fb socket: add flag to enforce SO_REUSEADDR on UDP sockets
When IPPROTO_UDP is used then SO_REUSEADDR omitted since UDP is
connection less we do not have to wait until lingering connections time
out. There were also negative effects such as that two applicatications
could use the same UDP port, normally one of the two applications would
get an error, but with SO_REUSEADDR this is supressed. However, there
are applications (UDP MULTICAST) where two applications must be able to
use the same port. In the osmocom project those are osmo-bts-virtual,
virtphy and gsmtap in general.

Lets introduce a flag that the API user can supply in order to have
SO_REUSEADDR applied.

- Add new flag OSMO_SOCK_F_UDP_REUSEADDR

Change-Id: I94aaf6d5224ab23bde5ea5c4a83569b6145ab32b
Related: OS#3497
2018-08-23 20:17:45 +02:00
Neels Hofmeyr 983dcb9af3 use __FILE__, not __BASE_FILE__
The intention was to use the file's basename, but __BASE_FILE__ means "the root
file that is being parsed and contains #include statements".

If we had a function using __BASE_FILE__ and that was defined in an #included
file, __BASE_FILE__ would indicate the first file where the #include is, and
not the file where the function is defined. __BASE_FILE__ works for us because
we don't ever include function definitions that log something, so __BASE_FILE__
always coincides with __FILE__ for our logging; but still __BASE_FILE__ is
semantically the wrong constant.

Related: OS#2740
Change-Id: Ibc1d3746f1876ac42d6b1faf0e5f83bd2283cdcc
2018-08-20 20:23:18 +00:00
Pau Espin 8ce6f488b6 msgb: Introduce msgb_{de,en}queue_count APIs
It's a common pattern having a list of msgb and having to maintain its
size (for instance, to limit the maximum size of the list). Having the
counter updated at the same time that the msgb is enqueued or dequeued
helps avoiding introducing new bugs by forgetting to update the size
counter at the right places.

Change-Id: I33b501e89a8f29e4aa121696bcbb13d4b83db40f
2018-08-17 10:34:15 +02:00
Pau Espin 0b6fcb0349 signal: Introduce API osmo_signal_talloc_ctx_init
Otherwise applications need to use "extern void* tall_sigh_ctx" and set
it manually (that symbol is not exported in any header file) or end up
allocating struct signal_handler into the NULL talloc ctx.

API created in a similar way as already existing msgb_talloc_ctx_init(),
but without the pool_size because it's not considered necessary in this
case.

Change-Id: Id58ca18eb826b8f4183a7cf0dbb2b38cba702a09
2018-08-16 21:03:32 +02:00
Alexander Couzens acc0a070c7 bssgp: introduce flush queue functions
To reset the state of BSSGP allow to flush the BSSGP queues.
When testing (with TTCN3) the test object should be resetted between
each test.

Introduce the functions:
bssgp_fc_flush_queue() - flushs a single flow control object
bssgp_flush_all_queues() - flushs queues of all BSSGP connections

Change-Id: I29b6ad6742ddf9b0b58b4af37d9a1cf18e019325
2018-08-10 06:55:43 +00:00
Vadim Yanitskiy 30cfeeb4a0 libosmogsm: (re)introduce gsm48_push_l3hdr()
There was gsm0480_l3hdr_push() declared in a header file, but
not exposed in 'libosmogsm.map'. Furthermore, for some reason
it was a part of GSM 04.80 API, what is not actually correct.

Let's rename this symbol, and properly expose it as a part of
the GSM 04.08 API. Also, let's introduce an auxiliary wrapper
for messages, where the transaction identifier is required
(see GSM 04.07, section 11.2.3.1.2).

Change-Id: I8a045efe8335d83fcbe8d43eb180972e3b1d9dda
2018-08-05 23:21:43 +07:00
Harald Welte 5a7740d1db re-introduce ipa_ccm_idtag_parse_off()
In the previous commit we deprecated ipa_ccm_idtag_parse() but
also removed ipa_ccm_idtag_parse_off(), for which I couldn't find
any users.  However, legacy openbsc.git still uses this function,
so let's re-introiduce it in its original form.

Change-Id: Ibfe53b04340eb355c8bfb8453a2af1522a4b6baf
2018-08-01 17:42:06 +02:00
Harald Welte 7869baf843 Deprecate ipa_ccm_idtag_parse() with ipa_ccm_id_{get,resp}_parse()
In the past, the function ipa_ccm_idtag_parse() was used to parse
the payload of IPA CCM ID RESP packets.  However, the function was
based on a possible misunderstanding of the message encoding, and
callers actually counted the first (upper) length nibble as part
of the header and passed a pointer to the second
(lower) length nibble of the first TLV into this function.  As such,
it was unfixable, and had to be replaced with a new function called
ipa_ccm_id_resp_parse().  At the same time, we also add
ipa_ccm_id_get_parse() to parse the slightly different format of
the IPA CCM ID GET payload.

We can never be 100% sure what is "correct", as our understanding
of the protocol is entirely based on protocol analysis, without any
official documentation available.

This patch also introduces unit test coverage for both of the new
functions.

Revert "ipa: Add libosmogsm.map entry for ipa_ccm_idtag_parse_off"
This reverts commit 7f31c90b80.

Revert "ipa: Properly parse LV stream of a ID_GET request"
This reverts commit f558ed4bb9.

It introduced a function/behavior that was not originally intended:
The parse of IPA CCM ID GET (8bit length followed by 1 byte tag
and variable-length payload) instead of the IPA CCM ID RESP (16bit
length followed by 1 byte tag and variable-length payload).

Change-Id: I1834d90fbcdbfcb05f5b8cfe39bfe9543737ef8f
2018-08-01 13:38:17 +02:00
Harald Welte 9b04c17c7a oap_client: Rename symbols with osmo_ prefix
As we're moving this to a common/shared library now, we need to use
the osmo_ namespace prefix for symbol names, struct/type names and
constants.

Change-Id: Ie36729996abd30b84d1c30a09f62ebc6a9794950
2018-07-30 12:50:51 +02:00
Harald Welte fdd366ed1b import oap_client into libosmogsm
This imports the code from osmo-msc 6afef893e17bce67e4d4119acd34d480ed03ba77
with minimal changes to make it compile.  Symbol renaming to osmo_
prefix is done separately in a follow-up patch to have a as-clean-as-possible
import first.

Change-Id: I9bc38102318da02d1fe46ef516df3cfd6bf8e3da
2018-07-30 12:16:11 +02:00
Harald Welte 7ecc4a3171 04.80: New gsm0480_gen_{reject,return_error}() functions
Add functions to generate TS 04.80 (supplementary services)
Reject and ReturnError components.

Change-Id: I6e5ee39c3d03364f7833ec717593d5ddb0a4c5f9
2018-07-29 14:39:36 +00:00
Harald Welte b0d9594081 USSD: Introduce gsm0480_gen_ussd_resp_7bit()
Contrary to the existing gsm0480_create_ussd_resp(), the new function
only generates the value part of the FACILITY IE, and not the IE
Tag/Length or the 04.08 L3 header.  This is needed in the context of
GSUP-encapsulated USSD, as here we don't work with L3 messages, but
only pass on the FACILITY IE value.

Change-Id: Ide240279240322f643e142229eb7829f538c6314
2018-07-29 14:39:36 +00:00
Harald Welte 88fa5a3e1e gsm0480: Factor out msgb allocation helper function
Change-Id: If25b467481023eadaaf3f78157eceff4b81d24d2
2018-07-29 14:39:36 +00:00
Kevin Redon 0bc3b83654 GSMTAP: add SIM sub_types
In SIMtrace 1 the ATR was sent the same way as an APDU.
The ATR is not an APDU, and could be mis-interpreted as valid APDU.
This change allows to make the difference between actual APDU and
the ATR, but also adds sub_types for future SIMtrace 2 use cases.

Change-Id: I5bd0dff5a4a90cfe96d9c4f3dec6657e1d85bf7a
2018-07-27 17:19:47 +00:00
Harald Welte 83361bd963 gprs_ns.h: Declare gprs_ns_cause_str() which already existed in c file
Change-Id: Ia95f0cc8d110f95814173bb5a1c11bd85d8cd533
2018-07-22 15:14:58 +02:00
Neels Hofmeyr 59f4caf4ef add osmo_sockaddr_to_str_and_uint()
This came from osmo-bsc refactoring patch I82e3f918295daa83274a4cf803f046979f284366
https://gerrit.osmocom.org/#/c/osmo-bsc/+/9671/6/src/osmo-bsc/gsm_data.c@1708

Add regression test in utils_test.c.

Change-Id: I1f2918418c38918c5ac70acaa51a47adfca12b5e
2018-07-20 14:02:21 +00:00
Pau Espin 239ed3b3ee ctrl: Introduce ctrl_cmd_parse3 API
Callers require to know whether the returned ERROR cmd was received or
generated locally, in order to send it or do something with it locally.

Related: OS#3394

Change-Id: Ide9170e5c31967c353f8fe4e8227e64130b91eae
2018-07-16 17:56:25 +00:00
Pau Espin f2cda621c0 gsm0808: Add value_string for encryption algorithms
Change-Id: Iadf6460c438d02c53c2eaa9e42d51844ad28859a
2018-07-12 20:58:23 +02:00
Philipp Maier cdd05816da gsm_08_08: gsm0808_permitted_speech does not have value strings
enum gsm0808_permitted_speech does not have any value strings. Lets
add value strings to make debugging easier.

Change-Id: I5b5612a5df2758b0137a34c17f7c8c2b3f07c806
2018-07-12 18:18:39 +00:00
Philipp Maier 5796a218db gsm_04_08: add function to get value string
The value string table gsm48_chan_mode_names[] lacks a function
to get the value string by a value. Lets add one.

Change-Id: I0757bcc278c140e18249e35864338e19cdaa3cf7
2018-07-12 18:18:39 +00:00
Vadim Yanitskiy 94c0031297 Don't enforce Python 2 for utilities
The conv_gen.py utility was tested against both Python 2 and 3,
so there is no need to enforce Python 2. Also, having:

  #!/usr/local/bin/python{2|3}

is a bad idea, because Python may be installed in a different location.

Change-Id: I6007d481047b584db13d6eda70fb99f11f9ddaa1
2018-07-02 20:30:31 +07:00
Harald Welte bc568d0b9f osmo_panic(): Annotate as __attribute__ ((noreturn))
In Change-Id I5a70eb65952cbc329bf96eacb428b07a9da32433 we redirected
all OSMO_ASSERT() via osmo_panic().  However, this caused various
applications to have build failures, as OSMO_ASSERT() now appeared
to be able to return to the call site.  Let's inform the compiler
explicitly that there's no return from osmo_panic().

Change-Id: I8adf4c7b0ee6a4581cef8dd4e9f6a1dfde70ee55
2018-06-29 20:32:57 +02:00
Harald Welte 459a180877 Don't call abort() directly, always use osmo_panic()
A loooong time ago, we introduced osmo_panic() as a wrapper around
abort().  The advantage is, that this wrapper can be overridden, and
that it will also work in embedded (bare iron) targets, where the
abort simply translates to an infinite loop.

Change-Id: I5a70eb65952cbc329bf96eacb428b07a9da32433
2018-06-28 10:57:42 +02:00
Neels Hofmeyr 60f3153125 add and tweak inter-BSC HO API
Add:
gsm0808_create_handover_detect()
gsm0808_create_handover_complete()
gsm0808_create_handover_failure()

To existing structs gsm0808_old_bss_to_new_bss_info and
gsm0808_handover_required, add a final 'more_items' flag that makes future
extensions API and ABI compatible.

Fix the msgb string for Handover Request Ack.

Extend some API doc comments.

Related: OS#2283 (inter-BSC Handover, BSC side, MT)
Change-Id: I03ee7ce840ecfa0b6a33358e7385528aabd4873f
2018-06-18 17:32:58 +00:00
Harald Welte b1a35d63b9 gsm 04.80: Add value_string for component type and op code
Change-Id: I2615a88db5224d65f37c7cc505e183ec8b196e8a
2018-06-16 18:39:59 +02:00
Harald Welte 6a6a609309 gsup: Add value_string for Session State IE
In Change-Id I1cee271fed0284a134ffed103c0d4bebbcfde2a8 we added support
for a new session state IE, but we didn't add any value_string array
for string conversion of it.  Let's fix this.

Change-Id: I3d9f087786dc37c42498fa9a2be07483ec93ba7b
2018-06-16 11:11:08 +02:00
Daniel Willmann f1318fe371 Add function gprs_nsvc_state_append
A common function to append the nsvc state from osmo-sgsn or osmo-gbproxy

Change-Id: I7f0eaff7329ab98cad792d30b20ab053007aab85
2018-06-14 17:43:31 +02:00
Harald Welte 520ebc17d9 gsup: Add osmo_gsup_get_err_msg_type() function
This function can be used to resolve the error message type for
a given message type.  Can be used by generic error handlers that
work for any incoming message type.

Change-Id: Ic637bec53dd7fe3ec83da99b49b4eae34d5602b2
2018-06-11 20:28:18 +02:00
Vadim Yanitskiy 5a09f75c1e gsm/gsm0480: refactor and expose gsm0480_parse_facility_ie()
This function can be used when there is only a part of GSM 04.80
message available - Facility IE, e.g. when a message is carried
over GSUP/MAP. Let's expose it.

Refactoring includes the following:

  - adding the 'gsm0480_' prefix;
  - correcting inverted return value;
  - cosmetic code style changes.

Change-Id: I623c39ffbe6cdee65eade8435a2faa04d0da193e
2018-06-11 23:50:00 +07:00
Vadim Yanitskiy 52e44121db gsm/gsm0480.c: introduce gsm0480_extract_ie_by_tag()
In some cases, there is no need to parse the whole message,
e.g. during the conversion from DTAP to GSUP/MAP. This
function can be used to extract given IE from a message.

Change-Id: I3989d061903352473305f80712f1a1560d05df3d
2018-06-11 23:45:48 +07:00
Harald Welte 11eb4b5add vty: Add logging_vty_add_deprecated_subsys
This function permits the user to register deprecated log categories,
which will ensure that if log categories are removed from a program,
old config files will still load.

We simply dynamically allocate a cmd_element and install it at
CFG_LOG_NODE.  Not registering it at VIEW_NODE or ENABLE_NODE
ensures that it's not accessible from the interactive VTY, but only
from the config file / configure node.

Change-Id: I171f62ea2dc565b3a6c3eecd27fb7853e2529598
2018-06-09 17:43:33 +02:00
Harald Welte 3385e4b0c4 fsm: Change semantics of LOGPFSML() log-level
The general idea about each osmo_fsm_instance having a separate
log-level was to be able to selectively increase/show/enable logging
for some FSM instances (e.g. of a particular subscriber) while
maintaining normal logging verbosity for all other instances of the
same FSM.

The introduction of LOGPFSML() in Change-Id
If295fdabb3f31a0fd9490d1e0df57794c75ae547 broke that idea, as it would
use a compile-time log level, irrespective of the
osmo_fsm_inst.log_level setting of the given instance.

Let's combine the two:
Use the explicit level stated at LOGPFSML(), _unless_ this instance
has a higher log_level configured.

This way, all FSMs should normally be created with
osmo_fsm_inst.log_level == LOGL_DEBUG.  At that point LOGPFSM()
statements would be rendered at debug level, typically below the
threshold of most logging configurations.

Code that has explicit higher log levels like LOGPFSML(fi, LOGL_ERROR)
would always be printed, as it is an error message.

And if we now increase the osmo_fsm_inst.log_level, then even the normal
LOGPFSM() statements would suddenly be logged at that higher level,
selectively increasing log verbosity - like originally intended.

Change-Id: I1820f04d0c6f5d5ff08eb95b8c0e88764534491a
2018-06-08 10:22:41 +00:00
Neels Hofmeyr 94e4265f07 fix gsm0808_permitted_speech(): don't return HR3 for TCH_F + AMR
Change-Id: Icca23940791f97fa64dbc3f2734270b99f9550c1
2018-06-07 16:55:36 +02:00
Harald Welte 15a5f8de00 Add osmo_isqrt32() to compute 32bit integer square root
Change-Id: I2b96db6e037e72e92317fec874877e473a1cf909
2018-06-06 16:58:53 +02:00
Harald Welte 1fbe3eba75 tlv: Add TLVP_VAL_MINLEN() to obtain value _if_ length is >= minimum
This is a combination of TLVP_VAP() and TLVP_GET_MINLEN()

Change-Id: Ic5a177941219ebc3a3bceb3f68bdb3b2cacb934b
2018-06-02 12:53:29 +00:00
Harald Welte ebd362dbd2 gsm0808: Add value_string for LCLS related IEs
Change-Id: I18d7a29496929c761aeaba9c0aee847befc13108
2018-06-02 14:44:09 +02:00
Neels Hofmeyr 407df02e7c add osmo_fsm_inst_state_chg_keep_timer()
Change-Id: I3c0e53b846b2208bd201ace99777f2286ea39ae8
2018-05-31 21:01:33 +00:00
Vadim Yanitskiy 36c7b33ccc GSUP: introduce new messages for SS/USSD payloads
In order to be able to transfer SS/USSD messages via GSUP,
this change introduces the following new message types:

  - OSMO_GSUP_MSGT_PROC_SS_*,

and the following new IE:

  - OSMO_GSUP_SS_INFO_IE

which represents an ASN.1 encoded MAP payload coming to/from
the mobile station 'as is', without any transcoding.

Change-Id: Ie17a78043a35fffbdd59e80fd2b2da39cce5e532
Related: OS#1597
2018-05-31 16:12:14 +00:00
Vadim Yanitskiy 72696040df GSUP: implement TCAP-like session management
Unlike TCAP/MAP, GSUP is just a transport layer without the
dialogue/context. This prevents us from having session based
communication, required e.g. for USSD. But we can emulate
TCAP dialogue by adding additional IEs, which would allow
to relate each message to a particular session.

This change introduces the following IEs:

  - OSMO_GSUP_SESSION_ID_IE,
  - OSMO_GSUP_SESSION_STATE_IE,

which optionally can be used to indicate that the message is
related to a session with given ID, and to manage session
state, i.e. initiate, continue, and finish.

Change-Id: I1cee271fed0284a134ffed103c0d4bebbcfde2a8
Related: OS#1597
2018-05-31 16:11:14 +00:00
Harald Welte 64e807c4bc gsm0808: Add encoding functions for LCLS BSSMAP messages
Change-Id: Ib83143e467df068b7d462a8e51d94b9d961ce18f
2018-05-30 01:36:04 +02:00
Harald Welte 2f51684e63 gsm_08_08.h: Add enum for LCLS config, control and status
Change-Id: I775aba59942fb6f34fb31b71d2f0f2ac5c3ae831
2018-05-30 01:36:04 +02:00
Daniel Willmann 07f075d197 ports.h: Add ctrl port for osmo-gbproxy
Change-Id: I46a1cef3013c9bbf9b5a6d64e83cd84568f2523c
2018-05-29 21:02:16 +02:00
Keith Whyte 05d3278c0e Add enum gsm48_progress_desc
From GSM 04.08
Section 10.5.4.21 / Table 10.5.127

Change-Id: I6574e8808aaf39fad8026290aa2cc657734e18b5
2018-05-28 15:10:16 +00:00
Neels Hofmeyr b662b36da0 add gsm0808_create_handover_request_ack()
Related: OS#2283 (inter-BSC Handover, BSC side, MT)
Change-Id: I692292a06c7d66004404560dc4ed933ca9107f9b
2018-05-27 22:04:17 +02:00
Neels Hofmeyr 70aba3ffe2 add support for gsm0808 HANDOVER REQUIRED message
Related: OS#2283 (inter-BSC Handover, BSC side, MO)
Change-Id: Idb6dc3eab0282158a17091d97ed77c1e2e3eb3c2
2018-05-27 22:04:17 +02:00
Neels Hofmeyr 38e58416b1 add gsm0808_cell_id_to_list()
The idea is to be able to add a gsm0808_cell_id to a gsm0808_cell_id_list2:
first convert it to a list, then re-use gsm0808_cell_id_list_add(). It will be
used by osmo-bsc to manage neighbor-BSS cell identifiers from VTY.

Change-Id: Ibf746ac60b1b1e920baf494b396658a5ceabd788
2018-05-27 21:54:12 +02:00
Harald Welte b4186824c2 ctrl: Add doxygen API documentation; generate html from it
Closes: OS#3293
Change-Id: I8dc2f24d4bf557ff7bb0f2f46881f9f8d9d7f86f
2018-05-26 21:58:15 +02:00
Keith Whyte adfa199b5d Add enum gsm48_cause_coding from GSM 04.08 Section 10.5.4.11
Change-Id: I3d9c8e117ad19f70a3273650d7c0f8280d7bdb9a
2018-05-26 10:22:08 +00:00
Stefan Sperling 97d3da2c59 introduce vty_out_rate_ctr_group_fmt() function
This new function can be used to print a rate counter group according
to a format string. The intention is to generalize and replace manual
printing of counters as implemented for the 'show statistics' VTY
command of osmo-bsc.

Related: OS#3245
Related: osmo-bsc commit 71d524c059c5a5c90e7cb77d8a2134c1c68b9cde (g#9217)

Change-Id: Idb3ec12494ff6a3a05efcc8818e78d1baa6546bd
2018-05-24 18:04:56 +02:00
Harald Welte dfd85137cf mncc: properly export osmo_mncc_name()
For some strange reason, the osmo_mncc_name() inline function
was not in the mncc.h header, but in the mncc.c file. Let's fix that.

Change-Id: I2c3666510c981dffa4ba25bed517fd7ebd1250f5
2018-05-24 12:19:45 +02:00
Thorsten Alteholz 0062a5fbbf fix spelling
Change-Id: I3ac92217f83279d5f987ab34eb18b2e6cb1c7812
2018-05-15 20:57:56 +00:00
Harald Welte 9da77abb6b isdnhdlc: Port from kernel to userspace
* prefix all symbols/constants with osmo_
* use stdint.h types instead of kernel types
* use Doxygen API documentation
* use Osmocom CRC16-CCITT functions
* use Osmocom bit-reversal functions
* integrate with Automake

Change-Id: I109085ab3e412c20b19cd42fb7137aa0e4167542
2018-05-11 21:57:46 +02:00
Harald Welte 85b9fbae7e import isdn4linux HDLC code from linux kernel
I've been importing from 94d7dbf108813ea45a91e27e9a8bd231d5a23fa7
but the isdnhdlc code hasn't seen any changes since 2012 anyway.

Change-Id: I3c58f9cb6921c2fdd0f2fcb11f622a0be88c7c63
2018-05-11 21:55:32 +02:00
Harald Welte ea4d8939af Add osmo_timerfd_* functions for osmo_fd-wrapped timerfd
Linux offers file descriptor based periodic (interval) timers,
which can achieve a higher precision than our userspace based
timers and which can be slave'd to CLOCK_MONOTINIC or other clock
sources.  Let's add some code for osmo_fd wrapped versions that
integrate well with our select() abstraction.

The code has been used in osmo-bts-trx since June 2017 (change-id
I51b19adde14ebb7ef3bb863d45e06243c323e22e), and I'm just renaming
and moving it to libosmocore here.  After a merge, the osmo-bts
implementations can be removed in favor if this one.

Change-Id: Ibeffba7c997252c003723bcd5d14122c4ded2fe7
2018-05-10 10:33:54 +02:00
Neels Hofmeyr afacc2be9f add gsm0808 channel enum to IE val conversion functions
Add:
- gsm0808_current_channel_type_1()
- gsm0808_permitted_speech()
- gsm0808_chosen_channel()
- gsm0808_channel_type_name()

gsm0808_permitted_speech() is moved from osmo-bsc's bssap_speech_from_lchan();
gsm0808_chosen_channel() is moved from osmo-bsc's lchan_to_chosen_channel();

Rationale: will be re-used by inter-BSC handover, makes sense to keep with the
other gsm0808 utils.

Related: OS#2283 (inter-BSC handover, BSC side)
Change-Id: I8a3cc5d4548e9a78d945d54c69ccced251edcec9
2018-05-08 20:32:56 +00:00
Stefan Sperling dda1d4511c define a constant for the max length of called party BCD IE
According to TS 24.008 10.5.4.7 the called party BSC number IE
has a maximum length of 43 octets.

This length is assumed inside osmo-hlr with a magic number:
uint8_t msisdn_enc[43]; /* TODO use constant; TS 24.008 10.5.4.7 */

This change makes libosmocore provide a constant which osmo-hlr can use.

Change-Id: Ia0bf6ceadcac38a8c75d166402b54058e5c6c6d4
2018-05-07 09:07:00 +00:00
Pau Espin 686eba9bfc control_if: Avoid heap-use-after-free in osmo_wqueue_bfd_cb
Imagine following scenario:
1- client connects to CTRL iface, a new conn is created with POLL_READ
enabled.
2- A non-related event happens which triggers a TRAP to be sent. As a
result, the wqueue for the conn has now enabled POLL_WRITE, and message
will be sent next time we go through osmo_main_select().
3- At the same time, we receive the GET cmd from the CTRL client, which
means POLL_READ event will be also triggered next time we call
osmo_main_select().
4- osmo_main_select triggers osmo_wqueue_bfd_cb with both READ/WRITE
flags set.
5- The read_cb of wqueue is executed first. The handler closes the CTRL
conn for some reason, freeing the osmo_fd struct and returns.
6- osmo_qeueue_bfd_cb keeps using the already freed osmo_fd and calls
write_cb.

So in step 6 we get a heap-use-after-free catched by AddressSanitizer:

20180424135406115 DLCTRL <0018> control_if.c:506 accept()ed new CTRL connection from (r=10.42.42.1:53910<->l=10.42.42.7:4249)
20180424135406116 DLCTRL <0018> control_cmd.c:378 Command: GET bts.0.oml-connection-state
20180424135406117 DLINP <0013> bts_ipaccess_nanobts.c:417 Identified BTS 1/0/0
20180424135406118 DNM <0005> abis_nm.c:1628 Get Attr (bts=0)
20180424135406118 DNM <0005> abis_nm.c:1628 Get Attr (bts=0)
20180424135406118 DCTRL <000e> osmo_bsc_ctrl.c:158 BTS connection (re)established, sending TRAP.
20180424135406119 DLCTRL <0018> control_if.c:173 close()d CTRL connection (r=10.42.42.1:53910<->l=10.42.42.7:4249)
=================================================================
==12301==ERROR: AddressSanitizer: heap-use-after-free on address 0x611000003e04 at pc 0x7f23091c3a2f bp 0x7ffc0cb73ff0 sp 0x7ffc0cb73fe8
READ of size 4 at 0x611000003e04 thread T0
    #0 0x7f23091c3a2e in osmo_wqueue_bfd_cb /home/osmocom-build/jenkins/workspace/osmo-gsm-tester_build-osmo-bsc/libosmocore/src/write_queue.c:65
    #1 0x7f23091ad5d8 in osmo_fd_disp_fds /home/osmocom-build/jenkins/workspace/osmo-gsm-tester_build-osmo-bsc/libosmocore/src/select.c:216
    #2 0x7f23091ad5d8 in osmo_select_main /home/osmocom-build/jenkins/workspace/osmo-gsm-tester_build-osmo-bsc/libosmocore/src/select.c:256
    #3 0x56538bdb7a26 in main /home/osmocom-build/jenkins/workspace/osmo-gsm-tester_build-osmo-bsc/osmo-bsc/src/osmo-bsc/osmo_bsc_main.c:532
    #4 0x7f23077532e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
    #5 0x56538bdb8999 in _start (/home/jenkins/workspace/osmo-gsm-tester_run-prod/trial-896/inst/osmo-bsc/bin/osmo-bsc+0x259999)

Fixes: OS#3206

Change-Id: I84d10caaadcfa6bd46ba8756ca89aa0badcfd2e3
2018-05-04 18:29:26 +02:00
Alexander Couzens 9f39d89c31 gsm_08_58.h: introduce RSL_IE_ERIC_PAGING_GROUP
Ericsson supports a RSL command to page and immediate assign
as single command. For paging a MS the BTS must know the
paging group.

Change-Id: I9194500e307ad69f8da07510bc965a7a5cd82a2a
2018-04-23 08:38:34 +00:00
Pau Espin 95959a8a86 gsm_08_58.h: Add Ericsson vendor-specific RSL message types
We are alredy doing the same way for ip.access and siemens ones, and
this way we avoid using the hardcoded value in osmo-bsc.

Change-Id: I7cb65f3ff1cfdbe4eee97b7545bcd13a38c72e25
2018-04-21 22:48:00 +02:00
Neels Hofmeyr a4399c8891 add gsm0808_cell_{id,id_list}_name() and friends
Provide comprehensive API to obtain string representations of Cell Identifiers
and -Lists.

Change gsm0808_test.c to use the new functions (which simplifies the output a
bit), so that we don't duplicate printing code in gsm0808_test.c, and so that
the not-so-trivial printing code is also tested.

In gsm0808_test, also test gsm0808_cell_id_list_name_buf()'s return value and
truncation behavior.

The rationale for gsm0808_cell_id_list_name(), i.e. printing an entire list of
cell identifiers, is that even though the maximum is 127 elements, a list of
more than a few elements is hardly ever expected in practice (even more than
one element isn't actually expected: either "entire BSS" or a single LAC). It
is thus useful to log the entire list when it shows up in Paging and Handover.

Change-Id: I9b2106805422f96c5cc96ebb9178451355582df3
2018-04-18 02:38:37 +02:00
Neels Hofmeyr 74e4ed6f36 tlv: add TLV_GET() and TLV_GET_MINLEN()
Rationale: so far we use code like

  if (TLVP_PRESENT(&tp, VERY_LONG_ENUM_VALUE_NAME_THAT_NEVER_ENDS)) {
  	val = TLVP_VAL(&tp, VERY_LONG_ENUM_VALUE_NAME_THAT_NEVER_ENDS);
	len = TLVP_LEN(&tp, VERY_L0NG_ENUM_VALUE_NAME_TH4T_NEVER_EMDS);
  }

This is a) very long and b) prone to picking the wrong name one of the three
times, which would use the wrong length or val without necessarily being
noticed. A safer and shorter, more readable pattern is:

  struct tlv_p_entry *e = TVLP_GET(&tp, VERY_LONG_ENUM_VALUE_NAME_THAT_NEVER_ENDS);
  if (!e)
        return -ENOENT;
  hexdump(e->val, e->len);

Change-Id: I445de17fc2daa3ab051f5708dd0cc185b23dc048
2018-04-18 02:38:37 +02:00
Vadim Yanitskiy 07bfd565a8 protocol/gsm_04_08.h: drop incorrect GSM48_PDISC_USSD
According to the GSM TS 04.07, section 11.2.3.1.1 "Protocol
discriminator", bits 1 to 4 of the first octet of a standard
L3 message contain the protocol discriminator IE.

Meanwhile, the GSM48_PDISC_USSD represents value 0x11, i.e.
0b10001, that requires 5 bits, and moreover it is not
documented anywhere. Let's drop it.

Change-Id: Ic4eb8a6db4ff1dfd535bd0c84e7acf1908422f64
2018-04-17 12:09:48 +00:00
Neels Hofmeyr 250e7f7d30 add gsm0808_{enc,dec}_cell_id
Clarify semantics and micro-optimise for the case of single Cell Identifer IEs.
Test in gsm0808_test.c

So far we have gsm0808_enc_cell_id_list2(), but there also exist instances of
single Cell Identifiers (3GPP TS 48.008 3.2.2.17).

It is possible to decode the same using the cell identifier list API, but this
forces the caller to also keep a full struct gsm0808_cell_id_list2 with all its
127 entries around.

E.g. for handover, there are two Cell Identifiers (Serving and Target); I'd
need two full cell id lists for each, and these would be dynamically allocated
for each handover operation, whether it uses them or not.

Related: OS#2283 (inter-BSC HO, BSC side)
Change-Id: I9f9c528965775698ab62ac386af0516192c4b0cc
2018-04-13 05:38:47 +02:00
Neels Hofmeyr a78b22ba20 add tlv_parse2(), capable of multiple instances of the same IE
Allow passing multiple struct tlv_parsed in an array, to allow parsing as many
repeated IEs as are expected by the caller.

From tlv_parse(), call tlv_parse2() with dec_multiple = 1 to yield the previous
behavior. tlv_parse() remains valid API.

An example of multiple IEs is the BSSMAP Handover Request, containing Cell
Identifier (Serving) and Cell Identifier (Target), both defined by 3GPP TS
48.008 3.2.2.17 with identical IE tags; both are mandatory.

Related: OS#2283 (inter-BSC HO, BSC side)
Change-Id: Id04008eaf0a1cafdbdc11b7efc556e3035b1c84d
2018-04-13 05:28:09 +02:00
Neels Hofmeyr 74663d97c6 add gsm0808_cell_id_list_add() to combine two cell identifier lists
This will be used by the upcoming neighbor_ident API in osmo-bsc, where the vty
interface allows composing neihbor BSS cell identifier lists, and we want to
allow adding individual items from individual user commands.

It will also be useful to accumulate cell identifiers in case a subscriber sees
multiple alternative cells from a neighboring BSS, and we want to pass these on
to the MSC in a Handover Required.

Related: OS#2283 (inter-BSC HO, BSC side)
Change-Id: I5781f5fa5339c92ab2e2620489b002829d206925
2018-04-13 05:28:09 +02:00
Neels Hofmeyr 43496206c1 add osmo_cgi_name()
This will be used by cell idenitifier list code, like upcoming neighbor_ident
VTY in osmo-bsc and regression tests.

Change-Id: Iebc5cdf61b697b1603900993fc265af3eca0cedf
2018-04-13 05:27:02 +02:00
Pau Espin c62fc2d20f msgb: msgb_pull: Abort when pulling more than avail size
Change-Id: I512ff2035ae7a929e6c96df82938cc1ddbcc4e2a
2018-04-11 20:14:08 +02:00
Pau Espin 9fa0912e5b msgb: msgb_get: Drop unneeded tmp var
Change-Id: I27bb2ab59408c9cd1363b3b5acb2263128c55732
2018-04-11 20:09:13 +02:00
Neels Hofmeyr bd6c8b5081 deprecate PLMN de-/coding functions incapable of 3-digit MNC with leading zeros
All our projects have seen patches to move to 3-digit MNC handling.

Furthermore, since our builds no longer break from deprecation warnings, I shall
no longer refrain from deprecating old API.

Change-Id: I55dfaf7ce74870de44120b26c42d45bb7b184341
2018-04-10 13:06:15 +02:00
Thorsten Alteholz cefce6688b fix issue on big endian architecture
OSMO_IS_LITTLE_ENDIAN is always defined and has a value of
either 0 or 1
as a result in byteswap.h the corresponding swap functions
will be always called, independent of the endianess

Signed-off-by: Thorsten Alteholz <osmocom@alteholz.de>
Change-Id: I4a09d2d8ccf155e70a3977ae1747758b6bc5125e
2018-04-09 17:32:11 +00:00
Neels Hofmeyr aead241df0 add gsm48_reject_value_names
There seems to be quite some confusion / overlap between enum
gsm48_reject_value, gsm48_gsm_cause and gsm48_gmm_cause. I tried to go with
gsm48_gsm_cause_names[], but e.g. GSM48_REJECT_CONGESTION is not represented.

Instead of attempting to mix/merge those enums, provide a separate value string
array for enum gsm48_reject_value.

This will be used by osmo-msc's libvlr (refactoring of FSM result handling),
I27bf8d68737ff1f8dc6d11fb1eac3d391aab0cb1.

Change-Id: I6661f139e68a498fb1bef10c266c2f064b72774a
2018-04-09 17:57:15 +02:00
Neels Hofmeyr a64c45a03e add osmo_fsm_inst_update_id_f()
In the osmo-msc, I would like to set the subscr conn FSM identifier by a string
format, to include the type of Complete Layer 3 that is taking place. I could
each time talloc a string and free it again. This API is more convenient.

From osmo_fsm_inst_update_id(), call osmo_fsm_inst_update_id_f() with "%s" (or
pass NULL).

Put the name updating into separate static update_name() function to clarify.

Adjust the error message for erratic ID: don't say "allocate", it might be from
an update. Adjust test expectation.

Change-Id: I76743a7642f2449fd33350691ac8ebbf4400371d
2018-04-09 17:57:15 +02:00
Neels Hofmeyr 04eb56f146 add osmo_quote_str(),osmo_quote_str_buf() and test
Rationale: with osmo_escape_str(), you get the escaped contents of the string,
but not so graceful handling of NULL strings. The caller needs to quote it, and
for NULL strings not quote it.

osmo_quote_str() is like osmo_escape_str() but always quotes a non-NULL string,
and for a NULL string returns a literal NULL, i.e. it should (tm) give the
exact C representation of a string.

That's useful in testing, to show exactly what char* situation we have, without
jumping through hoops like
  if (str)
  	printf("\"%s\"", osmo_escape_str(str, -1));
  else
  	printf("NULL");

Copy the unit test for osmo_escape_str() and adjust. To indicate that the
double quotes are returned by osmo_quote_str(), use single quotes in the test
printf()s.

I considered allowing to pick the quoting characters by further arguments, but
that complicates things: we'd need to escape the quoting characters. Just
hardcode double quotes like C.

Change-Id: I6f1b3709b32c23fc52f70ad9ecc9439c62b02a12
2018-04-09 15:56:14 +00:00
Neels Hofmeyr cdbc9afe5d ctrl: fix deferred commands (and hence fix osmo-bts-sysmo 'clock-info' cmd)
The CTRL interface has a ctrl_cmd_def_* API that allows deferring a CTRL
command reply until later. However, the command handling currently fails to
acknowledge this and deallocates the struct ctrl_cmd anyway.

Fix: in struct ctrl_cmd, add a defer pointer to be populated by
ctrl_cmd_def_make(). A cmd thus marked as deferred is not deallocated at the
end of command handling. This fix needs no change in calling code.

(Another idea was to return a different code than CTRL_CMD_HANDLED when the
command is to be deferred, but that would require adjusting each user of
ctrl_cmd_def_make(). The implicit marking is safer and easier.)

Show that handling deferred commands is fixed by adjusting the expectations of
ctrl_test.c's test_deferred_cmd() and removing the now obsolete exit_early
label.

One symptom of the breakage is that osmo-bts-sysmo crashes when asked to report
a trx's clock-info, which is aggravated by the fact that the sysmobts-mgr does
ask osmo-bts-sysmo for a clock-info.

The crash appears since Id583b413f8b8bd16e5cf92a8a9e8663903646381 -- it looked
like just fixing an obvious memory leak, which it did as shown by the unit
test, but deferred ctrl commands actually relied on that leak. Both fixed now.

Related: OS#3120
Change-Id: I24232be7dcf7be79f4def91ddc8b8f8005b56318
2018-04-05 03:11:49 +02:00
Vadim Yanitskiy a24ead0126 gsm0480: copy the raw USSD data, its DCS and length
As it was already documented before, the 'ss_request' struct has
a rudiment of deprecated 'ussd_request' struct - the 'ussd_text'
field. It represents the data either of an INVOKE component,
either of a RETURN_RESULT component, encoded as ASCII in case
if DCS is 0x0f (i.e. decoded by the code itself), otherwise
raw bytes 'as is'.

Previously, there was no possibility to distinguish between
ASCII and raw bytes with different DCS. Moreover, the payload
decoding is not desired in some cases.

Let's introduce the new fields, which will carry the raw
unmodified payload, its length and DCS (Data Coding Scheme).

Change-Id: Ia193d175021e145bb3b131290231f307dbefc64a
2018-04-04 20:22:13 +07:00
Vadim Yanitskiy 9fb7e3a9fb gsm0480: document the 'ss_request' structure
Change-Id: I22144dd759e0c1bb1965574b7ddd676606e5d6b7
2018-04-04 10:47:27 +07:00
Philipp Maier dbb7659208 gsm0808: Add value strings for BSSMAP cause codes
libosmocore has no value strings for BSSMAP cause codes yet.

- Add value strings for BSSMAP cause codes and a function
  to retrieve them

Change-Id: I313dd8d7b06374e1e35ddc18b7a42562d9e25d45
Related: OS#1609
2018-03-29 15:00:41 +02:00
Neels Hofmeyr 3d8b47fc5c fix logging talloc ctx: add osmo_init_logging2()
Deprecate osmo_init_logging() for the benefit of adding an explicit talloc
context argument to new function osmo_init_logging2().  Pass a ctx to
log_init() instead of hardcoded NULL.

Before now, *all* of our code uses a NULL ctx for logging, which amounts to
talloc "leaks" hit by address sanitizer builds on newer gcc (e.g. gcc 7.3.0 on
debian 9).

This commit helps fixing "leaks" detected in e.g. osmo-bsc unit tests by a
sanitize build with gcc (Debian 7.3.0-12) 7.3.0.

Change-Id: I216837780e9405fdaec8059c63d10699c695b360
2018-03-28 19:06:16 +02:00
Philipp Maier 7e27b14ef2 gsm_08_08: correct speech codec defaults
The speech codec defaults are not correct. The defaults recommended
in 3GPP TS 28.062, Table 7.11.3.1.3-2 are limited by 3GPP TS 48.008,
Section 3.2.2.103. Some defaults are actually reserved for future
use. Also the endianess of the 16 bit values is reversed.

- correct values so that they match the specification
- transmit bytes in the correct endianess

Change-Id: I6c3a34d39a375d71c4128fd38f06629e8b98b100
2018-03-23 11:59:29 +00:00
Harald Welte d86055b431 abis_nm: Introduce abis_nm_dump_foh()
This is a more modern way of printing the Abis OML Formatted Object
Header, without assuming that it would be used in a log statement
or prescribing the log level to be used.

Change-Id: I9b2c2afec28882b817d104d5b062651ade7aadd8
2018-03-17 11:28:31 +00:00
Stefan Sperling 11a4d9dd91 support for more cell ID list types in libosmocore
Introduce gsm0808_dec_cell_id_list2() with supports additional types of
cell identifier lists. The new parsing routines are based on similar
routines used by the paging code in osmo-bsc's osmo_bsc_bssap.c.

Likewise, introduce gsm0808_enc_cell_id_list2() with support for the
same additional types of cell identifier lists.

The old API using struct gsm0808_cell_id_list is deprecated.
The previous definition was insufficient because it assumed that all
decoded cell ID types could be represented with a single uint16_t.
It was declared in a GSM protocol header (gsm/protocol/gsm_08_08.h)
despite being a host-side representation of data in an IE.
The only user I am aware of is in osmo-msc, where this struct is used
for one local variable. osmo-msc releases >= 1.1.0 make use of this API.

While here, fix a small bug in a test:
test_gsm0808_enc_dec_cell_id_list_bss() set the cell ID type to 'LAC'
but obviously wants to use type 'BSS'.

Change-Id: Ib7e754f538df0c83298a3c958b4e15a32fcb8abb
Related: OS#2847
2018-03-13 14:28:15 +01:00
Philipp Maier bf86d71f58 features: define osmo_bts_*_feature() as static inline
The functions osmo_bts_set_feature() and osmo_bts_has_feature() are
currently defined as inline. Since inline is a hinting, the compiler
might choose not to inline the function. This eventually leads to
linker problems because the function is then defined multiple times.

- use "static inline" instead of "inline" only.

This patch is a follow up patch to
Change Id 680acae725

Change-Id: Iddd97415a17b06b69f69ddca2e2e296eb2f23a89
2018-03-05 17:37:46 +00:00
Neels Hofmeyr 4d68fd0955 gsm23003: add osmo_mcc_from_str()
I found myself often using osmo_mnc_from_str() to also decode an MCC and be
strict about it, but each time I felt the need to comment like "using
osmo_mnc_from_str() also for MCC". Rather formalize this properly.

Use a static inline function, no need to add more symbols to libosmo-gsm.

Change-Id: I020a4f11791c61742a3d795f782805f7b7e8733e
2018-03-05 04:28:04 +01:00
Philipp Maier 680acae725 features: move bts feature related functionality to libosmocore
osmo-bsc and osmo-bts share enums and value strings to describe
feature data that is exchanged via OML (manufacturer id) on startup.
Also the functions to set and get the respecitive bits in the feature
bitvectors are in osmo-bsc and osmo-bts. This is a code duplication
and should be resolved.

- add enum osmo_bts_features (replaces enum gsm_bts_features)
- add osmo_bts_features_descs (replaces gsm_bts_features_descs)
- add osmo_bts_set_feature (replaces gsm_btsmodel_set_feature)
- add osmo_bts_has_feature (replaces gsm_btsmodel_has_feature)

Change-Id: Id0c35aef11aa49aa40abe7deef1f9dbd12210776
2018-03-02 16:54:16 +01:00
Neels Hofmeyr ccfc387fb9 introduce GSM_MCC_MNC_INVALID
In some cases, we want to mark an unset MCC-MNC. Define uint16-max for this
purpose.

osmo-bsc code is already doing so with a -1 and using int data types, which
will become inconvenient with the new API that handles MCC and MNC as uint16_t.

Change-Id: Ieee7add0bd6d94cf84743a49794bbcd38561b72f
2018-03-01 13:00:56 +00:00
Pau Espin 87fade88bd timer: Introduce osmo_clock_gettime to override clock_gettime
Change-Id: I5bebc6e01fc9d238065bc2517058f0ba85620349
2018-03-01 12:33:02 +00:00
Neels Hofmeyr 721aa6ded9 gsm: add osmo_mnc_from_str(), osmo_mnc_cmp(), osmo_plmn_cmp() for 3-digit MNC
osmo_mnc_from_str() preserves leading zeros in the string and is useful for
VTY config parsing (osmo-bsc, osmo-msc, osmo-sgsn, osmo-pcu).

osmo_{plmn,mnc}_cmp() takes care of the slight intricacy of ignoring the 3-digit flag
if the MNC is anyway >99. Will be used by osmo-sgsn.git and osmo-bsc.git.  (All
current users just care about identical MNC, but a proper cmp doesn't hurt.)

Change-Id: Ib7176b1d65a03b76f41f94bc9d3293a8a07d24c6
2018-02-28 19:26:43 +01:00
Neels Hofmeyr c4fce1425e implement support for 3-digit MNC with leading zeros
Enable representing three-digit MNC with leading zeros. The MNCs 23 and 023 are
actually different; so far we treated both as 23. Re-encode an incoming BCD or
string of 023 as it were, i.e. not dropping the leading zero as 23.

Break ABI compatibility by changing the size and ordering of structs
gprs_ra_id, osmo_plmn_id, osmo_cell_global_id, ... by adding an mnc_3_digits
flag.

Change ordering in gprs_ra_id because the canonical oder is {Mobile Country
Code, Mobile Network Code}, so have the mcc member first.

ABI compatibility cannot be maintained for struct gprs_ra_id, since it is a
direct member of structs bssgp_bvc_ctx and bssgp_paging_info, and even just
adding a flag to the end would cause ABI changes of those structs. Similarly,
osmo_plmn_id is a direct member of osmo_location_area_id, and so forth.

Add new API to set and read this additional flag to preserve leading zeros:
- osmo_plmn_to_bcd(), osmo_plmn_from_bcd() after
  gsm48_mcc_mnc_to_bcd() and gsm48_mcc_mnc_from_bcd().
- gsm48_decode_lai2(), gsm48_generate_lai2() after
  gsm48_decode_lai(), gsm48_generate_lai().
- gsm0808_create_layer3_2() after gsm0808_create_layer3() and gsm0808_create_layer3_aoip().
- various osmo_*_name() functions in gsm23003.h (osmo_rai_name() still in
  gsm48.h close to struct gprs_ra_id definition). The amount and duplication of
  these may seem a bit overboard, but IMO they do make sense in this way.
  Though most code will soon see patches unifying the data structures used, in
  some cases (vty, ctrl) they are required singled out. Without these
  functions, the formatting ("%0*u", mnc_3_digits ?  3 : 2, mnc) would be
  duplicated all over our diverse repositories.

In various log output, include the leading MNC zeros.

Mark one TODO in card_fs_sim.c, I am not sure how to communicate a leading zero
to/from a SIM card FS. The focus here is on the core network / BSS.

To indicate ABI incompatibility, bump libosmogsm and libosmogb LIBVERSIONs;
adjust debian files accordingly.

Implementation choices:

- The default behavior upon zero-initialization will be the mnc_3_digits flag
  set to false, which yields exactly the previous behavior.

- I decided against packing the mnc with the mnc_3_digits field into a
  sub-struct because it would immediately break all builds of dependent
  projects: it would require immediate merging of numerous patches in other
  repositories, and it would make compiling older code against a newer
  libosmocore unneccessarily hard.

Change-Id: Id2240f7f518494c9df6c8bda52c0d5092f90f221
2018-02-28 19:26:33 +01:00
Pau Espin 8fd85578bc core/logging.h: Add logging category for jitter buffer
Forthcoming jitter buffer code in libosmo-netif will make use of it.

Change-Id: I2434f9dfa401f736bc62a2ddce920e587cd8c517
2018-02-27 21:11:27 +00:00
Harald Welte 38c902b776 l1sap: Add fields for higher-precision timing offset values
So far, we used quarter-bits across the L1SAP between the hardware/PHY
specific part of OsmoBTS and the common part.  In order to increase
the resolution, let's add fields/members for 1/256th bit.

In order to keep ABI and API compatibility, we use a union around the
old and new values, so old code will still compile + work withe new
libosmocore.

Change-Id: Ibb58113c2819fe2d6d23ecbcfb8b3fce4055025d
2018-02-27 17:30:08 +01:00
Harald Welte a57f90c80b l1sap: Add RSSI, BER and quarter-bit accurate timing to PH-RACH.ind
Let's extend PH-RACH.ind with some useful data across the L1SAP
boundary.

Change-Id: I9439810c3a3ad89ea0302753617b850749af887c
Related: OS#3003
2018-02-27 17:13:04 +01:00
Pau Espin 726ba36201 core: Add timespec helper macros and make timer_compat.h public
If a monotonic clock must be used, then the clock_gettime API is used
which uses timespec structures. Linux systems by default don't provide
helpers to calculate time using timespecs, so let's add them here.

Let's also make this header public so these helpers can be used in other
projects using libosmocore (expected user: libosmo-netif).

Change-Id: I45fc993b9bb0a343763238bf463c8640f47b00f1
2018-02-27 15:44:29 +00:00
Harald Welte 6950b191e8 coding: Add BER-reporting RACH decode functions
For all other decode operations we report the BER, but not for the
RACH.  This results in osmo-bts-trx not being able to report BER
to the higher layers, which is possible on other BTS backends.

Let's close this gap by introducing gsm0503_rach_ext_decode_ber()
and gsm0503_rach_decode_ber() with the usual n_errors / n_bits_total
arguments.

Change-Id: I2b1926a37bde860dcfeb0d613eb55a71271928c5
2018-02-26 12:26:38 +01:00
Harald Welte 175a4ae93a rate_ctr: Add rate_ctr_inc2() as convenience wrapper
rate_ctr_inc2() is slightly easier to use than the old
rate_ctr_inc() variant.

Change-Id: Ie00706be201c32ec2981ea38b70354ed85e1aefd
2018-02-24 14:46:35 +01:00
Harald Welte 92decf2aa9 Revert "Add function to encode classmark"
This breaks all existing / older osmocom-bb builds, and hence
cannot be accpeted. See also https://gerrit.osmocom.org/#/c/6679

Related: OS#2985

This reverts commit 3c38e60cd5.

Change-Id: Icfc52ca4e5cbe3a444d98037d27fa101e3614e06
2018-02-22 16:17:41 +01:00
Pau Espin 98a7a2646b ports.h: Add VTY and CTRL ports for osmo-trx
Change-Id: Ib79cdb62d45d8c78445c7b064e58eb7e9faeccf9
2018-02-22 08:03:06 +00:00
Philipp Maier d1f5793b5e fsm: allow graceful exit on FSM termination
The function _osmo_fsm_inst_term() terminates all child FSMs befor
it calls fi->fsm_cleanup(). This prevents the cleanup callback to
perform last actions on the child FSMs (e.g.
osmo_fsm_inst_unlink_parent()).

- Since moving the cleanup callack to the beginning of the function
  would alter the termination behavior and possibly cause malfunction
  in already existing implementation that use OSMO fsm, a new
  optional callback that is called immediately at the beginning of
  the terminatopn process is added.

Change-Id: I0fdda9fe994753f975a658c0f3fb3615949cc8bb
Closes: OS#2915
2018-02-19 08:30:21 +00:00
Daniel Willmann b0c43a6063 fsm: Add a function to change the FSM instance ID later
Sometimes we want to create an FSM instance before we know its name. In
that case we should be able to update the id later.

Change-Id: Ic216e5b11d4440f8e106a297714f4f06c1152945
2018-02-15 18:03:58 +00:00
Max 3c38e60cd5 Add function to encode classmark
The code is based on Osmocom-BB implementation.

Change-Id: I78f6968edaa3ed535673411fb2a80060a472290f
2018-02-15 16:14:19 +01:00
Max ebf149234e Add generic Mobile Identity encoder
Add generic function which allows caller to set Mobile Identity
explicitly. This allows to use IMEI or IMEISV for example. Make
gsm48_generate_mid_from_imsi() into wrapper around new function.

Change-Id: Id79be7abfff75ecd0d248bbeed93e605abeec9b3
2018-02-15 11:44:33 +01:00
allesklar2 eb18282031 gsmtap.h: define TETRA DMO mode channels
Change-Id: I98976c0ff16a69b2508a79259ed1aeaec51e7549
2018-02-14 00:41:33 +00:00
Stefan Sperling 1859515c69 Add helper functions for ACC bit flags in rach control IE.
Add inline functions to manipulate and query ACC flag bits
in the rach_control.t2 and rach_control.t3 octets.
These function definitions also serve as documentation of
the purpose of rach_control.t2/t3.

Change-Id: I8f0a65c2980f86eb5c43f3bebe727f4d4d973163
Related: OS#2591
2018-02-13 15:11:20 +01:00
Harald Welte 554780836f Add GSM 04.08 type-of-number / numbering-plan-id definitions
Change-Id: Idd8d8a7a1c7f0b6cb9318e4f19ebadb415df2ed1
2018-02-09 22:40:09 +01:00
Harald Welte ebd2b0f405 osmo_msgbdump_{l2,l3}(): Proper typecast
This avoids compiler warnings like

/tmp/work/sysmobts_v2-poky-linux-gnueabi/osmo-pcu/0.4+gitAUTOINC+4c112dc5a6-r1.18/recipe-sysroot/usr/include/osmocom/core/msgb.h: In function 'const char* msgb_hexdump_l2(const msgb*)':
error: invalid conversion from 'void*' to 'const unsigned char*' [-fpermissive]
    return osmo_hexdump(msgb_l2(msg), msgb_l2len(msg));

which we've been getting in osmo-pcu builds on some platforms.

Change-Id: I0ec652a1a569ec1507d8411cf1ef87afabcca799
2018-02-09 10:28:13 +00:00
Harald Welte 572177063d msgb: Add msgb_hexdump_{l2,l3}() to dump l2 or l3 part of message buffer
Change-Id: I98e85397fb541ee0fd711f2e1852f63f3bb87359
2018-02-09 02:21:34 +01:00
Max 80f4c4eb08 GSUP: change osmo_gsup_encode() return type
* match return type of osmo_gsup_encode() with osmo_gsup_decode() to allow
  propagating error to caller
* check return value of osmo_gsup_encode() in GSUP test
* return errors instead of braking app with aseert

Change-Id: Idaa1deecb6d9e15329bd51867b4f6a03357461f0
Related: OS#2864
2018-02-05 13:03:42 +01:00
Max 18c014de67 utils: add helper wrapper for osmo_strlcpy()
Add wrapper for osmo_strlcpy() which uses sizeof() to automatically
determine buffer's size and use it for GSMTAP logging. This is pretty
common use case for osmo_strlcpy() so it's a good idea to save some
typing by using generic define.

Related: OS#2864
Change-Id: I03d0d3d32a8d572ad573d03c603e14cdc27a3f7b
2018-02-05 11:34:14 +00:00
Harald Welte f1076ed75a gsm48_hdr_msg_type(): SS is in the same group as MM/CC
Change-Id: I1ddadeacced9650885f454b81f3f0df531ea1e5d
2018-02-03 21:17:43 +01:00
Harald Welte 143aed7fa6 gsm48_hdr_msg_type[_r99]: Fix bit-masks
TS 24.007 is quite clear: The upper two bits of the message type
octet are *not* part of the message type in any of the L3 protocols
which implement sequence numbers.  it doesn't matter if it's R98 or
R99, or whether the sequence number is 1bit or 2bits wide.

Related: OS#2908
Change-Id: Iec875a77f5458322dfbef174f5abfc0e8c09d464
2018-02-03 21:17:43 +01:00
Harald Welte cd82710be7 gsm_04_08.h: Reduce T310 default to 30s.
3GPP doesn't specify a network-side T310 default, but waiting for 180s
(3 minutes!) for the next message after CALL CONFIRMED is clearly way
too long and will just use radio resources for no good reason.

Change-Id: Ia52f9358bc86b23c72af9c80e2fff5cb0004b57a
Related: OS#2884
2018-01-27 09:48:07 +01:00
Harald Welte e50b00911b gsm_04_08.h: Clearly annotate timers that don't have a 3GPP Default value
Change-Id: I44fffaec1f7c0d819aa2ebc85e97f19581fc689c
2018-01-27 09:48:07 +01:00
Harald Welte d60e17ab0e SMS: Add value_string for TS 04.11 CP and RP state
Change-Id: I1b2f6fc6f455b0ba2a5732c567a4867bca97c3b0
2018-01-24 16:50:59 +01:00
Philipp Maier 2a06a491b1 fsm: add functions for unlinking and changing parents
At the moment it is not possible to unlink a child from from
its parent, nor is it possible to assign a new parent to a
child FSM.

- osmo_fsm_inst_unlink_parent():
  Make it possible to unlink childs from a parent.

- osmo_fsm_inst_change_parent():
  Make it possible to change the parent of a child.

Change-Id: I6d18cbd4ada903cf3720b3ad2a89fc643085beef
2018-01-24 12:03:28 +01:00
Harald Welte 0bbf67dfd3 MNCC: Add MNCC to string dumper
As MNCC is rather hard to debug (wireshark cannot trace UNIX domain
sockets), let's add our own decoder that we can use from related
debug log statements in the respective programs.

Change-Id: I216aaf70868ba5f3860a60c4b2442957531a3011
2018-01-19 23:52:42 +01:00
Neels Hofmeyr 0e2a94326e logging: allow to log only the basename of each source
In the C API, add another enum log_file_type value, and when set print only the
basename of the source file path.

Rationale: especially when not building directly in the source dir, the paths
to the source files can become rather long. Usually, just the basename of the
file is sufficient to identify the source line.

Change-Id: If3e4d5fb2066f8bf86e59c82d1752b1a843cf58e
2018-01-19 15:46:49 +00:00
Neels Hofmeyr bd7bd3947d logging: separate the '<000b>' subsys from filename logging
Add a separate flag and API to switch the category-in-hex output:
log_set_print_category_hex().

Add log_set_print_filename2() to modify only the print_filename flag. The old
log_set_print_filename() function still affects both flags. Explain the
rationale in the comment for log_set_print_filename().

There is no need to deprecate log_set_print_filename(); it might cause compiler
warnings and break strict builds unnecessarily.

Add VTY command 'logging print category-hex (0|1)'.

Since there is no VTY command to switch filename output, nothing needs to be
adjusted there (a command will be added in a subsequent patch).

Change-Id: Iba03a2b7915853c6dccaf6c393c31405320538b4
2018-01-19 15:46:49 +00:00
Neels Hofmeyr 886e548ab0 logging: add ability to log the log-level with API and vty
Log the log level string after the category name, if enabled.

The default behavior remains unchanged.

Change-Id: Ie6be365cfa6aeabdf115bff19bac198440c9adf1
2018-01-17 11:13:58 +00:00
Vadim Yanitskiy fa6c2b9b53 gsm0480: fix USSD OCTET STRING length confusion
According to the GSM 04.80 (version 5.0.0) specification Annex A
"Expanded ASN.1 Module "SS-Protocol", the maximum size of a USSD
OCTET STRING is 160 bytes.

Thus according to ETSI TS 123 038 (version 10.0.0) specification
6.1.2.3 "USSD packing of 7 bit characters", in 160 octets, it's
possible to pack (160 * 8) / 7 = 182.8, that is 182 characters.
The remaining 6 bits are set to zero.

This change defines both mentioned values:

  - GSM0480_USSD_OCTET_STRING_LEN  160
  - GSM0480_USSD_7BIT_STRING_LEN   182

keeping the old MAX_LEN_USSD_STRING 'as is' due to compatibility
reasons. Now the new value is used for ss_request structure, while
old one is still used for deprecated ussd_request structure.

Change-Id: I6dead74f9ecea079752ff2400cdaf7c30187784e
2018-01-17 10:45:39 +00:00
Philipp Maier 40def49ac4 libosmocodec: implement ECU (Error Concealment Unit) for FR
When a bad GSM voice frame is received, it's being replaced
by a silence frame. This may cause unpleasant audio effects.

This change implements a functionality to craft a replacement
frame from the last known good frame. Currently, only FR is
supported, support for other codecs may be added latter.

Change-Id: I06a21f60db01bfe1c2b838f93866fad1d53fdcd1
2018-01-15 20:12:03 +00:00
Max 309d0e5483 Deprecate gsm48_construct_ra()
It's just a tiny wrapper around gsm48_encode_ra() with less strict type
signature.

Related OS#1640
Change-Id: I79d6d1133afbf32e891a6b0e3a244c6885ea9614
2018-01-12 14:15:03 +00:00
Neels Hofmeyr ffad574a4b gsm: add gsm0808_speech_codec_type_names
Used for logging Speech Codec List entries in osmo-bsc, during handover
decision.

Change-Id: Ie6418d16db333188e9bcd2b32b7216f277ae8832
2018-01-12 05:34:05 +01:00
Max f1ad60e4d8 Add function to properly encode RAI
Add gsm48_encode_ra() which takes appropriate struct as [out] parameter
instead of generic buffer. Using uint8_t buffer instead of proper struct
type prooved to be error-prone - see Coverity CID57877, CID57876.

Old gsm48_construct_ra() is made into tiny wrapper around new
function. The test output is adjusted because of the change in function
return value which was constant and hence ignored anyway.

Related: OS#1640
Change-Id: I31f9605277f4945f207c2c44ff82e62399f8db74
2018-01-08 13:02:07 +00:00
Max ff2eedac0f Fix incorrect spec reference
RAI is defined in 3GPP TS 24.008 § 10.5.5.15

Change-Id: I484485d8c4c56b58dfecc1193bcdd48e61957422
2018-01-04 18:43:44 +01:00
Neels Hofmeyr 074478dc61 logging vty: tweak general 'logging' command doc
'logging' is not only for terminals, also for stderr and other log targets.

Change-Id: If1ee59c7d1073502259b7d60008206ac3d8e87a3
2017-12-20 16:00:59 +00:00
Philipp Maier 6cb9e7d898 libosmocodec: add FR bit offset definitions
This change defines the GSM FR bit positions as described
in RFC 3551, which will be used by further ECU
(Error Correction Unit) implementation.

Change-Id: I1d0a198af0f8dd1f690b5a81f5c9eb92c43aefed
2017-12-20 15:48:38 +00:00
Vadim Yanitskiy e094157e12 libosmocodec: add FR/HR/EFR frame length definitions
There are some projects, such as OsmoBTS and OsmocomBB, which
are dealing with raw TCH payloads, so they need to have the
FR/HR/EFR frame length defined. At the moment, each project
defines them itself. Let's share these definitions.

Change-Id: Ib19dd1bf81712d034157f9ce061008be0000ef38
2017-12-20 15:48:38 +00:00
Neels Hofmeyr 58a5665ecb ports: define proper VTY and CTRL ports for OsmoHNBGW
So far it uses 2323, a development default. Instead, assign new ports,
appending to the common range of VTY and CTRL ports: 4261 and 4262.

Related: https://osmocom.org/projects/cellular-infrastructure/wiki/Port_Numbers
Related: I28bd7a97d24455f88fadc6724d45c3264ba2fce4 (osmo-gsm-manuals)
Change-Id: Ife52a968a41cb286f640006587877971ff66c1a4
2017-12-20 10:57:19 +00:00
Neels Hofmeyr f2e83ad40d add ctrl_cmd_parse2() to return parsing errors
If a control command fails to parse, we so far discard specific error messages
and instead send just "Command parser error".

In ctrl_cmd_parse() we actually compose detailed error replies, but in the end
simply talloc_free() them and return NULL.

A first step to report these errors to the ctrl command issuer is to not return
NULL and instead return the cmd with type = CTRL_TYPE_ERROR. Add
ctrl_cmd_parse2() to return such instead of NULL.

To stay API compatible, provide ctrl_cmd_parse2() to return a cmd on errors.
ctrl_cmd_parse() retains identical behavior but becomes just a simple wrapper
around ctrl_cmd_parse2() which discards the cmd on error.

No need really to deprecate ctrl_cmd_parse() yet; especially as long as
compiler warnings might break jenkins builds.

Change-Id: I5047c9f977d70b03eea77cbcfd2b96d43ea46880
2017-12-18 23:05:50 +00:00
Neels Hofmeyr d53d216944 ctrl: prep test: separate new ctrl_handle_msg() from handle_control_read()
In order to allow unit testing the ctrl iface msgb handling, have a separate
msgb entry point function from the actual fd read function.

An upcoming patch will prove a memory leak in CTRL msgb handling by a unit test
that needs this separation.

Change-Id: Ie09e39db668b866eeb80399b82e7b04b8f5ad7c3
2017-12-18 23:05:49 +00:00
Neels Hofmeyr 9910bbc62d utils: add osmo_escape_str()
To report invalid characters in identifiers, it is desirable to escape any
weird characters. Otherwise we might print stray newlines or control characters
in the log output.

ctrl_test.c already uses a print_escaped() function, which will be replaced by
osmo_escape_str() in a subsequent patch.

control_cmd.c will use osmo_escape_str() to log invalid identifiers.

Change-Id: Ic685eb63dead3967d01aaa4f1e9899e5461ca49a
2017-12-18 23:05:49 +00:00
Neels Hofmeyr aa84b71f0f add osmo_auth_c3() (separate from gsm_milenage())
To send a Ciphering Mode Command, we may need to derive a Kc from UMTS AKA
tokens. gsm_milenage() derives Kc from 3G tokens, but also derives an SRES.
For SRES, it requires an OPC, which may need to be derived from OP first. All
we need is a Kc, so we could feed a zero OPC ...  but to simplify the function
call for cases where just a Kc is required, separate the c3 function out from
gsm_milenage(), as osmo_auth_c3(). Obviously call osmo_auth_c3() from
gsm_milenage() (meaning that osmo-hlr's 55.205 derived auc tests still cover
exactly that implementation).

Prepares: If04e405426c55a81341747a9b450a69188525d5c (osmo-msc)
Related: OS#2745
Change-Id: I85a1d6ae95ad9e5ce9524ef7fc06414848afc2aa
2017-12-18 23:05:24 +00:00
Neels Hofmeyr 937ddea6cc utils: add osmo_separated_identifiers_valid()
For validating CTRL input, we want to verify that an input variable is a series
of valid osmo_identifier_valid() separated by dots. Allow validating any
additional chars with identifiers, for CTRL vars will be just ".".

Change-Id: I13dfd02c8c870620f937d789873ad84c6b1c45de
2017-12-17 21:57:55 +00:00
Neels Hofmeyr 84ea2e0374 logging vty: describe 'logging set-log-mask' command, add OSMO_STRINGIFY_VAL()
Change-Id: I73ac5873ede858da44e1486d8a5c81da1ed5b19f
2017-12-12 18:00:24 +00:00
Max 32e5641dbb Add functions for extended RACH coding
Add support for extended RACH (11 bit) according 3GPP TS 45.003 §5.3.2:

* convolutional code with puncturing
* encoding/decoding routines
* corresponding tests

Change-Id: I85a34a82d5cd39a594ee89d91a2338226066ab5d
Related: OS#1548
2017-12-11 10:36:47 +00:00
Neels Hofmeyr dc75b114b4 comment: utils: more accurately describe OSMO_STRINGIFY macro
Change-Id: I7b057c026f9df90608b7cbd12481ab9e7a41d88c
2017-12-10 13:34:36 +00:00
Alexander Couzens 18ba26cfab counters: add osmo_counters_count() returns the amount of counters
Change-Id: I9068231d71876e06d27ee67a688d7fb611ac3a1b
2017-12-05 16:06:27 +01:00
Holger Hans Peter Freyther 37a83405a5 logging: Extend the LOGPSRC macro to put cont in it as well
For the lua console printing I need to print several values with
continuation but also specify the filename. Add a "C" for continue
and forward arguments.

Change-Id: I1d6dcb2567b9ed2c8767f661737b979bc3d1377e
2017-12-01 12:01:38 +00:00
Harald Welte f9b1e5556a gsmtap.h: Introduce new GSMTAP type for LTE NAS messages
Change-Id: I6e1274f17e2d9d2eee16481940642216ca96e3e3
2017-11-23 22:30:57 +01:00
Neels Hofmeyr e750980d6c tlv_put: guard against NULL val and 0 len
For example encode_auth_info() from gsup.c calls
  msgb_tlv_put(msg, iei, 0, NULL)
to put a tag and len with content data following later.

However, this would cause a memcpy() from a NULL pointer, in tlv_put(). Allow
passing NULL and len = 0 for cases like the above:

If val is NULL, use memset(0) instead of memcpy().
If len is zero, do not copy nor memset anything.

Hence make tlv_put() behave in a well-defined and valid way for any and all
input args; no negative fallout is possible from this patch.

Add proper API doc comment.

Fixes a sanitizer build failure in gsup_test:

  ../../../../src/libosmocore/include/osmocom/gsm/tlv.h:99:2: runtime error: null pointer passed as argument 2, which is declared to never be null

Helps fix sanitizer build on debian 9.

Change-Id: I13dce9cd1228817890d3e81edeeb660c893c1d64
2017-11-20 17:22:42 +01:00
Neels Hofmeyr 3fad5d782a msgb: add inline msgb_queue_free()
Related: Iaad35f03e3bdfabf3ba82b16e563c0a5d1f03639 (libosmo-netif)
Change-Id: Ia291832ca445d4071f0ed9a01730d945ff691cf7
2017-11-20 14:22:15 +01:00
Harald Welte abcd0e37b7 ports.h: Use same VTY port number for osmo-mgw and osmo-bsc_mgcp
It was decided that osmo-mgw as direct successor of osmo-bsc_mgcp
will use the same VTY port number (similar to osmo-nitb, osmo-bsc
and osmo-bsc-sccplite all using the same VTY port number)

Change-Id: Iec1da9f3b4d170416279f05876d9e1ae2970c577
2017-11-20 09:46:45 +00:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Philipp Maier c0fc7940df vty: add port number for osmo-mgw
Change-Id: Ied224fe94b5152fd19e259396fbc0eaf69be4b96
2017-11-10 14:55:04 +00:00
Neels Hofmeyr 4a73d5e843 vty: deprecate now empty node commands
Following I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b a deprecation of
vty_install_default() and install_default() commands is indicated.

However, compiler warnings may clutter build output or even fail strict builds,
hence I am submitting the deprecation in a separate patch.

Depends: I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b
Change-Id: Icf5d83f641e838cebcccc635a043e94ba352abff
2017-11-08 02:54:54 +00:00
Max cbf5cdfe7e GPRS: constify NS printing routine parameters
Change-Id: I549ab7c26ac1489e01f281594bafe44b0681dc83
2017-10-24 16:34:41 +00:00
Harald Welte ae510dc4a7 rate_ctr: Enforce counter (and ctr_group) names are valid identifiers
As rate counters are automatically exposed on the CTRL interface,
we need to make sure they don't contain special characters such as '.'
which are not permitted/supported by CTRL.

In order to be able to run old versions of osmocom programs with
libosmocore versions after this commit, we introduce some special
name mangling:  Any '.' in the names are replaced with ':' during
counter group registration, if valid identifiers can be obtained
this way.

Change-Id: Ifc6ac824f5dae9a848bb4a5d067c64a69eb40b56
2017-10-24 16:00:45 +00:00