Commit Graph

970 Commits

Author SHA1 Message Date
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
Harald Welte febe83c424 Introduce osmo_identifier_valid() function to check validity of identifier
We define the notion of an 'osmocom identifier' which is basically a
7-bit US-ASCII without any special characters beyond "-_:@".  We
introduce a function to verify if an identifier consists only of the
permitted characters.

Change-Id: I96a8d345c5a69238a12d040f39b70c485a5c421c
2017-10-24 16:00:44 +00:00
Max 9530859654 GPRS: clarify ip/frgre union use
* add comment about underlying assumption that structs in ip/frgre union
  members in gprs_nsvc struct have the same memory layout
* remove such assumption from gprs_ns_ll_str()
* use gprs_ns_ll_str() for NSE dump

Change-Id: Idcb912b7b3f7460fd2b058e16650c0bde8f757ee
2017-10-24 14:33:31 +00:00
Max 4ce24c45b9 GPRS: unify NS state printing
* introduce defines with NS state names
* use them for vty and tests
* expand test output to print complete NS state

Change-Id: I69f8d536135ae76dbca623c2f1ffba625adcb1e9
Related: SYS#3610
2017-10-24 14:33:30 +00:00
Neels Hofmeyr abdd7a28ed add osmo_talloc_asprintf() and ctrl_cmd_reply_printf()
Add macro to append to a CTRL commands' reply string, ctrl_cmd_reply_printf().
The talloc_asprintf() part of it is generic enough to qualify for a separate
macro, osmo_talloc_asprintf().

The idea is to not have to decide for each bit added to a string whether the
string is already allocated or not, but simply be able to issue printf commands
and let the macro worry about initial allocation or reallocation.

This originally came from osmo-hlr change
I1bd62ae0d4eefde7e1517db15a2155640a1bab58, where it was requested to move this
bit to libosmocore.

Change-Id: Ic9dba0e4a1eb5a7dc3cee2f181b9024ed4fc7005
2017-10-24 10:54:07 +00:00
Philipp Maier 224a6dda02 gb: optionally allow nsip packets only from a specific host
When listening for nsip connections is enabled, then every remote
host may send packets. This is useful for an SGSN that serves
multiple PCUs, but contraproductive for a PCU that awaits packets
from a single SGSN.

Add struct members remote_ip, and remote_port to struct gprs_ns_inst,
when set, then the listening end uses connect() to ensure that only
the expected host may send packets.

Related: OS#2401
Change-Id: Ifeb201d9006eec275a46708007ff342cdfc14e45
2017-10-24 10:50:07 +00:00
Max 0b3db5039d Replace bitvec_set_uint() with bitvec_set_u64()
Old bitvec_set_uint() uses "unsigned int" as input parameter which
length is not guaranteed. It does not allow to specify which bit_value
to set and does not check for incorrect length. Overall this makes it
harder to re-use and more error-prone.

Let's replace it with extended implementation which uses fixed type
length parameters and extra checks. The additional parameter allows
caller to explicitly indicate the need to use L/H instead of 0/1 for bit
vector elements. It's necessary to properly encode some of the messages
from 3GPP TS 44.018, for example §10.5.2.16 IA Rest Octets.

The old function is left for backward compatibility as a tiny wrapper
around new function and will be deprecated in follow-up patches.

Change-Id: I1b670dacb55fb3063271d045f9faa10fccba10a6
Related: OS#1526
2017-10-24 08:22:02 +00:00
Neels Hofmeyr ea66852a62 ctrl: allow more nodes than those in enum ctrl_node_type
Add ctrl_interface_setup_dynip2() to add a node_count parameter, which can be
used to define more ctrl nodes without having to merge a patch to libosmocore.

In consequence, also add ctrl_handle_alloc2(), since
ctrl_interface_setup_dynip() uses ctrl_handle_alloc() to allocate the node
slots, and add node_count param to static ctrl_init().

Passing zero as node_count indicates to use the default of _LAST_CTRL_NODE as
before, i.e. to not define more ctrl nodes. Assert that we never allocate less
than _LAST_CTRL_NODE slots.

The current ctrl_interface_setup_dynip() and ctrl_handle_alloc() become simple
wrappers that pass zero as node_count. Their use is still valid and they do not
need to be deprecated.

The API comment to ctrl_interface_setup_dynip2() explains how to define more
node IDs.

This patch was verified to work by osmo-hlr.git change
I98ee6a06b3aa6a67adb868e0b63b0e04eb42eb50 which adds two node IDs for use by
osmo-hlr only.

Change-Id: I1bd62ae0d4eefde7e1517db15a2155640a1bab58
2017-10-23 22:31:01 +00:00
Pau Espin 4b45669761 abis_nm: Add abis_nm_admin_name() API
Similar APIs exist for opstate and availability status.

This patch does not break backward compatibility because osmo-bsc still
requires direct use of the structure in get_string_value().

Change-Id: Ieace734aaff3f07606113feddde65b75202d96d6
2017-10-23 16:59:57 +00:00
Philipp Maier 2d2490ed4e socket: add function osmo_sock_local_ip() to query local ip
In some cases it is required to know the ip-address of the interface
through that a given remote IP-Address can be reached.

Add function osmo_sock_local_ip() to determine the local ip-address
for a given remote ip-address

Change-Id: I2988cc52b196fc8476703d1287e24cb4a48491c2
2017-10-23 08:47:38 +00:00
Philipp Maier c5b47cc032 add function msgb_printf() to print formatted text into msg buf
In ASCII string based protocols it a printf() version that prints
directly to the message buffer may be useful.

Add function msgb_printf(), make sure that msg buffer bounderies
are not exceeded. If the end of the tail buffer is hit, return
with an error code.

Change-Id: I15e1af68616309555d0ed9ac5da027c9833d42e3
2017-10-22 20:09:26 +00:00
Neels Hofmeyr b525b9ea44 api doc: fix two doxygen group closing braces
Change-Id: I6c1f47d13c5b7a9cb2281de9f017df4f1ed88ba7
2017-10-17 11:53:45 +00:00
Harald Welte 37b6165513 [doc] Properly define gsm0800 group and move all related files into it
Change-Id: I91920c69c86d6a1932172becacb76faff2d3eb1e
2017-10-17 07:53:02 +02:00
Harald Welte a338983d3b [doc] Properly define 'oap' group and add introductory text
Change-Id: I1e875991ae1dd93862f850f85d40b3dac61ece72
2017-10-17 07:53:02 +02:00
Harald Welte 381a1aa1c1 [doc] Define 'gsup' group with proper name, add intro text
Change-Id: Ieee6213dc5aad082a2d439c7418b51f281b80b1a
2017-10-17 07:53:02 +02:00
Harald Welte 55d724addc [doc] make sure all SMS related code is part of the 'sms' group
Change-Id: I24c56ccb56d5b39cfb887808f91b715da54c0f8b
2017-10-17 07:53:02 +02:00
Harald Welte 8cc2767891 [doc] gea has separate group; A5 is not part of crypto but a5 group
Change-Id: I2fd24c86f9b52244073ec800a3287e3d38e660d9
2017-10-17 07:53:02 +02:00
Harald Welte c368b5420a [doc] Provide proper name for 'auth' group
Change-Id: I5fb1c34475ea9db36c2ec5cddc988074a72a35f7
2017-10-17 07:53:02 +02:00
Harald Welte 9325d86192 [doc] TLV parser has far grown beyond GSM L3
Let's hence not call the group "GSM L3 compatible TLV parser"

Change-Id: Ic53f9c0d5ee787f994f42cf2aff313c6e131fbe6
2017-10-16 15:32:43 +02:00
Harald Welte 84bd33349c [doc] Rename "RSL" to "A-bis RSL" in documentation.
We also have "A-bis OML" and it's a bit odd to have one with prefix
and the other without.

Change-Id: Ida325f8a9c40b40c1aeaa4edfd1123ced7cc92b8
2017-10-16 15:32:06 +02:00
Harald Welte 7166094a85 [doc] Expand Doxuygen documentation for osmo_prim
Also, make sure prim.c is actually part of the 'prim' module.

Change-Id: I4363e46a5f606eb2114a9cc1d2086007eaa58d31
2017-10-16 14:52:37 +02:00
Harald Welte 197a4ac06d [doc] Put CRC-16 and generic CRC code in one Doxygen module
.. and add missing API documentation bits

Change-Id: I67119894bcbf8c779426a0272bae4c5ce1fbd1ed
2017-10-16 14:29:26 +02:00
Harald Welte ef7a44e33d [doc] bits.c: Better / more Doxygen documentation
Change-Id: If824a5c8d8ee6e3dc96a3fddeb105786c0c027c1
2017-10-16 14:19:12 +02:00
Harald Welte eb5b6ce444 [doc] Add Doxygen API documentation for stats.c and stats_statsd.c
Change-Id: I8e49505f5c19beac90290fdba8821714e8eecd97
2017-10-16 14:18:56 +02:00
Harald Welte 17bbaa324b [doc] counter.[ch] Add Doxygen API documentation
This adds a more complete set of API documentation for all
osmo_counter relatedd functions and definitions.

Change-Id: I24283c05620ee86a8beb165af98a85d754549efb
2017-10-16 14:18:54 +02:00
Harald Welte 781951bcf9 [doc] stat_item: Complete doxygen documentation for API
The stat_item code base had some incomplete doxygen documentation
so far.  Let's complete it, and at the same time fix some cosmetic
as well as copy+paste issues in the existing documentation bits.

Change-Id: Ib514c137b40bf7b9791bd74be99af0b65575f2b6
2017-10-16 14:18:50 +02:00
Harald Welte 216338c369 Rename 'statistics.c' to 'counter.c'
With stat_item, stats.c and stats_statsd.c, it is becoming a bit
difficult to understand file naming.  Also, the 'statistics.c' file
actually only contained osmo_counter handling, so let's rename it to
counter.c altogether.

Change-Id: I2cfb2310543902b7da46cb15a76e2da317eaed7d
2017-10-15 19:51:35 +02:00
Neels Hofmeyr 4335badd0e utils: add osmo_is_hexstr(), add unit test
Will be used by OsmoHLR to validate VTY and CTRL input.

Change-Id: Idf75946eb0a84e145adad13fc7c78bb7a267aa0a
2017-10-09 16:30:45 +02:00
Neels Hofmeyr 1a02e36c4c auth: add OSMO_MILENAGE_IND_BITLEN_MAX
Will be used by OsmoHLR to validate VTY and CTRL input.

Change-Id: Ic39f3404d1a49ffd06070aa9897b36f219eacf4d
2017-10-09 16:30:45 +02:00
Neels Hofmeyr 26e30b1309 auth: add value_strings for osmo_sub_auth_type, comment on osmo_auth_alg_name()
Add osmo_sub_auth_type_names[] and osmo_sub_auth_type_name().

Also add a hint to enum osmo_auth_algo's API doc that osmo_auth_alg_name()
already exists (it is defined further below).

Change-Id: I652a929bcd11c694d86812fb03d0a1cbd985efda
2017-10-09 16:30:45 +02:00
Max 4b2b0cc15d Add function to generate random identifier
The function is a wrapper on top of getrandom() (if available via glibc) or
corresponding syscall. If neither is available than failure is always
returned.

It's intended to generate small random data good enough for session
identifiers and keys. To generate long-term cryptographic keys it's
better to use special crypto libraries (like GnuTLS for example)
instead.

As an example it's used to replace old insecure random number generator
in osmo-auc-gen utility.

Change-Id: I0241b814ea4c4ce1458f7ad76e31d390383c2048
Related: OS#1694
2017-10-09 10:18:07 +00:00
Neels Hofmeyr 9cd1e7417e add osmo_imsi_str_valid() and osmo_msisdn_str_valid()
Add GSM23003_IMSI_MIN_DIGITS definition.
Add regression test gsm23003_test.c to test the two new functions.

Will be used by OsmoHLR to validate VTY and CTRL input.

Change-Id: I1e94f5b0717b947d2a7a7d36bacdf04a75cb3522
2017-10-05 19:44:28 +02:00
Neels Hofmeyr f4f23bd682 vty: install 'exit', 'end',... commands on *all* nodes
In many callers of the VTY API, we are lacking the vty_install_default() step
at certain node levels. This creates nodes that lack the 'exit' command, and
hence the only way to exit such a node is to restart the telnet session.

Historically, the VTY looked for missing commands on the immediate parent node,
and hence possibly found the parent's 'exit' command when the local node was
missing it. That is why we so far did not notice the missing default commands.

Furthermore, some callers call install_default() instead of
vty_install_default(). Only vty_install_default() also includes the 'exit' and
'end' commands. There is no reason why there are two sets of default commands.

To end this confusion, to catch all missing 'exit' commands and to prevent this
from re-appearing in the future, simply *always* install all default commands
implicitly when calling install_node().

In cmd_init(), there are some top-level nodes that apparently do not want the
default commands installed. Keep those the way they are, by changing the
invocation to new install_node_bare() ({VIEW,AUTH,AUTH_ENABLE}_NODE).

Make both install_default() and vty_install_default() no-ops so that users of
the API may still call them without harm. Do not yet deprecate yet, which
follows in Icf5d83f641e838cebcccc635a043e94ba352abff.

Drop all invocations to these two functions found in libosmocore.

Change-Id: I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b
2017-09-27 14:04:09 +00:00
Vadim Yanitskiy 463deef8c2 VTY: implement talloc context introspection command
This change introduces a new command, which could be used to
inspect the application's talloc context directly from VTY.
To enable this feature, an application need to provide it's
context via the 'vty_app_info' struct, and register the VTY
command by calling the osmo_talloc_vty_add_cmds().

The new command is a sub-command of 'show':

  show talloc-context <context> <depth> [filter]

Currently the following contexts may be inspected:

  - application - a context provided by an application;
  - null - all contexts, if NULL-context tracking is enabled.

A report depth is defined by the next parameter, and could be:

  - full - full tree report, as the talloc_report_full() does;
  - brief - brief tree report, as the talloc_report() does;
  - DEPTH - user defined maximal report depth.

Also, there are two optional report filters:

  - regexp - print only contexts, matching a regular expression;
  - tree - print a specific context, pointed by specified address.

The command output is formatted the same way as in case of calling
the talloc_report() or talloc_report_full().

Change-Id: I43fc42880b22294d83c565ae600ac65e4f38b30d
2017-09-27 11:02:19 +00:00
Max 383c5635e3 Add time conversion helpers
Add macros to break down absolute time in seconds into days/hours/minutes
passed.

Change-Id: I46b9a405c18ed9da8f31b7d5b6dcece5468bafbf
2017-09-25 14:41:41 +00:00
Neels Hofmeyr 657c5b6cad vty: derive node name from prompt, use as XML ids
The 'show online-help' produces XML output with <node id="..."> ids.  We
reference those from the osmo-gsm-manuals.

Instead of numeric IDs coming from internal code, rather use a human-readable
node ID -- referencing id='config-msc' is much easier than referencing id='23'.

Add a char name[] to struct cmd_node, to hold this name. This may be provided
upon struct definition.

Since callers of the VTY API so far don't have a name yet, we would need to add
names everywhere to get meaningful node IDs. There is a way to get node ID
names without touching dependent code:

My first idea was to find out which command entered the node, i.e. command
'msc' enters the MSC_NODE. But it is impossible to derive which command entered
which node from data structs, it's hidden in the vty command definition.

But in fact all (TM) known API callers indeed provide a prompt string that
contains a logical and human readable string name. Thus, if the name is unset
in the struct, parse the prompt string and strip all "weird" characters to
obtain a node name from that. We can still set names later on, but for now will
have meaningful node IDs (e.g. 'config-msc' from '%s(config-msc)# ') without
touching any dependent code.

When VTY nodes get identical node names, which is quite possible, the XML
export de-dups these by appending _2, _3,... suffixes. The first occurence is
called e.g. 'name', the second 'name_2', then 'name_3', and so forth.

If a node has no name (even after parsing the prompt), it will be named merely
by the suffix. The first empty node will become id='_1', then '_2', '_3', and
so forth. This happens for nodes like VIEW_NODE or AUTH_NODE.

If this is merged, we need to adjust the references in osmo-gsm-manuals.git.
This can happen in our own time though, because we manually create the vty
reference xml and copy it to the osmo-gsm-manuals.git and then update the
references from the vty_additions.xml. This anyway has to happen because
currently the references tend to be hopelessly out of sync anyway, placing
comments at wildly unrelated VTY commands.

Change-Id: I8fa555570268b231c5e01727c661da92fad265de
2017-09-23 12:24:58 +00:00
Neels Hofmeyr 4a31ffa2f0 VTY: implicit node exit by de-indenting, not parent lookup
Note: This will break users' config files if they do not use consistent
indenting. (see below for a definition of "consistent".)

When reading VTY commands from a file, use indenting as means to implicitly
exit child nodes. Do not look for commands in the parent node implicitly.

The VTY so far implies 'exit' commands if a VTY line cannot be parsed on the
current node, but succeeds on the parent node. That is the mechanism by which
our VTY config files do not need 'exit' at the end of each child node.

We've hit problems with this in the following scenarios, which will show
improved user experience after this patch:

*) When both a parent and its child node have commands with identical names:

  cs7 instace 0
   point-code 1.2.3
   sccp-address osmo-msc
    point-code 0.0.1

If I put the parent's command below the child, it is still interpreted in the
context of the child node:

  cs7 instace 0
   sccp-address osmo-msc
    point-code 0.0.1
   point-code 1.2.3

Though the indenting lets me assume I am setting the cs7 instance's global PC
to 1.2.3, I'm actually overwriting osmo-msc's PC with 1.2.3 and discarding the
0.0.1.

*) When a software change moves a VTY command from a child to a parent. Say
'timezone' moved from 'bts' to 'network' level:

  network
   timezone 1 2

Say a user still has an old config file with 'timezone' on the child level:

  network
   bts 0
    timezone 1 2
    trx 0

The user would expect an error message that 'timezone' is invalid on the 'bts'
level. Instead, the VTY finds the parent node's 'timezone', steps out of 'bts'
to the 'network' level, and instead says that the 'trx' command does not exist.

Format:

Consistent means that two adjacent indenting lines have the exact
same indenting characters for the common length:

Weird mix if you ask me, but correct and consistent:

  ROOT
  <space>PARENT
  <space><tab><space>CHILD
  <space><tab><space><tab><tab>GRANDCHILD
  <space><tab><space><tab><tab>GRANDCHILD2
  <space>SIBLING

Inconsistent:

  ROOT
  <space>PARENT
  <tab><space>CHILD
  <space><space><tab>GRANDCHILD
  <space><tab><tab>GRANDCHILD2
  <tab>SIBLING

Also, when going back to a parent level, the exact same indenting must be used
as before in that node:

Incorrect:

  ROOT
  <tab>PARENT
  <tab><tab><tab>CHILD
  <tab><tab>SIBLING

As not really intended side effect, it is also permitted to indent the entire
file starting from the root level. We could guard against it but there's no
harm:

Correct and consistent:

  <tab>ROOT
  <tab><tab>PARENT
  <tab><tab><tab><tab>CHILD
  <tab><tab>SIBLING

Implementation:

Track parent nodes state: whenever a command enters a child node, push a parent
node onto an llist to remember the exact indentation characters used for that
level.

As soon as the first line on a child node is parsed, remember this new
indentation (which must have a longer strlen() than its parent level) to apply
to all remaining child siblings and grandchildren.

If the amount of spaces that indent a following VTY command are less than this
expected indentation, call vty_go_parent() until it matches up.

At any level, if the common length of indentation characters mismatch, abort
parsing in error.

Transitions to child node are spread across VTY implementations and are hard to
change. But transitions to the parent node are all handled by vty_go_parent().
By popping a parent from the list of parents in vty_go_parent(), we can also
detect that a command has changed the node without changing the parent, hence
it must have stepped into a child node, and we can push a parent frame.

The behavior on the interactive telnet VTY remains unchanged.

Change-Id: I24cbb3f6de111f2d31110c3c484c066f1153aac9
2017-09-19 01:35:30 +00:00
Max a52d839343 Expand bit pretty-printer
Add OSMO_BIT_PRINT_EX() which is like OSMO_BIT_PRINT() but allows to
specify character to be printed for set bits. It's useful to print bytes
used as mask where set bit has particular semantics - for example TS
mask in OsmoPCU.

Change-Id: I72528bc1e376134c5a7b6e7a50c48e38c3f48b0a
Related: OS#2282
2017-09-18 09:14:28 +00:00
Max 483cdffeb8 Add define for supported a5 key length limit
Change-Id: I8ed0f1dbc31aaff22a685ceb3bd2f8db4d2f34fd
2017-08-30 09:09:39 +00:00
Neels Hofmeyr 2066a42d5a umts aka: add sqn_ms out-param, print SQN.MS in osmo-auc-gen
When doing UMTS AKA with AUTS, it can be interesting to know the SQN.MS that
was encoded in the AUTS. The only way to know this is to provide it as a
separate out-parameter from milenage_gen_vec_auts(), because the SQN.MS from
AUTS stored in umts.sqn is immediately modified non-trivially by
milenage_gen_vec(). Add sqn_ms to struct osmo_sub_auth_data to retain SQN.MS
even after a vector was generated.

Use this to print out SQN.MS for 'osmo-auc-gen -3 -A'.

Adjust test suite expectations.

Related: OS#2464
Change-Id: I9fc05bbf169d06716f40b995154fd42a3f91bef3
2017-08-29 12:46:46 +00:00
Neels Hofmeyr 95500c88b4 cosmetic: umts aka: tweak comments for sqn and ind
Clearly indicate that 'sqn' is an in *and* out-parameter.

Clarify the effect of 'ind'.

Change-Id: Ia40cd4ddf35f4fbe895b45b8ea59378f5ce9eb1f
2017-08-29 12:46:46 +00:00
Harald Welte bd3bb135a4 ports.h: Add VTY port for GGSN
Change-Id: I5bd49fbc19e88db96b4adbd56c82e7936059551c
2017-08-16 23:41:30 +02:00
Harald Welte 6c0a0e645d add osmo_fd_setup() convenience function to fill-in osmo_fd
This basically follows the concept of osmo_timer_setup() and allows
the caller to fill-in all configurable fields of osmo_fd in one
line of code, rather than open-coding it in 5 lines everywhere.

Change-Id: I6dbf19ea22fd65302bfc5424c10418d1b7939094
2017-08-12 11:43:14 +02:00
Harald Welte 4a29f34813 tlv: add [msgb_]t16lv_put() for 16bit tag + 8 bit len TLVs
In the Protocol Configuration Options IE (see 3GPP TS 24.008 10.5.6.3)
there is yet another new TLV format (derived from PPP IPCP/LCP/...)
which uses 16bit tag and 8bit length.  Let's add functions so we can
generate related TLVs.  Parsing is unfortunately not possible in our
existing structure as our tlv_parsed array only has 256 entries and
thus cannot cope with 16bit tags.

Change-Id: I9799130e2eba8fae8c4480fbb8a900c30232b694
2017-08-09 19:02:12 +02:00
Harald Welte 35b263240f Add osmo_gprs_{ul,dl}_block_size_{bits,bytes} functions
Those functions can be used to look up the size of (E)GPRS blocks.

Change-Id: I05ff75ef7dfae639886bbd09fe35f03a8af9d988
2017-08-09 19:02:12 +02:00
Harald Welte 977231cc3e Rename GSMTAP_CHANNEL_PDCH to GSMTAP_CHANNEL_PDTCH
PDCH is the physical channel, while actually we want to talk about
PDTCH the logical channel.  Introduce backwards compatibility define.

Change-Id: Id6782d2247846e2db29fc58d98684970a66db948
2017-07-29 13:35:37 +02:00
Max 8b8938f6ae BSSGP: add function to reset all PTP BVC
Change-Id: I9bf8f4dd784ccddbb9926492a85fff3293a0e913
Related: OS#1638
2017-07-28 14:54:35 +00:00
Neels Hofmeyr b970e1023d GSUP: define default GSUP port as 4222
See also:

https://osmocom.org/projects/cellular-infrastructure/wiki/Port_Numbers

https://gerrit.osmocom.org/#/c/3195/2/include/openbsc/osmo_msc.h@13
(change-id I639544a6cdda77a3aafc4e3446a55393f60e4050)

Change-Id: I4222e21686c823985be8ff1f16b1182be8ad6175
2017-07-22 11:31:06 +00:00
Neels Hofmeyr a7ccf6158c add DLMGCP logging category for libosmo-mgcp
In the course of splitting up the openbsc.git repository, we will create
libosmo-mgcp and need a library logging category for that purpose.

Change-Id: I09c587e2d59472cbde852d467d457254746d9e67
2017-07-18 10:47:56 +00:00
Harald Welte 5ade8f4b72 extend osmo_sysinfo_type with missing SYSINFO_TYPE
The list should now be complete up to Releae 14

Change-Id: I693cabe1a3b00a8c4198f7a4a1c647c5d7dc6c41
2017-07-15 22:49:19 +02:00
Minh-Quang Nguyen adc28dc7da LC15: Add IPAC Directed Retry Enquiry data structure
Change-Id: I8d2746eefe1f22dba5b19636ebc9444e458fc802
2017-07-14 16:04:59 +02:00
Minh-Quang Nguyen 17a8748324 IPAC manufacture-defined measurement pre-processing definitions
Change-Id: Ie1853697f4cff5ff98654fa1cae6c68e28a0076b
2017-07-14 15:54:50 +02:00
Harald Welte 37d204a120 socket: Add new OSMO_SOCK_F_NO_MCAST_ALL option
Using this option at socket creation, the caller can request disabling
the IP_MULTICAST_ALL socket option.

Change-Id: I5ab5de45c0b64ceb3636ea98245a23defa24ffd4
2017-07-13 16:54:23 +02:00
Harald Welte bc43a62f41 socket: Allow disabling multicast loop on socket creation
This introduces a new flag OSMO_SOCK_F_NO_MCAST_LOOP, which can be used
to disable the looping back of multicast packets transmitted throug this
socket to other local sockets on the machine.

As this looping-back is active by default, a single option to deviate
from the default is deemed sufficient.

Change-Id: I24a5b1ebc3f84d2d5d4734e54df50efaea26490b
2017-07-13 16:53:41 +02:00
Harald Welte e30d7e6018 socket.c: Add multicast related convenience functions
Change-Id: Id703e7a7a1e065181a4c76c088b8dcc1b7fe15a2
2017-07-13 16:53:37 +02:00
Harald Welte ea91a51ebe select: Add new osmo_fd_close() function
This is a convenience helper that will both close a fd, mark it as
closed and unregister it from the event loop abstraction.  In most
cases, you probably actually want to use it instead of manually closing
and calling osmo_fd_unregister().

Change-Id: Icd0933eed6a24edde7cdcb378e138897ecc5332c
2017-07-13 16:03:37 +02:00
Harald Welte aa3ba46e0f gsmtap: Add value_strings for GSMTAP_TYPE and GSMTAP_CHANNEL
Change-Id: Iaf8a99912f42a56ef785a1642e18238c0b67cf68
2017-07-13 00:03:29 +02:00
Harald Welte 93713a55b9 gsmtap_util: Add chantype_gsmtap2rsl() as inverse of chantype_rsl2gsmtap()
Change-Id: Ie1bc00670887064da0fea61c3dab036c23ceea25
2017-07-13 00:03:27 +02:00
Philipp Maier b808da44ab utils: add function gsm_fn_as_gsmtime_str()
Convert a given frame number into a printable string that displays
the sub components of the frame number.

Change-Id: I8015d2ded3940b01b35df7b72fc35c70c25e9926
2017-07-11 06:11:37 +00:00
Harald Welte 1389e86d11 Add pseudo-random bit sequence generator to libosmcoore
These PRBS sequences are specified in ITU-T O.150.  They are typically
used as test data to be transmitted for BER (bit error rate) testing.

Change-Id: I227b6a6e86a251460ecb816afa9a7439d5fb94d1
2017-07-10 23:42:02 +02:00
Harald Welte 548e371200 gsm_04_08.h: Add struct for 9.1.13b GPRS suspension request
Change-Id: I90113044460a6c511ced14f588876c4280d1cac7
2017-07-10 23:42:02 +02:00
Pau Espin 363130f3a1 gsm_utils: Add osmo_dump_gsmtime
Used by osmo-bts, moved from osmo-bts l1sap.c:dump_gsmtime.

Change-Id: Ib5452e2c20f53006c0f6d197fb055728947125d8
2017-07-10 07:44:11 +00:00
Holger Hans Peter Freyther 5a54dcbc38 gsm_04_08/sgsn: Add another IE for internal usage in the sgsn
The PDP charging characteristics will be returned from the PDP
selection code and be used in the SGSN. It is following the same
approach as the QoS and PDP addr. It is a bit of a pity that we
have to define this in a different project.

Change-Id: I7815c5dfd7b7fb0ea78d816ebfb3abfbf0090afe
2017-07-09 12:46:08 +02:00
Max 15b6d4131c Deprecate wrappers around loglevel_strs
Add deprecation notice for public API use: it shouldn't be used outside
of libosmocore anyway.

Change-Id: I792e30dc44f027fd94e1f65af19fe08bac52b95c
Related: OS#71
2017-07-08 10:39:45 +00:00
Holger Hans Peter Freyther eb55c0d4da gsup: Add encoding/decoding for the pdp charging characteristics
These fields can be in the ISD and the PDP Context inofmration. Store
pointers to this IE in both cases. It needs to be used by the SGSN
when opening a PDP context.

Change-Id: Iedc7c02adcf77ca5c9545119e19c968dfbbb3e6b
2017-07-07 21:54:38 +02:00
Max 4aaa8abcab Add missing BSSGP cause values
Add values from 3GPP TS 48.018

Change-Id: Ie39a6c91a46d179392d861805a106743a07c6fb0
2017-07-01 07:40:09 +00:00
Pau Espin 411402b4df l1sap.h: Add ber10k and lqual_cb to ph_tch_param
These fields are required in osmo-bts to do low link quality checks in a
generic way.

Change-Id: If4ae20c22b881e94585dad710f17b9e37f77bf82
2017-06-30 12:06:06 +02:00
Neels Hofmeyr 9a391e2edf fix map entry and .h declaration for gsm0808_chan_type_to_speech_codec()
Recent commit 3149b0d076 adds function
gsm0808_chan_type_to_speech_codec() but adds a completely mismatching name in
libosmogsm.map, as well as a definition with a typo in the name.

Fix the entry in libosmogsm.map.

Add the missing 'c' in gsm0808_utils.h

Change-Id: I5a621fa5ef6b632eabbe224f3dd383eacaffb695
2017-06-23 02:55:26 +02:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Neels Hofmeyr 33370cb18d doxygen: various fixes in core/timer.h
Move a longish comment to the timer group so that it appears in the API doc.

Un-doxygen some floating comments that were associated with unrelated code
items ('/**' --> '/*').

Add braces to some function names so that the API doc will render as reference
links.

Change-Id: I3ea5b88cbe9cb54702429158bf47e768e04e8fe7
2017-06-23 00:18:23 +00:00
Neels Hofmeyr fc47b03f33 api doc typo fix in core/logging.h
Change-Id: I3f1cd5b10e7beccb61f370d7f8fa2666e56542cf
2017-06-23 00:18:23 +00:00
Neels Hofmeyr 87e4550585 doxygen: enable AUTOBRIEF, drop \brief
Especially for short descriptions, it is annoying to have to type \brief for
every single API doc.

Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes
the first sentence of an API doc as the brief description.

Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-06-23 00:18:22 +00:00
Philipp Maier 4703fd215f cosmetic: remove API documentation strings in header file
Typically we don't place comments with the function declarations
in .h files. Not sure why this file has comments for each. The
API doc belongs in the .c file as proper doxygen comments,
and shouldn't be duplicated in the .h file.

In this particular case, doxygen comments are added in the
corresponding c file recently.

Change-Id: I5c4cb55be5ec59a6945b1720b875c5987f1cfaad
2017-06-22 17:08:16 +00:00
Philipp Maier 884ba0f2bc gsm0808: add function gsm0808_speech_codec_from_chan_type()
The contents of the speech codec element (struct gsm0808_speech_codec),
that is also used in the speech codec list element (struct
gsm0808_speech_codec_list) can be generated directly from the
permitted speech parameter in the channel type field (struct
gsm0808_channel_type) when full AoIP with compressed speech via
RTP/UDP/IP is assumed and when the codec configuration on the air
interface exactly matches the codec configuration on the IP backhaul.

This patch adds a function that can be used as a helper to fill
out spech codec fields by only giving a permitted speech parameter
as input.

Change-Id: I257c972e9fdf0dfe940a8d483447085bd62e50a2
2017-06-22 17:08:16 +00:00
Philipp Maier 3149b0d076 gsm0808: add function gsm0808_chan_type_to_speech_code()
The permitted speech field used in channel type element (struct
gsm0808_channel_type) uses a different representation as
the type field in the speech codec element (struct
gsm0808_speech_codec)

This patch adds a function to convert from permitted speech to
speech codec type.

Change-Id: Ib26a9c20864459b2baaa04f49b6e7902ba44b7cb
2017-06-22 17:08:15 +00:00
Philipp Maier a9b9276948 gsm0808: add default speech codec configuration
In an AoIP scenario, the speech codec list field specifies the
codecs used in the RTP interface. This patch adds a table
with default codec configurations that match the codec
configurations that are also used on the air interface.

Change-Id: I9dc0165d76a022b2c1b7418bc3133407e61b7261
2017-06-22 17:08:15 +00:00
Philipp Maier bb8396690e gsm0808: fix AoIP speech codec element parser/generator
The implementation of the parser/generator for the speech codec
information element slightly wrong, making it impossible to use
it properly.

(See also: 3GPP TS 48.008, 3.2.2.103)

Change-Id: Idabb0f9620659557672e1c6b90c75481192e5c89
2017-06-22 17:08:14 +00:00
Philipp Maier da38203418 gsm0808: add speech codec type constants
The codec type to be set in member type in struct gsm0808_speech_codec
has its own coding scheme to reference the used codec types. This patch
declares an enum with valid speech codec types.

Change-Id: Icaa768071d4364e671bc7e6d48b82d1f07f93f93
2017-06-21 20:20:02 +00:00
Philipp Maier 890f1f5a2c cosmetic: Add info about coresponding codecs to permitted speech consts
The constants in enum gsm0808_permitted_speech are not very expressive.
Add comments indicating each constant's corresponding codec.

Change-Id: I9734f7c261becffe38ffd41c304d006d08530c1a
2017-06-21 20:20:02 +00:00
Philipp Maier 3d9191ef2a gsm0408: update bearer capability speech version
3GPP TS 24.008 specifies two new speech versions for half rate and
two new speech modes for full rate. This patch adds the relevant
constants to enum gsm48_bcap_speech_ver in gsm_04_08.h

Change-Id: Id2835384c855f924332d38f01c73bd1cfdb62549
2017-06-21 20:20:02 +00:00
Philipp Maier a9e193b5dc cosmetic: Add codec references to Speech Version Indication
Add the information which GSM Speech codec version coresponds to
which bearer capability speech version.

Change-Id: Ic9493fea139420a52c32b17d00ac7d0b2bf86967
2017-06-21 20:20:02 +00:00
Philipp Maier e05c1f45ed vty: additional nodes for sccp-address configuration
The planned sccp-addressbook implementation in libosmo-sccp
requires two additional VTY nodes.

See also in libosmo-sccp.git:
Change-Id I068ed7f7d113dab88424a9d47bab7fc703bb7942

Change-Id: I42aa29c0cccc97f284b85801c5329b015b189640
2017-06-21 12:56:41 +00:00
Max dd75bacb78 Move NUM_BYTES macro to core library
It's universally useful so it make sense to have it in the shared core:
* move macro from libosmocoding to libosmocore
* add OSMO_ prefix
* add doxygen docs

Change-Id: I5386ba3e1f1cc153ba96c29dc71c9075a052aa02
2017-06-19 11:09:09 +02:00
Pau Espin 69dfe5aeec Fix compilation warning on deprecated macro
A warning was printed even if the deprecation didn't apply to
libosmocore because it is still allowed to use it internally.
This patch fixes this case while still printing a warning if external
projects build using libosmocore headers.

Change-Id: I32212f20756f828af1017482a71e29e4b3adbad4
2017-06-18 10:40:18 +02:00
Harald Welte 96e2a00d7a update/extend doxygen documentation
It's a pity that even with this patch we still are fare away from having
the whole API documented.  However, at least we have a more solid
foundation.  Updates not only extend the documentation, but also make
sure it is rendered properly in the doxygen HTML.

Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
2017-06-12 21:55:54 +00:00
Harald Welte 0eb2c5dab2 gsm0503_interleaving: Mark input arguments as 'const *'
The interleaving/deinterleaving functions were missing 'const'
qualifiers on their input data buffers

Change-Id: I2118c34a6353167787b23f877f1d81d60151aaf9
2017-06-12 15:35:27 +02:00
Harald Welte c663678b26 Add doxygen documentation to libosmocoding
This adds the minimum amount of API documentation that we should have on
all our code, particularly new code merged into a library.

Change-Id: I526804f64313867913574e50e5b9e9205ad3aa74
2017-06-12 15:35:23 +02:00
Harald Welte b9946d372c gsm0503_{coding,mapping}: Mark input arguments as 'const'
It is generally our coding style to mark pointers to constant input data
as 'const *'.  For some reason the gsm0503 coding and mapping was not
adhering to this, so let's bring it into compliance.

Change-Id: Id8731d7ae6171dff94741b6ddbb95ab5f03bfd4e
2017-06-12 12:59:21 +02:00
Harald Welte 2956737681 Add header file with definitions for GSM TS 04.14 / 3GPP TS 44.014
Change-Id: I1f4fc2761b55a4f83544c1c3793ab67fec9fc120
2017-06-12 01:57:41 +02:00
Harald Welte 3f066dde8f Update L3 protocol discriminator definitions
Change-Id: Ia699d3494b93b7f88c36338e4960b35c42a29b9c
2017-06-09 08:49:13 +00:00
Harald Welte 6789ba35a6 osmo_{fr,hr}_check_sid(): Use const input argument
Change-Id: If779cce63f06a18d4f3b0cb3d6dd7a99aa52a646
2017-06-09 08:17:38 +00:00
Pau Espin 75989e677d socket: Add osmo_sock_init2_ofd() function
Will be used by osmo-bts-trx

Change-Id: I3c655a4af64fb80497a5aaa811cce8005dba9cd9
2017-05-26 12:56:07 +02:00
Max 54ca30c8d3 Add human-readable names for signal_ns
Change-Id: Id664355eb8305fb287e4dae0800fb20dc2f9b8cd
Related: SYS#3610
2017-05-24 22:13:14 +00:00
Harald Welte 7711713b7a sercomm: More API documentation
Change-Id: I5d5002ceedd10e10d772693478f4f9cab6b1290a
2017-05-17 15:15:09 +01:00
Harald Welte 799bef5cf6 sercomm: Better integration of driver interface
We cannot assume a certain UART API like uart_baudrate() which only
exists in OsmocomBB.  Rather, use generic function prototypes
(sercomm_drv_*) which are to be provided by the application /
environment to the sercomm core.

Change-Id: I01ea3067baf1791000c1a7d537ccce496a1ab1ee
2017-05-17 15:15:09 +01:00
Harald Welte 7af6d22a4e sercomm: Include in libosmocore Makefile
Change-Id: If9d50d634381f43b2c67b97fea36a462a66e4559
2017-05-17 15:15:09 +01:00
Harald Welte 1d640889df sercomm: remove unrequired helper functions
osmo_sercomm_{bind,get}_uart() are not really needed anymore, as
sercomm_inst is public and thus the user can access the uart_id member
directly.

Change-Id: I6d57709c3764036046202f16a26c9eb87426c8d1
2017-05-17 15:15:09 +01:00
Harald Welte 8a4eb837ab sercomm: Move HDLC related defines into C file
Those values are not relevant to the sercomm user, only to the
implementation and thus can remain inside sercomm.c

Change-Id: I5700a45985b7c119c6338932171aae62ee4e2d22
2017-05-17 15:15:09 +01:00
Harald Welte ea3d3ba595 sercomm: Add doxygen-style documentation to public API
Change-Id: I2d8b11905692920d328262836420f01305be489e
2017-05-17 15:15:09 +01:00
Harald Welte f6adcd7dd6 sercomm: make rx msg size configurable per instance
Change-Id: I835506e26e83232e1e7290c0da04d389c8d7fb40
2017-05-17 10:46:40 +00:00
Harald Welte 1358836282 sercomm: introduce osmo_ naming prefix in struct and function names
Change-Id: If4e22f182a47b72b1fe43146716a4fbccceb62e6
2017-05-17 10:46:40 +00:00
Harald Welte cc95f4b06d sercomm: Enable multiple instances of 'sercomm'
Rather than having one global instance, let's permit multiple instances
of sercomm to co-exist, with all API functions extended by the instance
as first argument.

Change-Id: I0f3b53f464b119d65747bcb0be0af2d631e1cc05
2017-05-17 10:46:39 +00:00