Commit Graph

2675 Commits

Author SHA1 Message Date
Neels Hofmeyr 5314c513f2 vty: fix use-after-free and memleaks in is_cmd_ambiguous()
vty_test: add test against ambiguous cmd causing use-after-free and memory
leaks. Add this test along with the fix, because the new test triggers the
memory use-after-free and leaks, causing build failures.

Add cmd_deopt_with_ctx() to allow passing a specific talloc ctx.

is_cmd_ambiguous(): keep all cmd_deopt() allocations until the function exits.
Add a comment explaining why. Before this, if a command matched an optional
"[arg]" with square brackets, we would keep it in local var 'matched', but we
would free the string it points to at the end of that loop iteration; upon
encountering another match, we would attempt to strcmp against the freed
'matched'. Instead of adding hard-to-read and -verify free/alloc dances to keep
the 'matched' accurately freed/non-freed/..., just keep all cmd_deopt() string
allocated until done.

Needless to say that this should have been implemented on a lower level upon
inventing optional args, but at least this is fixing a program crash.

Related: OS#33903390
Change-Id: Ia71ba742108b5ff020997bfb612ad5eb30d04fcd
2018-07-11 15:47:08 +02:00
Neels Hofmeyr 4e0add239f vty: cosmetic: cmd_deopt(): use talloc_strndup(), not memcpy()
Change-Id: Ibf870ae02be706f802482f7cff6589a70cde8320
2018-07-09 23:41:11 +02:00
Neels Hofmeyr f2d323ef0f vty/command.c: talloc from tall_vty_cmd_ctx, not NULL
Change-Id: Iaa409b4f63557c8fb028bbb322b5e7253393c05c
2018-07-09 23:41:11 +02: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
Harald Welte 79d49af93a jenkins_arch.sh: Exit with error on unknown architecture
The jenkins build job used to call this script using an "arch"
it doesn't understand.  This should have resulted in an error,
but it didn't as there was a missing "exit 1" statement :(

Related: OS#3360
Change-Id: Ib27c9ebaf2630c432b1923f8e14b36e7772a6033
2018-06-28 10:57:42 +02:00
Harald Welte cae93e51d9 jenkins_arch.sh: Accept "arm-none-eabi" as alias for "arm"
The jenkins build job is calling the script using "amd64" and
"arm-none-eabi", while the script expects "amd64" and "arm".

Let's add "arm-none-eabi" as an alias for "arm".

Closes: OS#3360
Change-Id: Idedd4778a63d67cdbf4f4d538bf4a225abb7547a
2018-06-28 10:57:42 +02:00
Harald Welte 1e78313e8e jenkins_arm.sh: Don't run 'make check' on embedded builds
If we're cross-compiling for arm-none-eabi, we cannot execute test
programs.

Change-Id: I64e88a31091b67c37c308c44013c42d4574d2312
2018-06-28 10:57:42 +02:00
Harald Welte 14c4c498b1 Fix embedded (arm-none-eabi) builds
Due to OS#3360, build testing for arm-none-eabi was unfortunately
skipped for a long time.  This is a number of fixes that make the
compile test pass again.

Related: OS#3360
Change-Id: I88e3c8e1a8786ca2a6a023b0d27c74be200a8588
2018-06-28 10:30:34 +02:00
Stefan Sperling f1e13d6081 return error to sender upon bssgp_tlv_parse() failure
Return "invalid mandatory information" error status to
the sender in case bssgp_tlv_parse() failed.
To avoid loops, do not respond with an error status to
STATUS PDUs which failed parsing.

Change-Id: If73719b75a94d6742bdefc9b6572525cb00a96ee
Related: OS#3178
2018-06-25 12:59:23 +02:00
Stefan Sperling 2b544b257f check bssgp_tlv_parse() return code in bssgp_rcvmsg()
The return code from bssgp_tlv_parse() was not checked for a parsing
error. In case of a parsing error the stored return code could have
been overwritten later in this function.

Explicitly check for a parsing error and log corresponding packets.

Change-Id: Id3d7c52ec3df2bcf4efcee0e0b14fe22ef96964e
Related: OS#3178
2018-06-25 12:20:43 +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
Pau Espin 1eb270bda8 gsm: lapdm.c: Add missing new line char in notice log string
Change-Id: I92c78ea01570dc1f4be11b113c07f0aa3b342c8f
2018-06-18 19:23:11 +02: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 23a299f096 vty: Don't dump deprecated commands in XML export
we don't want to include deprecated commands in our VTY reference
manuals.

Change-Id: I5e179c9dca297b8c4bdbdf4e0e5b1d69eecc4232
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
Vadim Yanitskiy dfb0b97f55 Doxygen: gitignore generated files for libosmoctrl
Change-Id: Ia888d14c6e1f76374addd9b1ee66523f82fc06c9
2018-06-05 03:53:02 +07: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
Vadim Yanitskiy fb5da89579 gsm0480: fix: don't overwrite the data of RELEASE_COMPLETE
According to the 3GPP TS 04.80, table 2.5 'Release complete', a
RELEASE_COMPLETE message may containg optional FACILITY element.

Meanwhile, the 0xff byte is used to indicate that there is no
decoded message (legacy field). Let's avoid overwriting of
a decoded message.

Change-Id: I0c85292222749a48ca0c4b2e93f4fa2d61468c18
2018-05-29 19:23:42 +00:00
Daniel Willmann 07f075d197 ports.h: Add ctrl port for osmo-gbproxy
Change-Id: I46a1cef3013c9bbf9b5a6d64e83cd84568f2523c
2018-05-29 21:02:16 +02:00
Harald Welte 572fc2d344 debian: Add libosmoctrl-doc sub-package
This fixes the debian package builds for libosmocore.git

Change-Id: I454e3c0175ab5a89e8925e036a3644299367df0f
2018-05-28 17:55:51 +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
Harald Welte ed6057841d ctrl: Introduce libosmoctrl.map to avoid unintended exports
There are some symbols for use between control_cmd.c and control_if.c,
which are not supposed to be exported publicly.  Let's make sure we
keep those symbols local.

Change-Id: Ia85f36a9c4b2ebf4003718e0a230959638370320
2018-05-26 21:58:11 +02:00
Harald Welte 3b8921fae2 cosmetic: Whitespace fixes in control_if.c
Change-Id: I24666d0b90a355e9fdefd280d48900b8cac1de64
2018-05-26 10:22:22 +00: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 4df2251f1b remove unused argument from pad_append_ctr() helper function
Change-Id: Iff5699be1dc306120cc1752b0a892e4fcbc5a8c0
Fixes: 97d3da2c59
Related: OS#3245
2018-05-25 13:06:41 +02:00
Stefan Sperling 73b7fa6109 Add a 'show rate-counters' VTY command.
Add a new VTY command which shows all rate counters registered
with libosmocore.

Change-Id: Id60a5aa2d961ae99cddf1e776358a5517dbc573d
Depends: Idb3ec12494ff6a3a05efcc8818e78d1baa6546bd
Related: OS#3245
2018-05-24 18:44:40 +02: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
Pau Espin dab4db0217 gsm: kasumi: Fix dynamic-stack-buffer-overflow on out buffers not multiple of 64 bits
Fixes following AddressSanitizer report during gea_test run with gcc
8.1.0:

==8899==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffc5f1719bb at pc 0x7fe574adc5fe bp 0x7ffc5f171460 sp 0x7ffc5f171450
WRITE of size 1 at 0x7ffc5f1719bb thread T0
    #0 0x7fe574adc5fd in osmo_store64be_ext ../../include/osmocom/core/bit64gen.h:75
    #1 0x7fe574adc649 in osmo_store64be ../../include/osmocom/core/bit64gen.h:104
    #2 0x7fe574ade936 in _kasumi_kgcore libosmocore/src/gsm/kasumi.c:186
    #3 0x7fe574ae2532 in gea4 libosmocore/src/gsm/gea.c:44
    #4 0x7fe574ae266c in gea3 libosmocore/src/gsm/gea.c:60
    #5 0x7fe574a9b616 in gprs_cipher_run libosmocore/src/gsm/gprs_cipher_core.c:95
    #6 0x56422d3fb2ee in test_gea libosmocore/tests/gea/gea_test.c:29
    #7 0x56422d3fb506 in main libosmocore/tests/gea/gea_test.c:49
    #8 0x7fe5730f406a in __libc_start_main (/usr/lib/libc.so.6+0x2306a)
    #9 0x56422d3fadf9 in _start (libosmocore/tests/gea/.libs/lt-gea_test+0x1df9)

The kasumi_test is updated to calculate the entire array of bits
according to expected result. Before this commit it worked by writing
the entire last 64bit block, and addressSanitizer cannot catch it
because the allocated buffer is 64bit aligned too.

Change-Id: I7b2a0224a3b5527d5a3ad7e17efc73081b63eac1
2018-05-17 12:13:04 +02:00
Pau Espin 16e205bfb2 tests: a5_test: Print wrong buffer correctly on error
Before this patch, osmo_hexdump is called stacked in th esame printf
function. As a result, the first returned buffer is overwriten by the
second, which means the printed buffers will show as the same always.

Change-Id: I364328a59da31537c6c9b969e34edd360b685081
2018-05-16 21:13:58 +02:00