Commit Graph

1564 Commits

Author SHA1 Message Date
Neels Hofmeyr c1aa178c8b vty api: add vty_out_va()
Provide a va_list type vty_out() variant, to be able to pass on variable
arguments from other function signatures to vty_out().

This will be used by Ibd6b1ed7f1bd6e1f2e0fde53352055a4468f23e5 for osmo_tdef.

Change-Id: Ie6e6f11a6b794f3cb686350c1ed678e4d5bbbb75
2019-02-04 16:43:57 +00:00
Neels Hofmeyr 8d04f95d96 vty telnet: consistently never change nodes upon CTRL-C
Remove any special node exiting from the VTY CTRL-C handling.

From a curious VTY transcript test glitch, I noticed weird behavior by the VTY
telnet shell: usually, when the user hits CTRL-C, that means to cancel the
current command line and present a fresh, clean prompt. However, only on the
CONFIG_NODE and CFG_LOG_NODE, a CTRL-C also exits the current node and moves up
by one level. This behavior is unexplainable and makes zero sense.

No other nodes exit on CTRL-C:
- on the ENABLE node, a CTRL-C stays on the ENABLE_NODE and doesn't exit to the
  VIEW_NODE.
- any sub-nodes of the CONFIG_NODE stay unchanged, e.g. 'network' or 'bts' /
  'trx', etc.

There is no apparent special meaning of CTRL-C on CONFIG_NODE nor CFG_LOG_NODE
to justify this odd choice.

Particularly, the vty transcript tests using osmo_verify_transcript_vty.py rely
on sending CTRL-C to clear the command prompt, so that we can properly test
sending '?' to the VTY during transcripts. In a live session, a '?' prints
available options and then updates the prompt with identical command arguments.
In a transcript test, that doesn't make sense, because each time the transcript
writes out a new command to run. Consider e.g. a transcript test like:

	tdef_vty_test(config)# timer ?
	  tea       Tea time
	  test      Test timers
	  software  Typical software development cycle

	tdef_vty_test(config)# timer tea ?
	  [TNNNN]  T-number, optionally preceded by 't' or 'T'.

To be able to issue a fresh command after '?', osmo_verify_transcript_vty.py
explicitly sends a CTRL-C to clear the command buffer. Hence there we rely on
predictable behavior of CTRL-C.

More particularly, the upcoming osmo_tdef_vty transcript tests are apparently
the first that want to test '?' behavior on the CONFIG_NODE's root level and
fall on their face, because of the implicit exit that happens only there.

Change-Id: I4f339ba61f1c273fa7da85caf77ba116ae2697b1
2019-02-04 16:43:57 +00:00
Neels Hofmeyr 9ea9dd0d5f vty: enable tab-completion for optional-multi-choice args
In cmd_complete_command_real(), detect and strip square braces from
multi-choice arguments, to enable tab-completion for commands like

 > list
 cmd [(alpha|beta)]
 > cmd <TAB>
 alpha beta
 > cmd be<TAB>
 > cmd beta

Change-Id: I8c304300b3633bb6e9b3457fcfa42121c8272ac0
2019-02-04 16:43:57 +00:00
Neels Hofmeyr b55f4d2df2 vty: enable optional-multi-choice syntax: [(one|two)]
Since very recently we sensibly handle commands like

  cmd ([one]|[two]|[three])

as optional multi-choice arguments. In addition, support the more obvious
syntax of

  cmd [(one|two|three)]

Internally, the tokens are mangled to [one] [two] and [three], which is how the
rest of the code detects optional args, and makes sense in terms of UI:

  > cmd ?
  [one]
  [two]
  [three]

(i.e. optional arguments are always shown in braces in '?' listings)

Before this patch, commands defined with a syntax like [(one|two)], would lead
to an assertion (shows as "multiple") during program startup.

Change-Id: I952b3c00f97e2447f2308b0ec6f5f1714692b5b2
2019-02-04 16:43:57 +00:00
Neels Hofmeyr c197809deb vty: enable optional-multi-choice syntax: ([one]|[two])
Add basic optional multi-choice argument support.

The VTY detects optional arguments by square braces.

 > cmd ?
 [optional-arg]
 > cmd optional-arg
 ok
 > cmd
 ok

However, within multi-choice args, these braces were so far not treated as
optional:

 > list
 cmd2 ([one]|[two]|[three])
 > cmd2
 % Command incomplete

In preparation for I952b3c00f97e2447f2308b0ec6f5f1714692b5b2 which will enable
the more obvious syntax of

  cmd [(one|two)]

for reasons of internal implementation, first support a syntax of

  cmd ([one]|[two])

The internal vty implementation always needs square braces around each option.
There is currently no good way to prevent developers from defining braces
inside multi-arguments, so it is easiest to allow and handle them:

 > list
 cmd2 ([one]|[two]|[three])
 > cmd2
 ok

The VTY doesn't guard against a mix like

 cmd (one|[two])

With this patch, a multi-choice command is treated as optional iff the first
element is in square brackets. The remaining elements' square brackets have no
effect besides confusing the user. This is not explicitly checked against.

In general, I would prefer to check all of these details, but the current VTY
code with its endless code duplication and obscure string mangling just doesn't
provide that luxury. There are numerous worse errors hidden in there.

Change-Id: I9a8474bd89ddc2155c58bfca7bd038d586aaa60a
2019-02-04 16:43:57 +00:00
Oliver Smith d6ff9c8315 GSUP: deprecate osmo_gsup_get_err_msg_type()
Replace osmo_gsup_get_err_msg_type() with a wrapper to
OSMO_GSUP_TO_MSGT_ERROR(). This macro assumes, that all error messages
are (request message | 0x000001). Add a big comment header for
osmo_gsup_message_type, describing this already implicitly followed rule
and therefore making it explicit.

With this change, we don't need to maintain the request -> error message
mapping in osmo_gsup_get_err_msg_type() anymore.

Related: Iec1b4ce4b7d8eb157406f006e1c4241e8fba2cd6 (osmo-gsm-manuals)
Change-Id: I46d9f2327791978710e2f90b4d28a3761d723d8f
2019-02-04 10:42:12 +00:00
Neels Hofmeyr 89991fdb7c osmo_fsm_inst_state_chg(): clamp timeout_secs to <= ~68 years
During testing of the upcoming tdef API, it became apparent that passing very
large timeout values to osmo_fsm_inst_state_chg() wraps back in the number
range, and might actually result in effectively very short timeouts instead.

Since time_t's range is not well defined across platforms, use a reasonable
maximum value of signed 32 bit integer. Hence this will be safe at least on
systems with an int32_t for struct timeval.tv_sec and larger.

Clamp the osmo_fsm_inst_state_chg() timeout_secs argument to a maximum of
0x7fffffff, which amounts to just above 68 years:
float(0x7fffffff) / (60. * 60 * 24 * 365.25) = 68.04965038532715

(In upcoming patch Ibd6b1ed7f1bd6e1f2e0fde53352055a4468f23e5, this can be
verified to work by invoking tdef_test manually with a cmdline argument passed
to enable the range check.)

Change-Id: I35ec4654467b1d6040c8aa215049766089e5e64a
2019-01-31 17:40:24 +01:00
Neels Hofmeyr bd5a1dc84f osmo_fsm_inst_state_chg(): set T also for zero timeout
Before this patch, if timeout_secs == 0 was passed to
osmo_fsm_inst_state_chg(), the previous T value remained set in the
osmo_fsm_inst->T.

For example:

  osmo_fsm_inst_state_chg(fi, ST_X, 23, 42);
  // timer == 23 seconds; fi->T == 42
  osmo_fsm_inst_state_chg(fi, ST_Y, 0, 0);
  // no timer; fi->T == 42!

Instead, always set to the T value passed to osmo_fsm_inst_state_chg().

Adjust osmo_fsm_inst_state_chg() API doc; need to rephrase to accurately
describe the otherwise unchanged behaviour independently from T.

Verify in fsm_test.c.

Rationale: it is confusing to have a T number remaining from some past state,
especially since the user explicitly passed a T number to
osmo_fsm_inst_state_chg(). (Usually we are passing timeout_secs=0, T=0).

I first thought this behavior was introduced with
osmo_fsm_inst_state_chg_keep_timer(), but in fact osmo_fsm_inst_state_chg()
behaved this way from the start.

This shows up in the C test for the upcoming tdef API, where the test result
printout was showing some past T value sticking around after FSM state
transitions. After this patch, there will be no such confusion.

Change-Id: I65c7c262674a1bc5f37faeca6aa0320ab0174f3c
2019-01-29 10:25:26 +00:00
Neels Hofmeyr 7740d26d7e add osmo_classmark_* API
osmo-bsc and osmo-msc implement identical Classmark structures. It makes sense
to define once near the gsm48 protocol definitions.

Also move along some generic Classmark API from osmo-msc.

Change-Id: Ifd27bab0380f7ad0c44c719aa6c8bd62cf7b034c
2019-01-29 00:59:32 +01:00
Neels Hofmeyr 0423b61aa8 add osmo_hexdump_buf() and test
Add osmo_hexdump_buf() as an all-purpose hexdump function, which all other
osmo_hexdump_*() implementations now call. It absorbs the static
_osmo_hexdump(). Add tests for osmo_hexdump_buf().

Rationale: recently during patch review, a situation came up where two hexdumps
in a single printf would have been useful. Now I've faced a similar situation
again, in ongoing development. So I decided it is time to provide this API.

The traditional osmo_hexdump() API returns a non-const char*, which should
probably have been a const instead. Particularly this new function may return a
string constant "" if the buf is NULL or empty, so return const char*. That is
why the older implementations calling osmo_hexdump_buf() separately return the
buffer instead of the const return value directly.

Change-Id: I590595567b218b24e53c9eb1fd8736c0324d371d
2019-01-28 23:58:53 +00:00
Neels Hofmeyr d01ef75ab8 gsm0808: add BSSMAP Cell Identifier matching API
Add
* osmo_lai_cmp() (to use in gsm0808_cell_id_u_matches())
* osmo_cgi_cmp() (to use in gsm0808_cell_id_u_matches())
* gsm0808_cell_id_u_match() (to re-use for single IDs and lists)
* gsm0808_cell_ids_match()
* gsm0808_cell_id_matches_list()
* Unit tests in gsm0808_test.c

Rationale:

For inter-BSC handover, it is interesting to find matches between *differing*
Cell Identity kinds. For example, if a cell as CGI 23-42-3-5, and a HO for
LAC-CI 3-5 should be handled, we need to see the match.

This is most interesting for osmo-msc, i.e. to direct the BSSMAP Handover
Request towards the correct BSC or MSC.

It is also interesting for osmo-bsc's VTY interface, to be able to manage
cells' neighbors and to trigger manual handovers by various Cell Identity
handles, as the user would expect them.

Change-Id: I5535f0d149c2173294538df75764dd181b023312
2019-01-28 23:58:53 +00:00
Harald Welte 2033be8902 Work around bogus gcc-8.2 array-bounds warning/error
gcc-8.2 is printing the following warning, which is an error
when used -Werror like our --enable-werror:

In file included from gprs_bssgp.c:34:
In function ‘tl16v_put’,
    inlined from ‘tvlv_put.part.3’ at ../../include/osmocom/gsm/tlv.h:156:9,
    inlined from ‘tvlv_put’ at ../../include/osmocom/gsm/tlv.h:147:24,
    inlined from ‘msgb_tvlv_push’ at ../../include/osmocom/gsm/tlv.h:386:2,
    inlined from ‘bssgp_tx_dl_ud’ at gprs_bssgp.c:1162:4:
../../include/osmocom/gsm/tlv.h:131:2: error: ‘memcpy’ forming offset [12, 130] is out of the bounds [0, 11] of object ‘mi’ with type ‘uint8_t[11]’ {aka ‘unsigned char[11]’} [-Werror=array-bounds]
  memcpy(buf, val, len);

Where "130" seems to be the maximum value of uint8_t, shifted right one +
2.  But even as we use strnlen() with "16" as maximum upper bound, gcc
still believes there's a way that the return value of gsm48_generate_mid_from_imsi()
could be 130.  In fact, even the newly-added OSMO_ASSERT() inside
gsm48_generate_mid() doesn't help and gcc still insists there is a problem :(

Change-Id: I0a06daa19b7b5b5badbb8b3d81a54c45b88a60ec
2019-01-22 14:53:54 +00:00
Harald Welte 1c3bae138c constrain gsm48_generate_mid() output array bounds
The longest BCd-digit type identity is the IMEISV with 16, so there's
no point in trying to parse up to 255 decimal digits, which will do
nothing but to overflow the caller-provided output buffer.

Let's also clearly define the required minimum size of the output
buffer and add a reltead #define for it.

Change-Id: Ic8488bc7f77dc9182e372741b88f0f06100dddc9
2019-01-22 14:53:46 +00:00
Harald Welte 3927cc4368 Bump version: 1.0.0 → 1.0.1
Change-Id: I51696a3ace219ab69c294b0e3637371c5460291f
2019-01-21 17:40:34 +00:00
Max b27e6feb69 Rename msgb_wrap_with_TL()
This resolves an issue introduced in 84fb5bb6a0
when msgb_wrap_with_TL() was introduced as an inline function with
*exactly the same name* as in osmo-msc.git and openbsc.git.  We *NEVER*
do something like this.  Functions moved from applications to library
*MUST* always be renamed.  This has been the case for almost a decade
now.

With this subsequent change we make sure the libosmocore function
has a different name and doesn't clash.  After this commit, old
openbsc.git and osmo-bsc.git should again build fine.

Change-Id: If1e851ac605c8d2fde3da565b0bd674ea6350c2e
2019-01-21 13:47:08 +00:00
Harald Welte a0c1cba28a Bump version: 0.12.0.128-8dfde → 1.0.0
Change-Id: I1bd973754b1ebc42283f6a07defa60f58523f5a3
2019-01-19 22:07:56 +01:00
Max 3b90125346 LCLS: make GCR into static member of osmo_lcls
Most of the time we'll have GCR filled anyway so it make sense to have
it as static parameter instead of a pointer to separately allocated
structure. Update tests to cover both static and dynamic osmo_lcls
allocation variants.

Change-Id: I905c36d8455911c68c30bc429379b7313dd46aea
2019-01-19 21:06:03 +00:00
Max 414c8f565b LCLS: add status parameter to Assignment Completed message
* add gsm0808_create_ass_compl2() with additional gsm0808_lcls_status
  parameter and make gsm0808_create_ass_compl() into trivial wrapper
  around it
* update tests accordingly

Change-Id: I547c6b8707123aa8c1ef636db88908df112d90a4
Related: OS#2487
2019-01-19 21:03:56 +00:00
Philipp Maier d6ef6f1b91 gsm29118: fix coverity issues
The function msgb_sgsap_name_put() assignes the return code of
osmo_apn_from_str() directly to len. Len is an uint8_t and the return
code an int. If osmo_apn_from_str() returns -1. Len would become 0xFF
causing a buffer overrun with msgb_tlv_put. Lets use the proper type to
catch the return code and check it before using it as length.

Change-Id: Ic0bc5114eee47bdcf2300a6e4b0df473d3d1903a
Fixes: CID#190405
Fixes: CID#190401
Related: OS#3615
2019-01-18 08:21:00 +00:00
Philipp Maier 64b51eb68b socket: add define for socket name length
The function osmo_sock_get_name_buf() can be used to write a string
representation to a user provided memory. Unfortunately the proper
length for the user provided memory is not obvious. To make using
osmo_sock_get_name_buf() more practical, add a define constant that
defines the length of the required memory. Also use this define in
socket.c.

Change-Id: If8be8c2c0d4935da17ab13b2c2127b719ceefbcc
2019-01-17 17:46:08 +01:00
Max 1bec3908c6 LCLS: add GCR comparison helper
Change-Id: I9e3b5560a058b976638d03cb819415d237ae9984
2019-01-14 23:46:34 +00:00
Neels Hofmeyr f8963f9d4e change GSM48_CMSERV_* to enum type, add names
Prepare handling multiple CM Service Requests in osmo-msc: an enum is more
clear than an int and #defines for passing around and count CM Service types.

Change-Id: I9c2a7adc45ab7a1a7519168e965e7d805e1481ff
2019-01-14 17:42:03 +00:00
Oliver Smith 894be2d9da gsm23003: add osmo_imei_str_valid()
Verify 14 digit and 15 digit IMEI strings. OsmoHLR will use the 14
digit version to check IMEIs before writing them to the DB.

Place the Luhn checksum code in a dedicated osmo_luhn() function, so
it can be used elsewhere.

Related: OS#2541
Change-Id: Id2d2a3a93b033bafc74c62e15297034bf4aafe61
2019-01-14 14:39:57 +00:00
Stefan Sperling bd6e7a9f2d port rest octets encoding code from osmo-bsc
As part of fixing issue OS#3075, we want to migrate support
for encoding system information from osmo-bsc to libosmocore.

This change ports osmo-bsc code for encoding SI rest octets.

The conversion was a bit tricky in some places because some
functions receive a 'struct gsm_bts' parameter in osmo-bsc.
In this libosmocore version, such functions expect parameters
which correspond to the individual fields of 'struct gsm_bts'
which are used by these functions.

Several structs from osmo-bsc's system_information.h are now
also declared in libosmocore headers, with an added osmo_ prefix
to avoid collisions with existing definitions in osmo-bsc.

Some helpers were ported from osmo-bsc's system_information.c
to libosmocore's gsm48_rest_octets.c. Contrary to osmo-bsc's
implementation they are now only visible within this file.

Unfortunately, this code ported from osmo-bsc lacks unit tests.

Change-Id: I47888965ab11bba1186c21987f1365c9270abeab
Related: OS#3075
2019-01-12 09:51:08 +00:00
Stefan Sperling fdf8b7b1be port arfcn range encode support from osmo-bsc
As part of fixing issue OS#3075, we want to migrate support
for encoding system information from osmo-bsc to libosmocore.

This change ports one of the prerequisites for doing so:
osmo-bsc code for range-encoding ARFCNs, including tests.

An osmo_gsm48_ prefix has been prepended to public symbols in
order to avoid clashes with existing symbols in osmo-bsc code.

Change-Id: Ia220764fba451be5e975ae7c5eefb1a25ac2bf2c
Related: OS#3075
2019-01-12 09:51:05 +00:00
Max a6749ac7d4 msgb: fix debug print
Since osmo_hexdump() use static buffers we can't re-use pointers to it
after subsequent osmo_hexdump() calls. Let's print data used for
comparison directly instead.

Change-Id: I24dc3fad6f64ef788da9b7d790f9d5f689190c42
2019-01-09 12:19:44 +00:00
Neels Hofmeyr 92f3f5e491 add osmo_lu_type_names[], osmo_lu_type_name()
Move lupd_names[] from osmo-msc to libosmo-gsm.

Change-Id: Ica25919758ef6cba8348da199b0ae7e0ba628798
2019-01-08 14:07:07 +00:00
Neels Hofmeyr 02fd83d799 add osmo_mi_name(), for MI-to-string like "IMSI-123456"
We have gsm48_mi_to_string() and osmo_bcd2str(), but still lack a function that
conveniently prints both MI type and value in one function call.

Related: http://people.osmocom.org/neels/mi_mi_mi.jpg
Change-Id: I7798c3ef983c2e333b2b9cbffef6f366f370bd81
2019-01-08 14:07:07 +00:00
Max 45f89c938d LCLS: fix LCLS-CONNECT-CONTROL encoder
Previously it could encode both incorrect values as well as incorrect
message. Let's fix this by explicitly checking for invalid values and
ensuring that at least one of the parameters is valid.

This function have no external or internal users so it's better to fix
type signature as well to match the rest of gsm0808_create_lcls_*().

Change-Id: I7b33a771acbd391c5f9a494d6450edb18511433f
2019-01-07 15:49:36 +00:00
Max 42e567c5a9 Automatically disable GnuTLS fallback
Disable GnuTLS fallback if sufficient glibc version detected. Previously
GnuTLS fallback was used regardless of getrandom() availability in
glibc. Fix this by automatically disabling it when not needed. This does
not affect the ability to manually disable it unconditionally.

Change-Id: Ibe2117afc050261668a4d5a590044aabcd08aefe
2019-01-07 15:45:00 +00:00
Max 0187c3ae37 Streamline glibc version check
* use macro for version check
* report glibc version upon random.h detection
* comment where various #endif belongs to
* explicitly check for embedded build (our target toolchain don't use
  libc so there's no point in checking its version)

Change-Id: Ia54f0b7a861f955be65bb0cf06eb10af9372d062
2019-01-07 15:45:00 +00:00
Neels Hofmeyr 0d39a8de3c osmo_rat_type: add OSMO_RAT_EUTRAN_SGS
osmo-msc is about to implement the SGs interface and requires a RAT indicator
for that.

Change-Id: I00588396bfe03feba38ecb0717d584594f0b2b46
2019-01-04 04:38:54 +01:00
Neels Hofmeyr 5b5c3499cf gsm_utils: add enum osmo_rat_type, from osmo-msc enum ran_type
In the MSC, we have RAN types GERAN_A and UTRAN_IU, now we need a similar enum
in osmo-hlr's GSUP client.

Naming: in the MAP specifications, the RAN type is mostly called RAT type,
(Radio Access Network vs. Radio Access Technology?). Since GSUP is more about
MAP messages, I'm calling the enum osmo_rat_type.

Rationale: osmo-msc and osmo-sgsn want to tell the osmo-hlr which RAT a
subscriber is calling on. A subsequent patch will extend the GSUP protocol and
add a RAT types IE.

Change-Id: I659687aef7a4d67ca372a39fef31dee07aed7631
2019-01-03 02:21:23 +01:00
Vadim Yanitskiy 785ecc9e50 logging/gsmtap: fix buffer overflow in _gsmtap_raw_output()
According to the man page, vsnprintf() returns:

  - a negative value in case of error;
  - the number of characters written (excluding '\0');
  - the number of characters which *would have been written*
    if enough space had been available (excluding '\0').

We need to detect if the output was truncated, and properly
limit the amount of bytes to be reserved within a msgb.

Change-Id: Ifa822edf900ed925ba935c54a28c797c4657358a
2018-12-28 23:58:07 +01:00
Max 470221575d LCLS: enc/dec entire parameter set instead of GCR
In 3GPP TS 48.008 the Global Call Reference IE is only used in HANDOVER
REQUEST (§3.2.1.8) and ASSIGNMENT REQUEST (§3.2.1.1) messages which
also include LCLS Config and CSC parameters. Hence, there's no point in
using GCR encode/decode functions alone.

Introduce gsm0808_dec_lcls() and gsm0808_enc_lcls() as trivial wrappers
on top of GCR enc/dec routines which are made static. Adjust tests
accordingly. Test output intentionally left unchanged.

Change-Id: Icfbb2404e1a1d500243e2071173299b557369335
2018-12-23 10:20:05 +00:00
Harald Welte 34d54b2ba7 Fix VTY documentation error introduced in "bind" VTY port change
In 99ae401e49 we introduced the ability
to specify the TCP port to which the VTY should bind.  However, the VTY
dcumentation wasn't extended accordingly, causing virtually all master
build jobs to fail.

Change-Id: I54fb0ca0d3a884a64a349b22de70f3d9bd1a6d54
2018-12-23 10:27:45 +01:00
Holger Hans Peter Freyther 99ae401e49 vty: Make TCP port configurable and introduce telnet_init_default
Extend the vty_bind_cmd VTY command to allow to optionally specify
a port in addition to the IPv4 address.

Introduce telnet_init_default to relieve client code from having
to query the bind IPv4 address (and now the TCP port). Instead a
client only needs to pass the default TCP port to use.

Client code should use it like:

	int rc = telnet_init_default(ctx, priv, OSMO_VTY_PORT_SGSN);

Change-Id: Id5fb2faaf4311bd7284ee870526a6f87b7e260f3
2018-12-23 04:20:08 +00:00
Holger Hans Peter Freyther d8d0ef6b5c vty: The telnet interface is TCP only. Fix the comments
Change-Id: I38555c4d4f565ce21dda34fc3857c47b3d802dbd
2018-12-22 18:33:22 +00:00
Oliver Smith 10db2817e5 GSUP: add CHECK-IMEI message
Implement necessary messages for Procedure Check_IMEI_VLR (TS 23.018
Chapter 7.1.2.9). This lets the VLR ask the EIR to check if an IMEI
is valid. In the Osmocom stack, we don't have an EIR and this request
will be handled by the HLR. We will be able to store the IMEI in the
HLR as side-effect (OS#2541).

This is roughly based on TS 29.002 8.7.1 MAP_CHECK_IMEI service, but
only implements the bare minimum required IEs (imei and imei_result).

Related: OS#3733
Change-Id: I085819df0ea7f3bfeb0cabebb5fd1942a23c6155
2018-12-21 13:13:30 +01:00
Oliver Smith e8c3b1bc0b GSUP: fix missing osmo_gsup_get_err_msg_type()s
Add missing mappings of request to error message types in
osmo_gsup_get_error_msg_type():
* PROC_SS_REQUEST
* MO_FORWARD_SM_REQUEST
* MT_FORWARD_SM_REQUEST
* READY_FOR_SM_REQUEST

Change-Id: I801a0d6ffe09cfc75b77ab602bd25b3dc40f19c0
2018-12-21 10:47:23 +01:00
Max af25c37f90 Use define for key buffers
Add corresponding spec. references and comments where appropriate.

Change-Id: If5e2aad86eaecd8eada667b3488ba415d81c6312
2018-12-20 09:51:02 +00:00
Max 036012b508 LCLC: fix doc to match type signature
Change-Id: I8f7b3dca080ef0e632d47a907154f8404b0ec523
2018-12-19 19:03:37 +01:00
Max e035572ea8 Fix typos in SS opcode names
Change-Id: I8fa1961c85b3fd714bc8df56fe4af6be4060c208
2018-12-19 13:52:28 +01:00
Neels Hofmeyr 0145751a97 add to osmo_sock_get_name*() API
Basically, I am applying code review that I would have given had I not been on
vacation when the last osmo_sock_get_name* stuff was merged.

osmo_sock_get_name2() is so far a static internal function. However, it is
nothing like osmo_sock_get_name(), so instead rename it to
osmo_sock_get_ip_and_port(). Also make it public API, no need to hide it.  I'm
adding an "and" in the name to hopefully clarify: "ip_port" vs. "ip_and_port"
-- there already are _get_X_ip_port() functions that only return the port
string, despite "ip" in the name.

Add new public osmo_sock_get_name2(), which is like osmo_sock_get_name(),
except it uses a static string instead of talloc, and omits the braces. This
is most convenient for log statement formats, avoiding dyn allocations.

Add new osmo_sock_get_name_buf(), which is like osmo_sock_get_name2() but
writes to a caller provided char buffer.

Use osmo_sock_get_name_buf() in the implementation of osmo_sock_get_name(),
but use another (non-static) local string buffer, because adding braces is too
complex without talloc_snprintf().

Rationale:

I want to improve the logging of socket errors, e.g. change

  DLMGCP ERROR Failed to read: 111/Connection refused (mgcp_client.c:720)

to

  DLMGCP ERROR Failed to read: r=10.0.99.2:2427<->l=10.0.99.2:2728: 111='Connection refused' (mgcp_client.c:721)

but it is just not handy to compose logging with the current API:

- osmo_sock_get_name() requires a talloc_free().
- all the others require output buffers.
- the only way to conveniently compose a logging string and,
- notably, the only trivial way to skip the string composition if the logging
  level is currently muted, is to have a function that returns a static string:
  the new osmo_sock_get_name2().
- (I think the osmo_sock_get_{local,remote}_* convenience wrappers should never
  have been added, because they encourage the caller to invoke the same code
  twice, for IP addr and port, and throw away one half each time.)

Related: Iae728192f499330d16836d9435648f6b8ed213b6 (osmo-mgw)
Change-Id: I8ad89ac447c9c582742e70d082072bdd40a5a398
2018-12-19 03:25:55 +01:00
Vadim Yanitskiy f9ee8da0cd GSUP/SMS: introduce READY-FOR-SM message
According to 3GPP TS 29.002, section 12.4, MAP-READY-FOR-SM is
used between the MSC and VLR as well as between the VLR and the
HLR to indicate that a subscriber has memory available for SMS.

This change replicates this service in GSUP as READY_FOR_SM_*.
The only mandatory IE for this service (excluding Invoke ID) is
'Alert Reason' that is replicated by OSMO_GSUP_SM_ALERT_RSN_IE.

Change-Id: Ic37f3b2114b8095cfce22977e67133b9103942e3
Related Change-Id: (docs) I549b6c8840a1e86caac09e77fb8bc5042d939e62
Related Change-Id: (TTCN) If2256607527ecfcb10285583332fb8b0515d7c78
Related: OS#3587
2018-12-18 21:52:06 +07:00
Vadim Yanitskiy c2628317cc GSUP/SMS: introduce MO-/MT-FORWARD-SM messages
According to 3GPP TS 29.002, there are two services:

  - MAP-MO-FORWARD-SHORT-MESSAGE (see 12.2),
  - MAP-MT-FORWARD-SHORT-MESSAGE (see 12.9),

which are used to forward MO/MT short messages.

This change replicates both services as GSUP messages:

  - OSMO_GSUP_MSGT_MO_FORWARD_SM_*,
  - OSMO_GSUP_MSGT_MT_FORWARD_SM_*.

Please note, that only the 'must-have' IEs are introduced
by this change, in particular the following:

  - OSMO_GSUP_SM_RP_MR_IE (see note below),
  - OSMO_GSUP_SM_RP_DA_IE (see 7.6.8.1),
  - OSMO_GSUP_SM_RP_OA_IE (see 7.6.8.2),
  - OSMO_GSUP_SM_RP_UI_IE (see 7.6.8.4),
  - OSMO_GSUP_SM_RP_MMS_IE (see 7.6.8.7),
  - OSMO_GSUP_SM_RP_CAUSE_IE (see GSM TS 04.11, 8.2.5.4),

where both SM_RP_DA and SM_RP_OA IEs basically contain
a single nested TV of the following format:

  - T: identity type (see 'osmo_gsup_sms_sm_rp_oda_t'),
  - V: encoded identity itself (optional).

According to GSM TS 04.11, every single message on the SM-RL has
an unique message reference (see 8.2.3), that is used to link
an RP-ACK or RP-ERROR message to the associated (preceding)
RP-DATA or RP-SMMA message transfer attempt.

In case of TCAP/MAP, this message reference is being mapped to the
Invoke ID. But since GSUP has no 'Invoke ID' IE, and it is not
required for other applications (other than SMS), this change
introduces a special 'SM_RP_MR' IE that doesn't exist in MAP.

Change-Id: Ibe325c64ae2d6c626b232533bb4cbc65fc2b5d71
Related Change-Id: (docs) Ie0150756c33c1352bc4eb49421824542c711175c
Related Change-Id: (TTCN) Ibf49474a81235096c032ea21f217170f523bd94e
Related: OS#3587
2018-12-18 21:52:01 +07:00
Max 5207432780 LCLS: add gsm0808_create_ass2()
It allows setting additional assignment parameters explicitly.

Change-Id: Id89765df3f8c12f55f73f1d7a9d90c8883eb3bba
Related: OS#2487
2018-12-14 13:15:39 +00:00
Max 969fb2ed84 LCLS, TS 48.008: add GCR IE encoding/decoding
* add functions to encode Global Call. Ref. from TS 29.205 as 3GPP TS
  48.008 §3.2.2.115 information element
* add corresponding tests

Change-Id: I82ce0207dc8de50689a8806c6471ad7fbae6219d
2018-12-14 13:15:39 +00:00
Max 7918f84aeb LCLS, TS 29.205: add GCR routines
Add functions to encode and decode Global Call Reference as per
3GPP TS 29.205 Table B 2.1.9.1 add corresponding tests.

Change-Id: Iee95aa4e5c056645b6cb5667e4a067097d52dfbf
Related: OS#2487
2018-12-14 13:15:39 +00:00
Vadim Yanitskiy d8fcef7794 gsm0480: fix copy-pasted note for gsm0480_gen_return_error()
InvokeID is mandatory for ReturnError component.

Change-Id: Ie1c7116d368c2029b9f524cb74ffa316e282ec83
2018-12-14 00:31:06 +00:00