Commit Graph

2323 Commits

Author SHA1 Message Date
Daniel Willmann 89106524a0 ns2: Fix argv index in logging filter VTY commands
Change-Id: I8adaf8094ef028b2d580e918532d6712d2ebbc2c
Related: SYS#5232
2020-12-04 16:52:11 +00:00
Harald Welte a59e6dbee3 gprs_ns2_fr: remove include <linux/if.h>
It's not needed because net/if.h already include
the required parts. Furthermore the linux/if.h generates
a compiler error in combination with net/if.h on older systems
(e.g. debian jessie)

Change-Id: I53650e9c55bb9dd98ba60269025e72673e9f82c1
2020-12-04 10:30:43 +01:00
Harald Welte 26fc9136b0 mnl: Use mnl_socket_open() insatead of mnl_socket_open2()
mnl_socket_open2 is not yet available on e.g. Debian 8.  Furthermore,
osmo_fd_register() will set the CLOEXEC flag on every file descriptor
anyway, so there is no benefit from using mnl_socket_open2() at all.

Change-Id: I0b37ffa148ff0c0a22281b490820353f5fef00eb
2020-12-04 10:29:07 +01:00
Harald Welte d8e59b208c libosmogb: Add missing LIBMNL_CFLAGS
In Change-Id I779556991bfc88b7751b2be17bb81c329cfb9e01 we introduced
the use of libmnl via osmo_mnl to libosmogb.  Howver, we didn't add
LIBMNL_CFLAGS in Makefile.am, which now (rightfully) fails on some
distributions like the SuSE family of distributions.

Let's fix this.

Change-Id: Ib8740e8fd677026efb9dad5d5fe6b95147fb3c23
2020-12-04 10:17:21 +01:00
Daniel Willmann 751977be6f ns2: Add log filtering by NSE/NSEI, fix NSVC filter on receive
NSVC filtering was only implemented on sending messages, this also adds
log_set_context() calls to  ns2_recv_vc()
Filtering by NSE is implemented similar to NSVC.

Change-Id: I63c0e85f82f5d08c5a6f535da94b8648498439d2
Related: SYS#5232
2020-12-03 15:14:18 +01:00
Alexander Couzens d87a2f14e6 gprs_ns2: use switch() case instead of multiple if in ns2_create_vc()
Improve readibilty and allows it to extend for future ns2 vty changes

Change-Id: I8bd9c75fb04169a166b7a3f5e13a5902250cfd0e
2020-12-03 06:15:09 +01:00
Alexander Couzens 036bf140c9 gprs_ns2: fix typo in comment
Change-Id: Ic0653ce7de8d2d64bd7cf10e148b07da8cbeb0a2
2020-12-03 06:15:09 +01:00
Harald Welte 25ee755cc7 gprs_ns2_vty: Re-introduce a 'show ns' command
In I157467d6a74d6109bc23521c978c5aac6d29fe50 we introduced a split
between 'show ns entities' and 'show ns binds'.  However, there is
at least one test case in osmo-sgsn.git which depends on 'show ns'
working.  So let's re-add it as a backwards compatible, hidden command.

Change-Id: I7571c6d82f7a712803d09d165abb6c7cb5ae2e5c
2020-12-02 22:15:34 +01:00
Harald Welte 56f08a377c gprs_ns2_fr: Monitor the kernel net-device link state
We use the newly-introduced libmnl integration of libosmocore in order
to receive netlink events from the kernel on link state changes.

If one of "our" interfaces changed link state, we report this in the log
and also store it within the "bind".

Change-Id: I779556991bfc88b7751b2be17bb81c329cfb9e01
2020-12-02 21:04:51 +00:00
Harald Welte 53a2fde368 Integrate libmnl (minimal netlink) library with libosmocore select loop
This adds an easy way to listen to netlink events form the Linux kernel
from within libosmocore applications.

The new dependency can be disabled via the "--disable-lbimnl" configure flag.

Change-Id: I4f787ee68f0d6d04f0a5655eb57d55b3b326a42f
2020-12-02 21:04:51 +00:00
Alexander Couzens b7fc3a0a6d gprs_ns2_fr: remove include <linux/if.h>
It's not needed because net/if.h already include
the required parts. Furthermore the linux/if.h generates
a compiler error in combination with net/if.h on older systems
(e.g. debian jessie)

Change-Id: Iccf931207d8bea19969fbfc4225f622a1a709972
2020-12-02 20:49:48 +00:00
Daniel Willmann cb3e9b5847 ns2: Fix docs for some NS2 vty commands
Change-Id: Ie58607424340c102c930330e444c2e219c1803e0
2020-12-02 15:50:22 +01:00
Harald Welte 1e72df0208 gprs_ns2_udp.c: Fix typo - it's a DSCP and not a DCSP
also, acronyms are typically all-caps.

Change-Id: Ia12d1fd66348f0b317405f46589f041045c513a2
2020-12-01 18:21:17 +01:00
Harald Welte dc2d080813 gprs_ns2_vty: Print all relevant data on each NS-VC
After this patch, we can finally see the BLOCKED/UNBLOCKED state,
weights, persistence, etc. in the VTY.

Example:

OsmoGbProxy> show ns entities
NSEI 00101: UDP, DEAD
 NSVCI 00101: RESET PERSIST data_weight=1 sig_wight=1 udp)[127.0.0.1]:23000<101>[127.0.0.1]:7777
NSEI 00001: FR, ALIVE
 NSVCI 00001: UNBLOCKED PERSIST data_weight=1 sig_wight=1 fr)netif: hdlcnet1 dlci: 16
 NSVCI 00002: UNBLOCKED PERSIST data_weight=1 sig_wight=1 fr)netif: hdlcnet2 dlci: 17
 NSVCI 00003: UNBLOCKED PERSIST data_weight=1 sig_wight=1 fr)netif: hdlcnet3 dlci: 18
 NSVCI 00004: UNBLOCKED PERSIST data_weight=1 sig_wight=1 fr)netif: hdlcnet4 dlci: 19

Change-Id: I1cf8fe55d1d0cecc46113532c8550880558b0155
2020-12-01 18:19:02 +01:00
Harald Welte 96ec84a035 gprs_ns_vty: Unify display of NSVCI on VTY in 'show ns entities'
Change-Id: I2915b47a5fc4ed9ac16f611c9e9f71dc0955426a
2020-12-01 18:01:43 +01:00
Harald Welte 7aa609929c gprs_ns2_vty: Show NSVCI in dump_nsvc()
also, indent the statistics one more character

Change-Id: I2726d6f1c5f83255925d6a1b22f1ee71b8d6fdc5
2020-12-01 18:01:43 +01:00
Harald Welte 2fce19a243 gprs_ns2_vty: Differentiate 'show ns binds' and 'show ns entities'
Change-Id: I157467d6a74d6109bc23521c978c5aac6d29fe50
2020-12-01 18:01:43 +01:00
Harald Welte 0ff12ad0ba gprs_ns2: Print link layer and global ALIVE/DEAD state
Change-Id: I56455d1fef2f99d72bc0c4811f307428aec12b96
2020-12-01 18:01:43 +01:00
Harald Welte 6188e004d2 gprs_ns2: Don't return an empty string in case of unknown LL
Change-Id: Id2c689ab83ada18a5cb6d70ded31aacaa701f99c
2020-12-01 18:01:43 +01:00
Harald Welte 37322bc714 gprs-ns2: Fix stringification of NS/FR NSVCI
Before this commit, gprs_ns2_ll_str_buf() would always return an empty
string.

Change-Id: I6ec07f58fa5cbb7ec4be967b2c72ae75935e4f75
2020-12-01 18:01:43 +01:00
Harald Welte 48bd76cbc0 gprs_ns2_fr: Print Frame Relay 'role' in VTY
Change-Id: I23182e5d952fd28a0bbfa76a4fc94d8e03b7a65d
2020-12-01 18:01:43 +01:00
Harald Welte a24e7ee3bd gprs_ns2: Introduce gprs_ns2_lltype_str() for link layer name
Change-Id: I4b257c09d9d3c97d6da04240c7a74a95c7c93675
2020-11-30 13:30:14 +00:00
Harald Welte b6b82da56c frame_relay: Fix error path on ioctl() failure
We don't want to pass -EINVAL as file descriptor into the bind() call.

Closes: CID#215529
Change-Id: Ic4d411c0ade6867c4fe2c01eb3368e6420158724
2020-11-30 13:29:33 +00:00
Harald Welte 29b77a61ff frame_relay: Fix null pointer dereference in DLC/PVC delete
Change-Id: I71de58f6ca15e2057f26d9c5502c8bc3e03e714f
Closes: CID#215530
2020-11-30 13:29:33 +00:00
Pau Espin 3f2775b4d2 statsd report: Fix wrong fmt specificier generating wrong stats
Fixes: OS#4871
Change-Id: I04aba0f3a4ff6563a4e285b982077184645d1180
2020-11-28 01:11:25 +01:00
Harald Welte 920491936e gprs_ns2_vty: Fix VTY documentation errors
Those two documentation errors made e.g. gb-proxy VTY tests fail.

Change-Id: I487ee3532aed4de38494005106ae9686d590608d
2020-11-25 20:57:09 +01:00
Harald Welte 6d4db2367d Revert "ns2: permit multiple nsvci in one nse in VTY"
This reverts commit 0bd8a4b5b3, which
was causing massive VTY test failures for osmo-pcu.git and osmo-sgsn.git

Change-Id: I0236d1e835111604e58c5d8c3f84221e055ce59d
2020-11-25 20:56:46 +01:00
Harald Welte 78ebc3fa31 frame_relay: Fix some spelling/language issues
Change-Id: I0ec34c0b452a46008a629f664c10dabd3f836d56
2020-11-25 17:39:06 +01:00
Alexander Couzens 10e991b224 ns2: remove obsolete type GPRS_NS2_LL_E1
There is already frame relay type GRPS_NS2_LL_FR
to support frame relay.

Change-Id: Iabb4608d91ccb32a07cad67519166dabfba76612
2020-11-24 03:53:22 +01:00
Alexander Couzens aac9016570 ns2: move link layer type into NSE
Even it was in theory possible to mix NS-VC ll types within
a NSE. This is an unrealistic configuration.
Further more to select the correct load sharing mechanism
the NSE must know the correct link layer.

Change-Id: I18dfd40a2429cd61b7c4a3dad5f226c64296f7d8
2020-11-24 03:53:22 +01:00
Alexander Couzens 24a14ac80c ns2: move LL into public api
Also fix prefix. GPRS_NS -> GPRS_NS2.
In preparation to move LL into upper layer.

Change-Id: I3b5e0d51ce69b095095e5160ca0cf0d4534db1b8
2020-11-24 03:53:22 +01:00
Harald Welte 0bd8a4b5b3 ns2: permit multiple nsvci in one nse in VTY
Change-Id: I4ad454320d0a03e81b399f55e8bd0ee57402dad0
2020-11-24 03:53:22 +01:00
Alexander Couzens fc3dd1fb14 ns2: implement link sharing selector
Change-Id: I212fa1a65e8c16cf1e525d1962d5689446c7e49e
2020-11-24 03:53:22 +01:00
Alexander Couzens 841817ec52 ns2: add support for frame relay
Add support for frame relay over dahdi hdlc device.
It's supporting lmi by q933 and supports both
SGSN and BSS.

Change-Id: Id3b49f93d33c271f77cd9c9db03cde6b727a4d30
2020-11-24 03:53:22 +01:00
Daniel Willmann dbab714343 ns2: Add a VTY command to reset NSVC FSM
Mainly useful for testing so implemented as a hidden command

Change-Id: I83b9cd7381c25da0e8aa847038a2d422c8dd63cf
Related: SYS#5002
2020-11-20 15:38:00 +01:00
Daniel Willmann ed0c982079 ns2: Add a function to set the NSVC FSM back to unconfigured
The function gprs_ns2_vs_force_unconfigured() resets the NSVC state back
to the initial value when it was first started. This can be useful for
testing.

Related: SYS#5002
Change-Id: If96d56b19959372af4eba009661be19e985b4d51
2020-11-20 15:38:00 +01:00
Daniel Willmann f5b2e28c87 ns2: Split 'initiater' into initiate_{reset,block}
Related: SYS#5002
Change-Id: Iff5aff0cf8d19d9c718dd11c4e731ced2aeb16ba
2020-11-20 15:37:46 +01:00
Alexander Couzens c06aa710d0 ns2: check if ns_vc_alloc() fails in bind_connect()
Change-Id: I82c984b9808451a72a62ff03b0495a1d09473e1c
2020-11-20 08:51:19 +00:00
Vadim Yanitskiy c1c420ce3d bts_features: add missing description for BTS_FEAT_ACCH_REP
Change-Id: Ie1d7f00b1bed43c41274bba4ce767a61cd71bb61
Fixes: Ib4d1d8d8a1a1d58bc320a1c0eff2d52100267f09
2020-11-20 01:41:15 +07:00
Harald Welte 702c998391 card_fs_usim: Add definitions of DF.ProSe and DF.ACDC
those are the only two sub-directories of Release 15 we didn't cover
yet.

Change-Id: I1f85430cbb0041766b0725df9fa97c5a82e4f38d
2020-11-17 09:56:01 +00:00
Vadim Yanitskiy 7031ac1dd2 vty/command: add 'hidden only' VTY reference generation mode
Change-Id: I511ce26350cd04bb0f66d130b5286cab84f16df2
Related: SYS#4910
2020-11-17 16:23:11 +07:00
Pau Espin 4fe8a7598a serial: Introduce API osmo_serial_speed_t
This allows usual integer parsing at app level and calling this function
to make sure correct values will be passed to
osmo_serial_set_baudrate().

Change-Id: I41415c99d26128b33a8bf5ef7b38948bd1fe5d50
2020-11-13 22:58:14 +01:00
Pau Espin 28acb21321 serial: Log error if tcgetattr() or tcsetattr() fail
Change-Id: I79121e016f045c9d0555881359cd3008320223ed
2020-11-13 22:58:02 +01:00
Pau Espin 71ba873cc1 serial: Fix typo in debug log line
Change-Id: Ibfe70a42649512719be3c3ae42b5fad8b28a800a
2020-11-13 22:58:00 +01:00
Pau Espin 23999dac6e cosmetic: serial: Fix typo in comment
Change-Id: I5d4901e01af477ebb815f70a5326ada6224c4be8
2020-11-13 22:57:49 +01:00
Pau Espin 4c951adcf4 bitvec: Fix left shifting out of range on signed variable
Fixes following ASan runtime errors spotted by TypeTest osmo-pcu unit test:
libosmocore/src/bitvec.c:275:13: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

Change-Id: I70502044d05c0505a4b65c1e12e89ff657afe804
2020-11-13 12:09:02 +01:00
Philipp Maier e36be56fc8 gsm_04_08: add parser for Mobile Station Classmark 3
3GPP TS 24.008 section 10.5.1.7 describes a Mobile Station Classmark 3
IE, which is encoded as CSN.1 struct. This means that it can not be
parsed by just casting a memory location to a struct pointer, so lets
add a parser to parse the CM3 IE.

This is fixed version of Ic8b2bfd00330235f5bed00771e421588abfaac1f,
which got reverted because it used the keyword "class" as struct member,
which lead into problems with c++ builds. This is now fixed.

Change-Id: Id8732551b33616227609cd6fcf6c3133751a89eb
Related: OS#4796 SYS#5114
2020-11-12 15:55:31 +00:00
Harald Welte c2118940aa Revert "gsm_04_08: add parser for Mobile Station Classmark 3"
This reverts commit a4939dc846,
which caused massive build failures in C++ programs like osmo-pcu
- unsurprisingly, as it calls a struct member "class", which is a
reserved keyword in C++.

Change-Id: Ia43e56385e7b580f492c560aee8ff8b1e8a0e1d8
2020-11-11 23:11:15 +01:00
Pau Espin 1b75e4bbd1 tdef: Introduce OSMO_TDEF_US unit
Some applications may need submillisecond timers, such as those
interacting with modbus serial lines (RS-485, RTU), which require
timers of values around 1.5 char-time (T1.5), where a data char is
composed of 11 bits sent on the line: 1 start bit, 8 data bits,
1 stop bit, and and parity bit (or 2nd stop bits if no parity).

For instance, for a baudrate of 9600:
1.5 * 11 / 9600 = 1.718 ms = 1718 us

So having a granularity of MS is not enough here.

Change-Id: I71848d7c1ee0649929ce07680ee7320bb2a42f0e
2020-11-11 20:08:26 +00:00
Philipp Maier a4939dc846 gsm_04_08: add parser for Mobile Station Classmark 3
3GPP TS 24.008 section 10.5.1.7 describes a Mobile Station Classmark 3
IE, which is encoded as CSN.1 struct. This means that it can not be
parsed by just casting a memory location to a struct pointer, so lets
add a parser to parse the CM3 IE.

Change-Id: Ic8b2bfd00330235f5bed00771e421588abfaac1f
Related: OS#4796 SYS#5114
2020-11-10 16:36:54 +01:00
Harald Welte f396b96e66 card_fs_usim.c: Add support for DF.5GS directory
card_fs_usim already contained definitions up to Rel-15, but somehow
didn't add the DF.5GS yet.

Change-Id: I9f8102dc7e5a865193ff9930dfc48c5f2e6ecbcf
2020-11-10 15:33:49 +00:00
Philipp Maier a15967ba98 gsm_08_58: add proprietary IE to signal Repeated ACCH Capability
3GPP TS 24.008, section 10.5.1.7 specifies a Repeated ACCH Capability
bit in the Classmark 3 IE. Unfortunately, there is no way specified how
the Repeated ACCH feature should be controlled on RSL level. Since it is
not unusual that BTS/BSC vendors occassionally add proprietary IEs to
different RSL messages we may pick this as a solution as well and add a
propritary RSL_IE_OSMO_REP_ACCH_CAP IE, so that we can enable repeated
FACCH/SACCH on the BTS side when we send RSL CHAN ACT or RSL CHAN MODE MODIFY
messages.

Change-Id: I61ea6bf54ea90bd69b73ea0f0f3dc19a4214207b
Related: OS#4796 SYS#5114
2020-11-09 23:41:10 +01:00
Alexander Couzens 0ab028c84e ns2: fixup gprs_ns2_prim_strs
The gprs_ns2_prim_strs was merged to early. The renaming
in the last gerrit patchset wasn't done correct.

Change-Id: Ie8e1e003d70af48f2d647b2c2701d4fc0f17e307
2020-11-09 11:07:17 +00:00
Pau Espin 64c67bb088 vty: Mark cpu_sched_vty commands with attr immediate
Change-Id: I85c80376c13c7dddf34dadd2a6c09caf23fd70ce
2020-11-09 11:24:21 +01:00
Daniel Willmann ed1fa018c3 ns2: Improve NSVC output
In show ns lots of info was printed many times. We can just use
gprs_ns2_ll_str() to get the information about an NSVC so use that and
ensure newlines.
The NSVC are still printed twice - at least for the UDP bind: Once in
dump_nse and once in dump_bind.

Change-Id: I6f734d92ec1e17f339f7b32e449ffd614efa7319
Related: SYS#4998
2020-11-06 15:40:27 +01:00
Daniel Willmann 15c09a81e9 ns2: Send NSVC representation in NS_AFF_CAUSE_VC_* status indication
NS_AFF_CAUSE_VC_* failure and recovery should indicate the NSVC in
question. Use the string representation reported by gprs_ns2_ll_str()
for that.

NS_AFF_CAUSE_VC_RECOVERY was never sent so do that on unblock as well.

Change-Id: Iad6f0dc4565a46868cbbe17c361dcd473006c83d
Related: SYS#4998
2020-11-06 11:41:16 +01:00
Daniel Willmann f128654c7f ns2: Add gprs_ns2_nsvc_state_name() to get the current state of a VC
Change-Id: I4c4c5b9142d7240ed452218e263ba12e2b70d1a0
Related: SYS#4998
2020-11-06 10:23:44 +00:00
Alexander Couzens cce8828238 libosmocore: change the memory management of NS2
Until now NS2 always free'd it's own memory. Even when the msg
was sent as primitive to the upper layer.
Change the memory ownership when sending a primitive to the upper layer.
The upper layer has to free the msg buffer.

Merge together with: I180433735bfbb3375c41318d7a7709d5845199ba (osmo-pcu)

Change-Id: Id844d7acbcab102a7dc472d608a5e97a748ecb43
2020-11-03 22:37:45 +00:00
Daniel Willmann 2d42b90dbb libosmogb: Add a function to tx BVC RESET by nsei/bvci
This is needed for osmo-gbproxy where we need more control over BSSGP.

Related: SYS#4998
Change-Id: Ifa769bce920a08cf93553dcb164a3fcf50162517
2020-11-03 10:14:00 +00:00
Vadim Yanitskiy f5f0d4304a gsm48: add missing RR cause value definitions
3GPP TS 44.018 version 15.4.0 Release 15 (2019-04).

Change-Id: If7187e005d65fd2bf067d258148281c5df0526ff
2020-10-29 18:23:06 +07:00
Vadim Yanitskiy 65954bac13 fix spelling in 'value_string' arrays: existAnt -> existEnt
It could be that this spelling variant was originally used in the
specs., but now at least in 3GPP TS 44.018 they use 'existEnt'.

Change-Id: I847de910411f2edf7cc45b8c296b43e65fed5447
2020-10-29 18:09:36 +07:00
Alexander Couzens b3b837c5e8 gprs_ns2: convert gprs_ns2_cause_str into an static inline
Be consistent with other implementation of get_value_string() in
libosomocore.

Change-Id: Ic79757df8683e0461c04f7ef9279e4fe645eb821
2020-10-27 14:49:03 +00:00
Alexander Couzens 2498f1db9d ns2: add value strings for ns2_affecting_cause_prim_str & ns2_prim_str
Change-Id: Ibf610fbd929dddc4a4e235152447caff522d4eb2
2020-10-27 15:24:47 +01:00
Alexander Couzens 0346b643b5 gprs_ns2: remove the nsvc fsm timer when cleaning up the fsm
Change-Id: I9c7f767077ed2e354d0980a9f11246c1151c65e2
2020-10-27 13:53:08 +00:00
Pau Espin 0a446a1804 gb: ns2_sns: Add missing value_string entry for GPRS_SNS_EV_NO_NSVC
Change-Id: Ifd4501676217f1a27f3ee02156be4e3dcb847703
2020-10-27 13:30:08 +01:00
Pau Espin 7fbe7cfcd7 gb: ns2_sns: Fix missing trailing newline char in log line
Change-Id: I8dc45237a605e76e852a74a0de91ac2a812387d0
2020-10-27 13:27:18 +01:00
Vadim Yanitskiy 0a2d9bdfae vty/command: fix: restrict the expert mode to the current session
Having the expert mode flag stored in the global 'host' structure
was a bad idea, because this way it applies globally.  In other
words, if user Bob activates the expert mode in his dedicated
session (e.g. a telnet connection), then not only him, but all
other users would see the hidden commands in their VTYs.

Moreover, if somebody deactivates the expert mode, it would also
affect the Bob's VTY session.  And finally, terminating a VTY
session would not deactivate the expert mode.

Let's move that flag from the global 'struct host' to 'struct vty'
representing an individual VTY session, so then the expert mode
would only affect the session where it was activated.

In functions related to the XML VTY reference generation we don't
have access to 'struct vty' (there may be no VTY session at all).
Add two additional arguments to vty_dump_nodes(), indicating the
global flag mask and a matching mode.  This would allow to match
the VTY commands in many different ways, e.g. one can dump hidden
commands only, or all commands except the library specific ones.

Change-Id: Iba13f0949061e3dadf9cf92829d15e97074fe4ad
Related: SYS#4910
2020-10-25 16:52:42 +07:00
Harald Welte b904e428aa select: Migrate over to poll()
select is an ancient interface with weird restrictions, such as
the fact that it cannot be used for file descriptor values > 1024.

This may have been sufficient 40 years ago, but certainly is not in
2020.  I wanted to migrate to epoll(), but unfortunately it doesn't
work well with the fact that existing programs simply set osmo_fd.flags
without making any API calls at the time they change those flags.

So let's do the migration to poll() as a first step, and then consider
epoll() as a second step further down the road, after introducing new
APIs and porting applications over.

The poll() code introduced in this patch is not extremely efficient,
as it needs to do extensive linked list iterations after poll() returns
in order to find the osmo_fd from the fd.  Optimization is possible,
but let's postpone that to a follow-up patch.

At compile time, a new --enable-force-io-select argument can be given
to configure, forcing the use of the old select() backend instead of the
new poll() based backend.

Change-Id: I9e80da68a144b36926066610d0d3df06abe09bca
2020-10-23 15:09:05 +00:00
Vadim Yanitskiy 6760845da6 vty/command: add CMD_ATTR_HIDDEN to CMD_ATTR_PUBLIC_MASK
Otherwise in the expert mode, hidden commands do not get the
associated attribute printed to the XML VTY reference.

Change-Id: I8ded973031beb6d8c7ad55f06641c9651b1d9e71
Related: OS#4910
2020-10-23 20:37:37 +07:00
Vadim Yanitskiy 4165d048f3 vty/command: introduce vty_dump_xml_ref_mode()
This change introduces an enumerated type 'vty_ref_gen_mode' that
(as the name suggests) defines the VTY reference generation mode:

  - DEFAULT - all commands except deprecated and hidden,
  - EXPERT - all commands including hidden, excluding deprecated;

and a new function vty_dump_xml_ref_mode(), that allows to specify
that mode.  The old vty_dump_xml_ref() is now deprecated.

Change-Id: Ie2022a7f9e167e5ceacf15350c037dd43768ff40
Related: SYS#4910
2020-10-23 20:20:23 +07:00
Vadim Yanitskiy efe1342b62 vty/command: make some 'struct cmd_element' pointers const
Change-Id: I4a8b3bada44538a5e5711bbc4dccf8b2cf3e2e08
2020-10-21 20:36:21 +07:00
Pau Espin 76190d308d lapdm: Allow SABM L=0 in Timer Recovery State
3GPP TS 44.006 8.6.3 "Procedures for re-establishment" is quite
explicit:
"""
When the data link layer receives in the multiple frame established state
or !!!timer recovery state!!! a DL-ESTABLISH- REQUEST primitive from layer
3 or an SABM (with L=0), the normal establishment procedure of sub-clause
8.4.1.2 shall be initiated.
"""

If L>0 in that state, send a DM as stated in 8.4.1.2:
"""
If the data link layer entity is unable to enter the multiple-frame-established
state, it shall respond to the SABM command with a DM response with the F bit
set to the same binary value as the P bit in the received SABM command.
"""

Related: OS#4549
Related: OS#4819
Change-Id: I7959dc39f883cd5c56c36a21176a2401838d7b62
2020-10-21 13:03:30 +00:00
Pau Espin d5f7147419 lapdm: Split lapd_rx_u() spaghetti into one function per message type
Change-Id: Ia1a49f7ae1d133174fad7a396db72867612fa619
2020-10-21 13:03:30 +00:00
Pau Espin 16333bb58c lapdm: Drop log lines printing fmt=B
Change-Id: Ic8794ee66ddeb45ebcc7b9834f4d5e8321fd91f1
2020-10-21 11:54:23 +00:00
Vadim Yanitskiy 72b90883f9 vty: introduce the expert mode and a command to enable it
Some VTY commands are intentionally hidden, e.g. because they might
by relatively dangerous if used in production operation.  We equip
such commands with a special attribute - CMD_ATTR_HIDDEN.

The problem is that neiter they appear in the XML VTY reference,
nor in the online VTY help, so it's a bit tricky to invoke them.
This change introduces so-called 'expert' mode, in which hidden
(but not deprecated) commands are getting visible.

In the (telnet) VTY session, this mode can be activated by passing
an additional argument to well-known 'enable' command:

  OsmoApp> enable ?
    [expert-mode]  Enable the expert mode (show hidden commands)
  OsmoApp> enable expert-mode
  OsmoApp#

so then hidden commands will appear together with all the other
commands.  They will be marked with a special '^' flag:

  OsmoApp# list with-flags
    ^ ...  foo-hidden [expert-mode]
    . ...  foo-regular-one
    ! ...  foo-immediate
    ^ u..  app-hidden-unbelievable

For the XML reference generation, additional API needs to be
introduced.  This will be implemented in subsequent patches.

Change-Id: Ie69c2a19b22fb31d7bd7f6412f0aeac86ea5048f
Related: SYS#4910
2020-10-21 06:27:48 +07:00
Vadim Yanitskiy e7bf4354b9 logging: introduce 'systemd-journal' target
This change implements 'systemd-journal' logging target, that is
similar to the existing 'syslog' target.  The key difference is
that 'systemd-journal' allows us to offload rendering of the meta
information, such as location (file name, line number), subsystem,
and logging level, to systemd.  Moreover, we can attach arbitrary,
user-specific fields [1] to the logging messages, so they can be
used for advanced log filtering (e.g. by IMSI/TMSI/TLLI):

  $ journalctl OSMO_SUBSYS=DMSC -f

Since we don't want to make libsystemd a required dependency, this
feature is optional, and needs to be enabled at build-time:

  $ ./configure --enable-systemd-logging

The new logging target can be configured in the same way as any
other one - via the VTY interface, or using the configuration file:

  log systemd-journal [raw]
    logging level set-all notice
    logging filter all 1

Two logging handlers are available: generic and raw.  The first one
behaves similarly to both 'syslog' and 'stderr', i.e. all the meta
information is rendered by libosmocore itself, and then passed to
systemd together with the logging message.  The later is more like
the 'gsmtap' target, so all available meta information is handed
over to systemd in form of fields [1]:

  - CODE_FILE / CODE_LINE - location info,
  - PRIORITY - syslog-compatible logging level,
  - OSMO_SUBSYS - Osmocom-specific sub-system (e.g. DMSC),
  - OSMO_SUBSYS_HEX - same as OSMO_SUBSYS, but encoded in hex,
  - MESSAGE - the logging message itself,

and then can be rendered in any supported format (e.g. JSON).

More details about the API can be found in [2].

[1] https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html
[2] https://www.freedesktop.org/software/systemd/man/sd-journal.html

Change-Id: I609f5cf438e6ad9038d8fc95f00add6aac29fb23
2020-10-19 15:02:00 +00:00
Harald Welte 7e65791b66 select: Introduce osmo_fd_{read,write}_{enable,disable}()
If we watn to migrate to something like epoll(), user application
code must call a function of the libosmocore API whenever it changes
its read/write interest in a file descriptor.

Let's introduce API so applications can be ported to this API,
before making direct 'ofd->when' manipulations illegal as a second step.

Change-Id: Idb89ba7bc7c129a6304a76900d17f47daf54d17d
2020-10-19 09:54:17 +00:00
Vadim Yanitskiy fdaec8e706 rsl: rsl_chan_nr_str_buf(): use ABIS_RSL_CHAN_NR_CBITS_* macros
Change-Id: I3cd745e180787ea5c22f2a13441d599e0220d81f
2020-10-17 00:27:12 +07:00
Harald Welte 65aabd437c [cosmetic] rest_octets: Follow coding style regarding {}
As pespin point out, the kernel coding style says:

Do not unnecessarily use braces where a single statement will do.
[...]
This does not apply if only one branch of a conditional statement is a single
statement; in the latter case use braces in both branches:

Change-Id: Ia23c4bd018db141ff0afe77fe25678a9b2a395f0
2020-10-15 08:06:08 +02:00
Harald Welte 5e1cd5e411 gsm48_rest_octets: Add parser for SI4 rest octets
Introduces osmo_gsm48_rest_octets_si4_decode()

Change-Id: I9d6ed06731ae15fdcef1a1f397d6ac2b7b1ca980
Related: OS#3075
2020-10-15 08:01:43 +02:00
Neels Hofmeyr b85c87aec6 gad.c: fix rc for osmo_gad_enc_ell_point_unc_circle()
Related: CID#214889
Change-Id: If9bb6ab22280e0dc66ca21bba9409d817603dd4f
2020-10-15 01:02:04 +00:00
Neels Hofmeyr 9faeacd6a1 gad.c: try to workaround warning for "h.type >= 0"
The DEC_ERR() macro has a check for a missing type, but when used on the uint
h.type variable, emits a warning about an always-true statement. Try to work
around that warning with a cast to (int).

Related: CID#214888 CID#214890 CID#214891
Change-Id: Ic5fa87d23a6f0ce872de9c1dcfe36023981f70de
2020-10-15 01:02:04 +00:00
Pau Espin 86160ace73 gsm: Fix make distcheck with parallel make
Change-Id: I0bab4cfbc82d2b0aa7bd07769000ab8e4968a00b
2020-10-13 08:24:03 +00:00
Alexander Couzens 80788fac9e add osmo_sockaddr_to_str_buf/osmo_sockaddr_to_str
Add helper to format osmo_sockaddr into a string.

Change-Id: I917f25ebd1239eae5855d973ced15b93731e33a0
2020-10-12 15:13:43 +00:00
Alexander Couzens d420ea9dce gprs_ns2: add gprs_ns2_ip_vc_equal()
Compare the NS-VC with the given parameter

Change-Id: I3a0cd305fd73b3cb9ec70246ec15ac70b83e57f2
2020-10-12 15:13:43 +00:00
Pau Espin 5bc9f3854d cosmetic: vty: Fix trailing whitespace
Change-Id: Ieea7d13161440326d58f80f1fbc9f7e3fa5a40af
2020-10-12 15:09:37 +00:00
Pau Espin 715a612aba vty: Fix left shifting out of range on signed variable
Fixes following ASan runtime errors while running vty tests:
src/vty/command.c:3088:27: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
src/vty/command.c:3136:23: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

Change-Id: Ie11ff18d6fd9f6e1e91a51b6156fb6b0b7d3a9a8
2020-10-12 15:09:37 +00:00
Alexander Couzens 8ebc1acbaa gprs_ns2: Partial revert 48f63867 allow to create NS_ALIVE NSVC
NS_ALIVE can't create new NS-VC. Those NS-VC can be only created
by SNS or by vty.
Also fixes a crash because the TLV parser tried to retrieve NSEI TLV
which doesn't exist on NS_ALIVE PDUs.

Related: OS#4792
Change-Id: I16b9d7b2eb7544a83ce871d894887c4b30605b34
2020-10-12 14:15:50 +00:00
Alexander Couzens 6cb5d5f2e0 gprs_ns2: add gprs_ns2_nse_foreach_nsvc()
Allow to loop over all NSVC within a NSE via a callback

Change-Id: I5a2bb95d05d06d909347e2fb084a446ead888cb3
2020-10-12 15:54:21 +02:00
Alexander Couzens d33512b997 gprs_ns2: gprs_ns2_ip_vc_remote() the nsvc can be also const
Change-Id: Ia000f535f18f21b41038f2ce7721f0fb59f6a093
2020-10-12 15:54:21 +02:00
Alexander Couzens 125298f2b5 gprs_ns2: add gprs_ns2_nse_sns_remote() returns the initial SNS address
Allows the PCU to get the SNS remote address.

Change-Id: I54f110acc3acccb362f6e554324d08cc42b7c328
2020-10-12 15:54:21 +02:00
Alexander Couzens 979f5f5449 gprs_ns2: add gprs_ns2_ip_vc_local() return the local sockaddr
Change-Id: I65a739772596015b90473045d32d4934d924e43f
2020-10-12 15:54:21 +02:00
Alexander Couzens c4229a458c gprs_ns2: rename gprs_ns2_ip_vc_sockaddr -> gprs_ns2_ip_vc_remote
It's more clear which part of the address is returned.
In preparation to add a gprs_ns2_ip_vc_local.

Change-Id: I6110ff573362961c713a990da7ef3f3dbedf6c57
2020-10-12 15:54:21 +02:00
Alexander Couzens 9a4cf275b2 gprs_ns2: const the return value of gprs_ns2_ip_vc_sockaddr / gprs_ns2_ip_bind_sockaddr
The sockaddr should not be changed.
free and create the bind/nsvc if the address should be changed.

Change-Id: I371ac2361b569e36722b02fc9cd82ec8da2fa9e3
2020-10-12 13:08:42 +00:00
Alexander Couzens 4b6c8afcb2 gprs_ns2: add gprs_ns2_free_nses() to free all NS-E
Allow users to clean up most of the state (e.g. the PCU).

Change-Id: Ia00753a64b7622a0864341f51ea49b6963543755
2020-10-12 13:08:42 +00:00
Alexander Couzens 896fcd5c80 gprs_ns2: add gprs_ns2_free_binds() to free all binds
Allow users to clean up all binds (e.g. the PCU).

Change-Id: Ic8f6f8aca10da23a18fab8870be7806065a34b47
2020-10-12 13:08:42 +00:00
Alexander Couzens 05e7f7dd99 gprs_ns2: add gprs_ns2_nse_nsei() to get the nsei of a nse
Change-Id: I5f67e6a9bf4cb322bd169061fee0a528012ed54d
2020-10-12 13:08:42 +00:00
Alexander Couzens 6090b1db4b gprs_ns2: gprs_ns2_ip_bind() check if the bind already exists
To prevent adding the same bind twice. It also returns
the bind in **result.

Change-Id: Ib816f14c387cc6ff86f9c0057daded1d72cee0f5
2020-10-12 13:08:42 +00:00
Alexander Couzens 4f60845552 gprs_ns2: add gprs_ns2_ip_bind_by_sockaddr() to search for binds by sockaddr
Change-Id: I48c3f1a82574eee0a49e6941cf9e1365c2302d3b
2020-10-12 13:08:42 +00:00
Alexander Couzens bb0a53ba40 gprs_ns2: fix empty prefix in TLV Parse error
Those messages were printed without any prefix because
LOGPC was used. LOGPC means continue a log line.
This must happened while copying this part of code over
from ns1 where has been a LOGP in this function.

Related: OS#4792
Change-Id: I2672ea0e34d19ea6172cb3458b8ff98d9700b2d0
2020-10-12 10:54:46 +00:00
Alexander Couzens c068d860a5 gprs_ns2: fix SNS_ADD for IPv4
The remote must be initialized because the osmo_sockaddr_cmp is using a memcmp() and might fail
on spare bytes in the struct. The same was already done for IPv6.

Related: OS#4792
Change-Id: Iefeef969bb2b5ae4d5db6a6358293ef9eeda858a
2020-10-12 10:54:39 +00:00
Alexander Couzens 3531504d52 gprs_ns2: gprs_ns2_free(): add missing talloc_free
It clean up all the space except the nsi itself.

Change-Id: Ia3fbe5d679d0af75b2b0db020f1eb082d629cf50
2020-10-10 03:28:17 +02:00
Neels Hofmeyr 6d744989e2 doc tweaks for osmo_float_str_to_int(), osmo_int_to_float_str*()
Drop nonexistent arg from api doc, fix "factor of a million", and explain a bit
more.

Change-Id: I131e839b6b7dd601b859313b358d346904c0e145
2020-10-09 19:23:34 +00:00
Vadim Yanitskiy a07f25e3ba gprs_ns2: make struct osmo_sockaddr pointers const
Using the 'const' qualifier allows the compiler to spot some
programming errors and further optimize the code.

Change-Id: I0df6a00ac1830bd64a10b9336b827e113fa772bb
2020-10-09 15:24:09 +00:00
Vadim Yanitskiy def5a407c1 socket: make the arguments of osmo_sockaddr_cmp() const
Change-Id: Ibfdfdd40c52709b32ac934974cc78ee821fa83ba
2020-10-09 15:22:49 +00:00
Harald Welte 36be9d890e gprs_ns2: Fix parsing of SNS-{ADD,DEL,CHANGE_WEIGHT}
Change-Id: I94c12986f8255e4373b13b1a8fae3df08004ad96
Related: OS#4791
2020-10-09 16:12:01 +02:00
Pau Espin aa83d4110b gprs_ns2_udp: Avoid dangling freed struct in list if binding fails
Change-Id: Ic54434b7cfc40136788257e768cae7a2b5d5bc79
2020-10-09 14:20:13 +02:00
Harald Welte cb11a60d25 osmo_float_str_to_int: When using strtoll(), use LLONG_{MAX,MIN}
When we use strtoll(), the return type is "long long" and we cannot
compare against LONG_MAX and LONG_MIN but must compare against LLONG_MAX
and LLONG_MIN.

Change-Id: I9c18ac237b4aacd56639d1faffa6841c8ad7b8da
Closes: OS#4787
2020-10-09 10:10:07 +02:00
Philipp Maier a5218ea9b3 command: add library command attribute for libosmo-abis
Change-Id: I0efc57f2cb54798ba207ae6fef9af4771d96bfa9
Related: SYS#4937, OS#1601
2020-10-08 19:08:17 +02:00
Harald Welte bd771a9576 bssgp: Don't include RA-ID in BVC-RESET for BVCI=0 (signalling)
3GPP TS 48.018 is quite clear: The RA-ID must only be included
when a PTP-BVCI is being reset [and only if the sender is the BSS].

Before this patch, osmo-pcu is including the RA-ID in BVC-RESET
for BVCI=0.

Change-Id: Ie87820537d6d616da4fd4bbf73eab06e28fda5e1
2020-10-08 07:18:39 +00:00
Neels Hofmeyr 5b214e2847 add BSSMAP coding for Location Services
BSSMAP: add A-interface messages between MSC and BSC:
- Perform Location Request
- Perform Location Response
- Perform Location Abort

Change-Id: I4d7302a4853518916b6b425e710c10568eb2ffe5
2020-10-07 15:37:50 +02:00
Neels Hofmeyr 02de87bd5c add BSSMAP-LE coding for Location Services
BSSMAP-LE: add Lb-interface messages between BSC and SMLC:
- Reset
- Reset Acknowledge
- Perform Location Request, possibly containing BSSLAP TA Layer3
- Perform Location Response
- Perform Location Abort
- Connection Oriented Information containing any BSSLAP APDU

Add encoding and decoding tests.

Change-Id: I271e59b794bafc0a7ae0eabbf58918f6d7df431d
2020-10-07 15:37:50 +02:00
Neels Hofmeyr c6848f4145 add BSSLAP coding for Location Services
BSSLAP: there are APDUs transferred in BSSMAP-LE Connection Oriented
Information messages on Lb between BSC and SMLC.
Add BSSLAP coding for these APDU messages:
- TA Layer3
- TA Request
- TA Response, possibly containing Location Estimate coded in GAD
- Reject
- Reset (for intra-BSS handover during TA Request)
- Abort (for inter-BSS handover)

Add encoding and decoding tests.

Change-Id: I6409c4bcac402dc7626a3afce9081c59cd715fe8
2020-10-07 15:19:43 +02:00
Neels Hofmeyr 086bd33f18 add GAD coding for Location Services
GAD, Universal Geographical Area Description:
- raw coding for all GAD elements.
- SI-units encoding and decoding for Ellipsoid point with uncertainty circle,
  which I presume is the typical "at most N meters away from cell tower located
  at X,Y", which corresponds to the TA positioning currently being implemented.
- other SI-units GAD element encodings are so far not implemented.

Add encoding and decoding tests.

In gsm/protocol/gsm_23_032.h are the raw coding structs as defined in 3GPP TS
23.032.

In gsm/gad.h are structs carrying consistent units based on meters and degrees,
for convenient / less error prone handling of GAD data, and for human readable
representations of the GAD data.

The separation of the two is desirable because OsmoBSC will receive GAD data
from OsmoSMLC on the Lb interface, and pass on this data to the MSC via the A
interface. It is better to pass the GAD data as-is without de/encoding.

Change-Id: I7a9dd805a91b1ebb6353bde0cd169218acbf223c
2020-10-07 11:39:46 +00:00
Neels Hofmeyr 87c3afb5a9 add osmo_float_str_to_int() and osmo_int_to_float_str_*()
This will be useful to handle latitude and longitude numbers for GAD, which is
the location estimate representation used for LCS (Location Services).

The OsmoSMLC VTY user interface will provide floating-point strings like
"23.456" while GAD stores them as micro-degress 23456000. The osmo_gad_to_str*
will also convert latitude and longitude to floating-point string.

There was code review concerns against adding this API, upon which I tried to
use floating point string formats. But I encountered various problems with
accuracy and trailing zeros. For global positioning data (latitude and
longitude), even inaccuracy on the sixth significant decimal digit causes
noticeable positional shift. To achieve sufficient accuracy on the least
significant end, I need to use double instead of float. To remove trailing
zeros, the idea was to use '%.6g' format, but that can cause rounding. '%.6f'
on a double looks ok, but always includes trailing zeros. A test program shows:

 %.6g of ((double)(int32_t)23230100)/1e6 = "23.2301"     <-- good
 %.6g of ((double)(int32_t)42419993)/1e6 = "42.42"       <-- bad rounding
 %.6g of ((double)(int32_t)23230199)/1e6 = "23.2302"     <-- bad rounding

 %.6f of ((double)(int32_t)23230100)/1e6 = "23.230100"   <-- trailing zeros
 %.6f of ((double)(int32_t)42419993)/1e6 = "42.419993"   <-- good
 %.6f of ((double)(int32_t)23230199)/1e6 = "23.230199"   <-- good

It looks like when accepting that there will be trailing zeros, using double
with '%.6f' would work out, but in the end I am not certain enough that there
aren't more hidden rounding / precision glitches. Hence I decided to reinforce
the need to add this API: it is glitch free in sufficient precision for
latitude and longitude data, because it is based on integer arithmetic.

The need for this precision is particular to the (new) OsmoSMLC vty
configuration, where reading and writing back user config must not modify the
values the user entered. Considering to add these functions to osmo-smlc.git,
we might as well add them here to libosmocore utils, and also use them in
osmo_gad_to_str_*() functions.

Change-Id: Ib9aee749cd331712a4dcdadfb6a2dfa4c26da957
2020-10-07 11:39:46 +00:00
Alexander Couzens d745a0e7f3 gprs_ns2_vty_create: remove bind pointer check
The bind pointer can't be NULL because gprs_ns2_ip_bind()
is either return 0 and bind is valid or != 0 and returning.

Found-by: Coverity
Fixes: CID#214854
Change-Id: I11d86c9cb36226701e51942f14d7a6412c3eff26
2020-10-07 10:16:40 +00:00
Vadim Yanitskiy f1fc9d3af5 vty: fix vty_dump_element(): do not print empty <attributes>
Some attributes like CMD_ATTR_LIB_COMMAND are not being printed
to the XML VTY reference (despite being set), so we should not
print empty "<attributes scope='global'></attributes>".

Change-Id: Ie7e53b080c10564bfef6f0e8ddeb470e46fad387
Related: SYS#4937
2020-10-07 14:17:02 +07:00
Vadim Yanitskiy ef4c597b4a vty/command: restrict the use of '.', '!', and '@' as flags
Change-Id: Icb4acbab0a15de2b0ed7b88fb0e227675317146a
Related: SYS#4937
2020-10-07 14:17:02 +07:00
Vadim Yanitskiy 7e1a78fb03 vty/command: assign flags to CMD_ATTR_{IMMEDIATE,NODE_EXIT}
Change-Id: I77c1ef7ca4c667c769cc53c7ac65c3be5c7e1c86
Related: SYS#4937
2020-10-07 14:17:02 +07:00
Vadim Yanitskiy 75fec3a419 vty/command: print attribute flags in the output of 'list'
Here is an example:

  OsmoAPP(config-foo)# list with-flags
    ...  help
    ...  list
    ...  show running-config
    ...  exit
    ..F  lib-command foo (one|two|three)
    ZB.  lib-command bar [zoo]
    .bf  app-command foo-bar
    z..  app-command zoo .TEXT
    ...  app-command nope

A dot indicates that the associated attribute is not set.

Note that there is no strict relation between rows and index values
of the attributes.  In the example above there could be one or more
hidden flag rows corresponding to attributes that are not assigned
to any of the commands within 'config-foo' node.

If neither of the commands belonging to the current node (where
'list' command is executed) has attributes, the output would
not contain empty dot-rows.

Global attributes (such as CMD_ATTR_IMMEDIATE) are not yet displayed
because we still have not agreed on what kind of symbols to assign
them.  This will be implemented later.

Change-Id: I71cef3ec0fab44c7e11fc353b8bc42268a4ee8f0
Related: SYS#4937
2020-10-07 12:18:10 +07:00
Vadim Yanitskiy 44c4d17d40 vty/command: introduce a command to list attributes
Here is an example of listing all attributes:

  OsmoBSC# show vty-attributes
    Global attributes:
      .  This command is deprecated
      .  This command is hidden
      .  This command applies immediately
      .  This command applies on VTY node exit
    Library specific attributes:
      (no attributes)
    Application specific attributes:
      o  This command applies on A-bis OML link (re)establishment
      r  This command applies on A-bis RSL link (re)establishment

or only a specific kind of attributes:

  OsmoBSC# show vty-attributes application
    Application specific attributes:
      o  This command applies on A-bis OML link (re)establishment
      r  This command applies on A-bis RSL link (re)establishment

Change-Id: I561114d7416e30cc06b7d49c0bc1217a76039c99
Related: SYS#4937
2020-10-07 04:01:48 +07:00
Philipp Maier 608b1a40ff command: add library command attribute for libosmo-sccp
Change-Id: I4439a414af05700cb1ccff7e7e5927ffc194d171
Related: SYS#4937, OS#1601
2020-10-06 16:42:58 +02:00
Vadim Yanitskiy c0745ebc28 vty/command: introduce API for the library specific attributes
See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.

Change-Id: I15184569635b3ef7dfe9eeddcc19bf16cc358f66
Related: SYS#4937
2020-10-06 00:22:26 +07:00
Vadim Yanitskiy 8e7c49649e vty: use install_lib_element() and install_lib_element_ve()
See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.

Change-Id: Ic541126ffd4975daf87199abfafb465e2055e44f
Related: SYS#4937
2020-10-06 00:22:22 +07:00
Vadim Yanitskiy 99d5c2d721 vty/command: add CMD_ATTR_LIB_COMMAND and install() API wrappers
This new attribute would allow to distinguish commands provided
by libraries from commands registered by the application itself,
so vty_dump_element() would print proper description for the
library specific attributes.

All VTY commands defined by the libraries need to use the new API:

  - install_lib_element(), and
  - install_lib_element_ve,

instead of the old functions (respectively):

  - install_element(), and
  - install_element_ve().

See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.

Change-Id: I8baf31ace93c536421893c2aa4e3d9d298dcbcc6
Related: SYS#4937
2020-10-06 00:22:06 +07:00
Vadim Yanitskiy ceb3b39440 vty/command: add global command attribute CMD_ATTR_NODE_EXIT
Change-Id: I56306f4886a72a3525b60225721aa2fcf7c57213
Related: SYS#4937
2020-10-06 00:20:37 +07:00
Vadim Yanitskiy f94355dc68 vty: check for reserved flags in application specific attributes
We agreed to reserve uppercase flag letters for libraries.

Change-Id: If0c332f7c86ff26a4060a14b947445d194a6702e
Related: SYS#4937
2020-10-06 00:14:18 +07:00
Alexander Couzens 22f34710d9 ns2: vty: on `show ns` add information of NS binds
Change-Id: I6cef42749555e577d5573f2ed8b8bce4cf842a98
2020-10-05 14:23:33 +00:00
Alexander Couzens 1fac6f7452 ns2: vty: allow the users (pcu/sgsn) to set a default bind
The SGSN will always bind to 0.0.0.0 in difference the PCU bind is depending
on the info indication. Allow to the user to define a default bind
address.

Change-Id: I2a9dcd14f4ad16211c0f6d98812ad4a13e910c2a
2020-10-05 14:23:33 +00:00
Vadim Yanitskiy 024e1957cc vty: check for duplicate flags in application specific attributes
This would facilitate detecting duplicates on early development stages.

Change-Id: I4e27d6e89d3f851b5ea4f00da01e7093afa537b2
Related: SYS#4937
2020-10-04 20:55:39 +00:00
Alexander Couzens a3373e3394 ns2: vty: show all nse
Don't stop after dumping the first nse

Change-Id: I0ca1807692854b23b77ca9042768529df3f80289
2020-10-03 07:19:59 +00:00
Alexander Couzens da0a285612 ns2: status ind: add additional flags (first and persistent)
Both flags are required to allow the NS user to sent BVC RESET for persistent NSE.
On persistent NSE with persistent NS alive configuration (no RESET/UNBLOCK/BLOCK) the
PCU can't detect if the SGSN has restartet or crashed.

Change-Id: Iaad7b53d44338e5dd81dc2202f23bdcb715af804
2020-10-03 07:19:48 +00:00
Alexander Couzens bf95f0fb2e ns2: refactor ns2_prim_status_ind()
Replace parameters nsi + nsei with a single nse pointer.

Change-Id: I35f6381110ba7ba1e013f21120e971362bdff55b
2020-10-03 07:17:54 +00:00
Alexander Couzens 477ffb0e72 ns2: parse the return code of gprs_ns2_ip_bind
Fixes a crash when the bind fails.

Change-Id: I96c8e871a350f8f7b9ba2450bb37b90b535f42e2
2020-10-01 19:33:00 +02:00
Neels Hofmeyr 6b5f1de06d osmo_use_count_to_str: make robust against unused use_count
A use_count struct gets properly initialized once the first use count is added.
Normally, this happens directly at object allocation. Still make sure
osmo_use_count_to_str_*() don't crash on a yet unused struct use_count.

Change-Id: I47b1acc7f13f2557c78e2cbe67d4690709ce795e
2020-09-30 18:48:12 +00:00
Harald Welte a8b1b2175c logging: Introduce MAX_LOG_SIZE for the magic number 4096
Change-Id: Ia9645098dffecd29242857de8f1aea6b9aca5918
2020-09-29 19:06:22 +02:00
Harald Welte e4d9a2c5eb logging_vty: set osmo_stderr_target to NULL on "no log stderr"
We cannot keep a reference to the old log_target around if we
just destroyed/deleted it.

Change-Id: I98a801cf83347a4422534d020d5ed5e2d1eb5482
2020-09-29 16:58:22 +00:00
Harald Welte c433889bba write_queue: Re-enqueue msgb if write_cb returns -EAGAIN
By adding this functionality, the write_cb() handler can "un-dequeue"
the msgb in case of some error.  The msgb might have been modified
meanwhile, e.g. due to a partial write already pulling some data off
the head of the msgb.

Change-Id: I97bb0d64ec991adf5dd0b3708e0c7cf029e03b5f
2020-09-29 16:58:11 +00:00
Harald Welte f44937834f write_queue: use msgb_{en,de}queue_count()
The write_queue.c implemetation predates the msgb_*queue_count()
functions for maintaining a count alongside witha msgb queue. Let's
migrate over to those implementations.

Change-Id: I0ebd42a50f239dd7e9f663ce4c42824a5c1b3ce7
2020-09-29 16:30:56 +00:00
Harald Welte 66138ccab5 write_queue: Add osmo_wqueue_enqueue_quiet()
Same as osmo_wqueue_enqueue() but without logging queue overruns.

Change-Id: Ic082eb39795b08631284eeb421fef3c28f2e90dc
2020-09-29 16:30:56 +00:00
Vadim Yanitskiy 7f6c87da2f vty/command: reflect global attributes in the XML reference
Given that commands with either/both of the following attributes:

  - CMD_ATTR_DEPRECATED,
  - CMD_ATTR_HIDDEN,

never end up in the XML reference, only CMD_ATTR_IMMEDIATE would
be reflected for commands taking effect immediately as follows:

  <command id='foo'>
    <!-- Global attributes -->
    <attributes scope='global'>
      <attribute doc='This command applies immediately' />
    </attributes>

    <!-- Application specific attributes -->
    <attributes scope='application'>
      <!-- ... -->
    </attributes>

    <params>
      <!-- ... -->
    </params>
  </command>

Change-Id: I8476c1163c23a9a52641987acf3df0b8c49d8f7b
Related: SYS#4937
2020-09-28 13:03:52 +07:00
Pau Espin 470cc12447 cosmetic: Fix typo in API doc
Change-Id: I2c8f61768f96eda8d9f3e9b867a7e9625f4f6078
2020-09-27 12:58:23 +02:00
Alexander Couzens 772ca6195e ns2: fix a msg leak when receiving REJECTED messages
Change-Id: I7edc53c29c3dd09c395a275ceb8648b8eb19c06c
2020-09-26 19:58:50 +00:00
Daniel Willmann 4fb27a80d2 gprs_ns2: Make reason const
Change-Id: Ia0db18703d9fd137a5c5fe4474e2d76868a9af9d
2020-09-25 15:39:46 +02:00
Alexander Couzens 1301012837 ns2: refactor handle_nsip_read/handle_nsfrgre_read
Might be more readable.

Change-Id: Ib2dbcae55a8c7a973cfa1123784f509708de7f3b
2020-09-25 09:46:31 +00:00
Alexander Couzens 1f0625f214 ns2: vty: fix behavior of vtyvc_by_nsei when vtyvc isn't found
Fixes the parsing of persistent nsvcs.

Change-Id: I297409f557f17df680ac76018b4202eb99713021
2020-09-25 09:45:24 +00:00
Alexander Couzens ffd49d0757 ns2: ns2_recv_vc: remove unused parameter nsi
Change-Id: I0dbc079e83d37de01a4260442363ed5fdcd51d28
2020-09-25 09:45:24 +00:00
Alexander Couzens 38b19e88bb ns2: refactor nsvc_by_ functions
gprs_ns2_nsvc_by_sockaddr_nsei is doing the lookup within a NSE.
gprs_ns2_nsvc_by_sockaddr_bind is doing the lookup within a bind.
Make both function look similiar and take similiar arguments.

Change-Id: Ia499fc279013668abe7348e578a0768f7d16faf9
2020-09-25 09:45:24 +00:00
Alexander Couzens c1cd333072 ns2: check the specific bit of NS SDU Control bits
Change-Id: I9632abe70585cb7aff2602590453d903dd88b48a
2020-09-25 09:45:24 +00:00
Alexander Couzens c82c40aa53 ns2: vty: add missing docs for IPv6 address
Change-Id: I0ac04e1352ceadb7b787bcb3358c70e5bfd7c65b
2020-09-24 23:32:18 +00:00
Alexander Couzens 89acdef892 ns2: remove bssgp specific msgb->cb parts
There shouldn't be any knowledge of the upper layer in the NS layer.
The PCU / SGSN / gbproxy have to add the pointer when parsing the primitives.

Change-Id: Id7edb8feb96436ba170383fc62d43ceb16955d53
2020-09-25 01:06:36 +02:00
Alexander Couzens 495b4a7cdb gb/gprs_bssgb: ensure the fc timer has been stopped when freeing bssgp_bvc
Change-Id: Id03ebef31bb513e2b3b5bc709a91e9352ebbbc79
2020-09-24 13:52:18 +00:00
Alexander Couzens 6a2c0740b1 gb/gprs_bssgb: check if talloc failed on btsctx->fc
Change-Id: I1cfccc2cb696d9e95f590b99559d0a987031adfe
2020-09-24 15:51:46 +02:00
Vadim Yanitskiy 349d3480a6 vty: cosmetic: fix missing curly braces in vty_describe_command()
Change-Id: I1585ee70a3db77aa8737f9463c4d0665f4e90d90
2020-09-22 19:29:28 +00:00
Vadim Yanitskiy f909d336c3 vty: cosmetic: s/width/cmd_width/g in vty_describe_command()
Change-Id: Ifcf5f7be925c5421040d3cac2c4c5e4dd497c0f5
2020-09-22 19:29:28 +00:00
Vadim Yanitskiy aade232c54 vty: cosmetic: drop redundant 'break' statements
Change-Id: I54ee7c3c6fe16a413d0e1128c7358ff6e4b76c6a
2020-09-22 19:29:28 +00:00
Pau Espin 53fbc67d4e osmo_strlcpy: Clarify length calculation
Change-Id: I78dc7b87d5b42595c0b1392fce61606eae8f6ec8
2020-09-22 19:28:14 +00:00
Pau Espin c29d513a2b osmo_strlcpy: Avoid calling memcpy with size=0
Change-Id: Ic84af86d33c8a20f06036b13d0a10cf312582f0d
2020-09-22 19:28:14 +00:00
Vadim Yanitskiy 34e94f3c3a vty: print program specific attributes in the XML reference
Change-Id: I1f35368ba9178e1454f2e3ddfcad9d96576143ef
Related: SYS#4937
2020-09-20 09:57:44 +00:00
Neels Hofmeyr 9277b97d0b add osmo_use_count_to_str_c()
So far there is only osmo_use_count_name_buf(). Also provide a use count to
string using a talloc context, allowing to use OTC_SELECT.

- instead of foo_name(), rather use foo_to_str().
- osmo_use_count_name_buf() returns the buf and not the chars_needed. So add
  osmo_use_count_to_str_buf() with a signature that is usable by
  OSMO_NAME_C_IMPL().
- provide osmo_use_count_to_str_c() using OSMO_NAME_C_IMPL().

Change-Id: I1d2e7ee979f8c316ef99f7c65675b36d092ddfca
2020-09-20 09:51:32 +00:00
Harald Welte b40cfdc54b gprs_ns2: Mark gprs_ns2_validate_* as static
They are all called indirectly via gprs_ns2_validate(), so mark them
as static.

Change-Id: I8425ed3da32019b86cf12d3c27132f07d931cf27
2020-09-18 23:14:36 +02:00
Harald Welte 92ad029e1a ns2: Use NULL and not '0' when returning a NULL-Pointer
Change-Id: I9458e6dcf8133fbcfbc89437e58aad049a6d432b
2020-09-18 23:14:36 +02:00
Harald Welte 5bef2cc4bd ns2: Improve/extend doxygen comments for new ns2 implementation
I was reading through the code and noticed many functions not
documented yet, or with incomplete documentation. Change that.

Change-Id: I85a2419604a9fd9ff3c4828a7463e222652f77bf
2020-09-18 23:14:36 +02:00
Vadim Yanitskiy ecaf5faa79 gsm0808: fix: do not encode invalid encryption algorithm
According to 3GPP TS 48.008, section 3.2.2.44, the Chosen Encryption
Algorithm IE, which may be included in the following messages:

  - 3.2.1.2   ASSIGNMENT COMPLETE
  - 3.2.1.8   HANDOVER REQUEST
  - 3.2.1.10  HANDOVER REQUEST ACKNOWLEDGE
  - 3.2.1.12  HANDOVER COMPLETE
  - 3.2.1.25  HANDOVER PERFORMED
  - 3.2.1.31  CIPHER MODE COMPLETE

is coded as follows:

  0000 0001   No encryption used
  0000 0010   GSM A5/1
  0000 0011   GSM A5/2
  0000 0100   GSM A5/3
  0000 0101   GSM A5/4
  0000 0110   GSM A5/5
  0000 0111   GSM A5/6
  0000 1000   GSM A5/7

basically A5/X => X + 1.  All other values are Reserved for future
international use.  As can be seen, value 0x00 is RFU.  Passing
this value to some encoding functions would result in a PDU with
this IE omitted.  Although, some functions would still encode
Chosen Encryption Algorithm IE with this RFU value.

Let's ensure that all functions behave consistently.

Change-Id: If10e433a8174eabe6aa6d2c2937bf9cf5d14d7c9
2020-09-18 08:41:57 +00:00
Harald Welte 7da6ace594 gprs_ns2_sns: Fix compilation on Debian 8
[  198s]     for (unsigned i = 0; i < gss->num_ip6_remote; i++) {
[  198s]     ^
[  198s] gprs_ns2_sns.c: In function 'ns2_sns_st_configured_change':
[  198s] gprs_ns2_sns.c:1053:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
[  198s]    for (int i = 0; i < num_v4; i++) {
[  198s]    ^
[  198s] gprs_ns2_sns.c:1067:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
[  198s]    for (int i = 0; i < num_v6; i++) {
[  198s]    ^
[  198s] Makefile:535: recipe for target 'gprs_ns2_sns.lo' failed

Change-Id: I4b7c576fcdf9d35f85e00ad076af7c48d5eb34a5
2020-09-18 09:48:05 +02:00
Alexander Couzens 48f6386717 libgb/ns: allow to create NS_ALIVE NSVC
Change-Id: I562c3ac4a8baaa2c97852bbd6a5a10ba1f144004
2020-09-15 13:55:24 +02:00
Alexander Couzens 6a161497cf Gb: add a second NS implementation
Reimplement NS with FSM.

Change-Id: I3525beef205588dfab9d3880a34115f1a2676e48
2020-09-15 11:54:41 +00:00
Pau Espin 6407c822ae logging: Avoid printing OSMO_LOGCOLOR_END if no color was used
There's no point in printing that code if no color was used in first
place, and looks strange when using logging with color enabled but no
color assigned to the category printing lines.

Only affected unit test output by this fix is osmo-bts'x
tx_power_test.c, which has been fixed in osmo-bts.git Change-Id
I5aa95997c8df4ce5ba8271acae99c45f68b96e11.

Change-Id: Ie38cc639d7f4acd908f357e5bfb3ced07147583e
2020-09-14 08:45:01 +00:00
Vadim Yanitskiy e0ed147984 vty: fix 'Unsigned compared against 0' generate_cpu_hex_mask()
Change-Id: I49549439d5bbfbb83954ba92957304b03062d003
Fixes: CID#212137
2020-09-11 20:14:34 +07:00
Vadim Yanitskiy b89114b3fa logging: fix memleak in log_target_create_file()
Change-Id: If16d8c6417698bbb5cf87716f9507c7256aeaecb
2020-09-09 05:00:15 +07:00
Vadim Yanitskiy 04f4271704 logging: fix log_target_destroy(): properly close syslog
Change-Id: I122445e8ee842b5f807d21a272520648660e7e65
2020-09-09 04:47:45 +07:00
Vadim Yanitskiy 744236b96e logging: refactor and simplify log_target_destroy()
Change-Id: Ic6b9906e6fd24de6af9c869348c100d9ef6a7df6
2020-09-09 04:42:22 +07:00
Alexander Couzens 0f36421ba8 add osmo_sockaddr_local_ip() to determine the local address for a remote.
Similiar to osmo_sock_local_ip but for osmo_sockaddr.

Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2
2020-09-07 16:22:21 +02:00
Alexander Couzens 3b688835b0 gb/common_vty: use void *
As long the filter doesn't look into the nsvc/bvc structs
there is no need to use the type.
Further it allows to use the same code for NS1 and NS2.

Change-Id: I9b9a70f382a94f1d41142060d5db569f9df865ac
2020-09-07 07:50:58 +00:00
Alexander Couzens 83fb686baa gb/gprs_bssgp: remove superfluous whitespace
Change-Id: Ic66f7e640cd473fa2c8473a3e91f57332ae9bf6a
2020-09-06 23:44:02 +00:00
Alexander Couzens e4181ea8a2 socket: add osmo_sockaddr_cmp()
Compare two osmo_sockaddr.

Change-Id: I2d12ebae2710ffd17cf071e6ada0804e73f87dd6
2020-09-02 18:42:21 +02:00
Alexander Couzens 43957e69ca socket: introduce osmo_sock_init_osa & osmo_sock_init_osa_ofd
osmo_sock_init_osa() takes osmo_sockaddr* as local and remote endpoints
to setup a socket.

Change-Id: I1eece543e3241ef0e095eb63bb831f7c15a16794
2020-09-02 18:42:21 +02:00
Alexander Couzens d95f5d41fa sockaddr_str: add osmo_sockaddr_str_from_str2() which doesn't set the port
In case the port isn't known at the time osmo_sockaddr_str_from_str2()
parse only the ip and don't touch the port.
This is the case when a user has different vty commands for ip and port.

Change-Id: Ifd4e282586b8bd40b912a9f1c25f9e8208420106
2020-09-02 15:22:57 +00:00
Pau Espin d8cf52b993 socket: Fix bug in osmo_sock_init2(AF_UNSPEC) matching IP versions
See previous commit for a bug description.

Fixes: 2c962f5de1

Change-Id: I59bf4b4b3ed14766a5a5285923d1ffa9fc8b2294
2020-08-31 19:01:02 +02:00
Pau Espin 5cc4fe4706 socket: Add some osmo_sockaddr print helpers
These are APIs useful to inline in log calls.

Change-Id: Ie07a38b05b7888885dba4ae795e9f3d9a561543d
2020-08-31 12:52:09 +02:00
Pau Espin 7bda8549a4 socket: fix wrong ipv6 dst buf size passed in osmo_sock_local_ip
Change-Id: I13939fda9b3d642f9fa1413e59458aba0628a4a6
2020-08-31 11:21:30 +02:00
Pau Espin 81e7a6c859 socket: Fix stack-buffer-overflow in osmo_sock_local_ip()
On IPv6 sockets, getsockname() and inet_ntop() would act upon a
structure struct sockaddr_in.

First getsockname() would succeed but truncate the address, and later on
inet_ntop would read out of the scope of the structure.

Change-Id: If781d56680758a97643b1b38e78d3431ea649020
2020-08-31 08:50:42 +00:00
Pau Espin 308ab792a3 socket: Use AF_UNSPEC instead of PF_UNSPEC calling getaddrinfo
man getaddrinfo entry doesn't mention PF_UNSPEC, but AF_UNSPEC.

Change-Id: Icab676ff7ee9d813d7b7fe807fbe172512f5e397
2020-08-31 08:50:42 +00:00
Pau Espin 1a3d24e8a5 socket: Add support for AF_INET6 in osmo_sockaddr_to_str_and_uint()
Related: SYS#4915
Change-Id: I439c7fa52a3a30eebc3d35e78be7f1724fb69294
2020-08-31 08:50:42 +00:00
Pau Espin 4f463c5ccc socket: Allow binding to :: (IPv6) and connecting to IPv4-only on the remote
sctp_bindx() fails if passed both "0.0.0.0" and "::", only "::" must
be passed instead, which covers both.
As a result, it is fine in this case and makes sense having only IPv6
formatted IPs in the local side (which actually also includes all IPv4
ones in th system) and IPv4-only addresses on the remote side.

Change-Id: I0b590113e5def20edcbcb098426b19cd504eabff
2020-08-30 16:08:35 +00:00
Vadim Yanitskiy 776c5b16ea lapdm: fix SAPI-0/SAPI-3 frame prioritization on DCCH
According to 3GPP TS 44.005, section 4.2.2 "Priority":

  a) on DCCH, a SAPI=0 frame always has higher priority than SAPI=3;
  b) on ACCH, the priority arrangement is more complex:
    b1) if a SAPI = 3 frame is awaiting transmission, two SAPI=0
        frames shall not be sent in consecutive SACCH frames;
    b2) on the network side (LAPDM_MODE_BTS), it must also be ensured
        that any SAPI=3 frame is followed by at least one SAPI=0 frame;
    b3) a SAPI = 0 frame may be repeated in the next SACCH period
        if the Repeated SACCH is supported (see 3GPP TS 44.006, section 11).

We definitely need to extend our testing coverage to ensure that
we implement b) correctly, but for now let's focus on DCCH:

  a) for DCCH, ensure that SAPI=0 frames preceed SAPI=3 ones;
  b) for ACCH, re-use the existing round-robin implementation.

Change-Id: Ia3780bce1222b312ae2fd2d21496a4d6c5ccb6e0
Related: SYS#5047, OS#4731
2020-08-27 22:10:54 +07:00
Vadim Yanitskiy 29ecabe7a2 lapdm_pad_msgb(): cosmetic: use GSM_MACBLOCK_PADDING
Change-Id: Ic2ff931ea4272903c440c7c5ea996dd84c2e470b
2020-08-27 19:35:13 +07:00
Pau Espin 9cc661b0e8 ipa: Fix wrong output log formatting
Change-Id: I1862465e9f9a1d9f06a189641360ae7b9e03b1fc
2020-08-27 10:45:30 +00:00
Vadim Yanitskiy f76f21b245 macaddr: fix osmo_macaddr_parse(): return meaningful error codes
Change-Id: I316deb83979198acc26721d29708d9942174b192
2020-08-27 01:10:51 +07:00
Vadim Yanitskiy a751f77cad macaddr: fix osmo_get_macaddr(): return -1 if no device is found
Change-Id: I74d33159485ec1f7f09b444621a2d1941c3dd4db
2020-08-27 01:05:18 +07:00
Vadim Yanitskiy fa6cd88ee5 gsm0808: add gsm0808_create_sapi_reject_cause()
This is basically a successor of gsm0808_create_sapi_reject(), but
instead of hard-coding GSM0808_CAUSE_BSS_NOT_EQUIPPED, it allows
the caller to specify a cause value to be used.  The old function
is now deprecated and should not be used.

Change-Id: Iefe5484d0fa02d5722b628b1dc237d51d3fb1a9b
Related: OS#4728
2020-08-26 18:30:19 +07:00
Pau Espin 3119d47603 socker: Remove AI_ADDRCONFIG from getaddrinfo flags
The flag was added recently in cd133316cf,
and it is causing issues while running unit tests in environement like
OBS where probably there's no non-loopback address configured.

Change-Id: I47c31953f1db39fcd2870bde0b984057b8e7b4c4
2020-08-25 11:43:02 +00:00
Pau Espin 4541cf2b96 osmo_sock_inti2_multiaddr: Fix memleak and free uninitialized mem
Under some specific cases, res_loc could be leaked. Under some others,
res_loc and res_rem were freed without being initialized previously.

Fixes: CID#212863
Fixes: CID#212861
Change-Id: Id9c4eda6fd1172e7324aa23c81e8658967a8dd0b
2020-08-25 11:43:02 +00:00
Neels Hofmeyr b19b533e36 comment: mention spec reference in cbsp.[ch]
Change-Id: I1217883a85b4ddd20e9646c7e80ba18950e09713
2020-08-25 13:34:04 +02:00
Pau Espin ed42a88900 osmo_sock_get_ip_and_port(): Support IPv6 sockets
Change-Id: I255a71cf047fd022285fc9aa2f24e5070aa3920b
2020-08-24 08:29:19 +00:00
Pau Espin ba828c30a0 socket: Log proper getaddrinfo() error
Drop one of the two log lines since it would be a duplicated and anyway
it misses context (return code).

Change-Id: I4620bf86f4bcda58ae85209278ac9ae9a0f3012a
2020-08-24 08:29:19 +00:00
Pau Espin cd133316cf socket: multiaddr: Support IPv4 + IPv6 addresses in SCTP associations
The function is improved to support AF_INET:v4->v4, AF_INET6:v6->v6 and
AF_UNSPEC:v4+v6->v4+v6.
Unit tests for the function are added to make sure function behaves
correctly in several scenarios.

Change-Id: I36d8ab85d92bba4d6adb83bc1875eb61094ed2ef
2020-08-24 08:29:19 +00:00
Pau Espin 796c651372 sock: osmo_sock_init2_multiaddr: decouple addr resolution from socket creation
Address resolution is done first and once we have the information, it
proceeds to create the socket. This separation in steps will help when
adding support for IPv6+IPv4 sets, where AF_UNSPEC is passed and created
socket needs to be AF_INET6 in order to handle addr of both versions.

Change-Id: I03147e3033a0c1fd04c9ac61d2ffbd78a1bb784a
2020-08-24 08:29:19 +00:00
Pau Espin 62be97e89d vty: Fix cpu-sched VTY node name
Durin dev cycle, node was initially called "sched" instead of
"cpu-sched", and when it was renamed, this specific part was missed.

Change-Id: I0709fee12cc8ddc4d57efb4ea40b0b79b7ea4151
2020-08-20 08:40:30 +00:00
Vadim Yanitskiy 478dd1b330 vty/command: cosmetic: swap i and j in vty_dump_element()
It's more convenient to use i in the outer loop, and j, k, etc.
in the inner loops.  Otherwise it looks a bit confusing.

Change-Id: I61ef48fcf977d6a872e288571a4ff2c3dfe3184b
2020-08-18 18:40:22 +07:00
Vadim Yanitskiy b0bbd72b2e vty/command: fix switch / case coding style in vty_go_parent()
Change-Id: I6f7f5af6879d91811be6f0edf3feb2ebae185ac7
2020-08-18 18:34:47 +07:00
Eric Wild dde327275c vty cpu sched: do not assert if sched impossible
Shared code might be used by applications that have no vty, so sched
can't be initialized, do not assert and break everything in this case, a
warning should suffice.

Change-Id: Ic40075df8d4cf9fe8f1d711f899dae9a4b5b0928
2020-08-17 10:14:27 +00:00
Vadim Yanitskiy 1d7ae15625 vty/command: cosmetic: fix formatting of config_help_cmd
Change-Id: I8f784d0cf65fa7813088e3ff76d7213b99b975d0
2020-08-15 07:46:53 +00:00
Vadim Yanitskiy 6f50e21936 vty/command: cosmetic: simplify conditions in in config_list_cmd
Change-Id: Id1c082d102b7156dafb9c5d9197dcdc4d26bff63
2020-08-15 07:46:53 +00:00
Harald Welte 5c5713e869 Bump version: 1.3.0.173-51974 → 1.4.0
Change-Id: I4fc6dd4f727c8ff5a64865bbb87e1d9feb7c5174
2020-08-13 11:06:36 +02:00
Pau Espin eb6882fa52 vty: Introduce support to set cpu-affinity and scheduler policy
Process willing to support this kind of configuration through VTY simply
need to call "osmo_sched_vty_init(tall_ctx);" during startup to register
the commands.
For multithreaded processes, new threads willing to get their
cpu-affinity mask according to VTY config should call
osmo_sched_vty_apply_localthread() (potentially after
setting the thread name through pthread_setname_np()).

Related: SYS#4986
Change-Id: If76a4bd2cc7b3c7adf5d84790a944d78be70e10a
2020-08-10 14:11:18 +00:00
Vadim Yanitskiy 9b766bfafe src/Makefile.am: add conv_acc_neon_impl.h to EXTRA_DIST
Change-Id: I641c25f8aec249df43c781debfc967f07e221b9d
2020-08-07 02:45:39 +07:00
Eric Wild 3afc1d1777 libomsocoding: NEON viterbi acceleration
configure flag required to enable this: --enable-neon

Although autodetection according to __ARM_NEON would work because this
is only defined if the fpu is neon neon-fp16 neon-vfpv3 neon-vfpv4
neon-fp-armv8 crypto-neon-fp-armv8 doing that would lead to a unknown
performance impact, so it needs to be enabled manually.

Speedup is about ~1.3-1.5 on a unspecified single core Cortex A9. This
requires handling a special case for RACH with len 14 which is far too
short for neon and would actually incur a performance penalty of 25%.

Related: OS#4585
Change-Id: I58ff2cb4ce3514f43390ff0a2121f81e6a4983b5
2020-08-06 16:47:40 +00:00
Alexander Couzens 2c962f5de1 osmo_sock_init2: improve support for AF_UNSPEC
osmo_sock_init2 abstract two calls of getaddrinfo into one.
While there aren't problems with AF_INET or AF_INET6. When using
AF_UNSPEC there are corner cases when this fails. E.g. calling
local_host with "" and remote_host with an IPv6 only address results in
setting up a local socket with AF_INET while trying to connect from there towards
AF_INET6 will most likely fail.
To prevent such cases with AF_UNSPEC, search prio calling any syscalls if local and remote site
supports AF_INET or AF_INET6. In case both supported, prefer AF_INET6

Change-Id: I397c633931fd00d4f083955a3c49a40fb002d766
2020-08-06 16:41:20 +00:00
Alexander Couzens 6300aff3b2 gsm 12.21: add osmocom specific NM_ATT_OSMO_NS_LINK_CFG
The sysmobts uses the same OML attributes as IP.access. Because the IP.access
attribute only supports IPv4 as NSVC configuration, add an own attribute.

Change-Id: Ic261bc43a07fa741b97a9c6ec5a9ed6f5ecae588
2020-08-06 16:41:20 +00:00
Alexander Couzens 85a8fd3911 Gb/BSSGP: replace hardcoded Tx into NS library by a callback
Add bssgp_ns_send callback() to set the transmission path into the
NS library. This allows to use the Gb implementation with
the old NS and the new upcoming NS implementation.
Users of the old NS implementation don't have to set the callback as
the default is the old NS implementation.

Only users of the new NS implementation need to set the callback and
the callback data.

Change-Id: I3a498e6a0d68b87fed80c64199b22395796761b4
2020-08-04 10:33:09 +00:00
Harald Welte 44964981c2 i460: Fix bit- and subslots ordering of I.460 mux + demux
When I wrote the new I.460 mux + demux code, I failed to realize that
* bit numbers in relevant ITU specs start with 1 as MSB ... 8 as LSB
* sub-slot 0 is bits 1+2, i.e. the two MSBs of a byte
* bit-ordering within each sub-slot is also MSB first

As a result, the code and test data was broken.

Change-Id: I6df7dbf411efbdeaf516e72ac552432bf5a569d0
2020-08-02 21:57:05 +02:00
Harald Welte b3b474d8ad i460: pass more context to call-back functions
When calling a user-provided call-back function for the i460 mux
or demux, always pass a pointer to the osmo_i460_subchan the callback
relates to.  This way, the user can walk the i460 data structures
to obtain information about which mux/demux instances is calling.

Change-Id: Id842c72ce371a67fe5df6694e195c281aaf607ab
2020-08-02 11:57:55 +02:00
Harald Welte eb8240d564 i460: Add back-pointer from sub-channel to timeslot
A user may want to walk back from a sub-channel to the timeslot
to which it belongs.

Change-Id: Id6e5e208c5daa63fd23ac719d62314622b5d0ed9
2020-08-02 11:57:55 +02:00
Philipp Maier b5518a8f1f i460_mux: add callback to notify empty tx queue
There is no way for the API user to know if the TX queue of the
multiplexer runs empty. However, this is criticil since an empty TX
queue will cause dropout of a TRAU frame, which can have quite severe
effects to the receiving end. Lets add a callback that allows the APU
user to insert appropiate idle frames or silent frames into the queue
before it runs empty.

Change-Id: I88a87724235fe50d55ce6215bb385c044072226e
Related: OS#2547
2020-08-02 11:57:55 +02:00
Harald Welte 2ba641edaa bits.c: Use faster look-up-table approach for osmo_revbytebits_{buf,u8}
Benchmarking has shown that a look-up table based approach is much
faster than the arithmetic approach we used so far.

This is from a Core i7-6600U:

10    bytes, 1     iterations: flip=379, revb=5491; revb = 1448 %
10    bytes, 10    iterations: flip=728, revb=1517; revb = 208 %
10    bytes, 100   iterations: flip=2952, revb=9305; revb = 315 %
10    bytes, 1000  iterations: flip=26305, revb=90953; revb = 345 %
100   bytes, 1     iterations: flip=468, revb=1093; revb = 233 %
100   bytes, 10    iterations: flip=2634, revb=7418; revb = 281 %
100   bytes, 100   iterations: flip=23666, revb=70718; revb = 298 %
100   bytes, 1000  iterations: flip=237595, revb=900555; revb = 379 %
1024  bytes, 1     iterations: flip=3417, revb=11454; revb = 335 %
1024  bytes, 10    iterations: flip=33579, revb=92353; revb = 275 %
1024  bytes, 100   iterations: flip=555399, revb=1196228; revb = 215 %
1024  bytes, 1000  iterations: flip=3478271, revb=9227966; revb = 265 %
1048576 bytes, 1     iterations: flip=10189583, revb=7022193; revb = 68 %
1048576 bytes, 10    iterations: flip=19693347, revb=54389925; revb = 276 %
1048576 bytes, 100   iterations: flip=151308243, revb=454293151; revb = 300 %
1048576 bytes, 1000  iterations: flip=1390338439, revb=4429862642; revb = 318 %

where 'revb' is the old arithmetic approach, and 'flip' the new
look-up-table approach. In our usual cases of 100..1024 bytes in a
single iteration, the old code takes 233..335% of the look-up table.

Benchmarks on an Atom E6xx also show improvements except in one
situation (a single iteration over one 1MB large buffer).

10    bytes, 1     iterations: flip=416, revb=9184; revb = 2207 %
10    bytes, 10    iterations: flip=1960, revb=4024; revb = 205 %
10    bytes, 100   iterations: flip=13624, revb=32408; revb = 237 %
10    bytes, 1000  iterations: flip=160656, revb=361784; revb = 225 %
100   bytes, 1     iterations: flip=3536, revb=4952; revb = 140 %
100   bytes, 10    iterations: flip=12960, revb=20912; revb = 161 %
100   bytes, 100   iterations: flip=122448, revb=215152; revb = 175 %
100   bytes, 1000  iterations: flip=1204928, revb=1647680; revb = 136 %
1024  bytes, 1     iterations: flip=12944, revb=23128; revb = 178 %
1024  bytes, 10    iterations: flip=126192, revb=239784; revb = 190 %
1024  bytes, 100   iterations: flip=1190184, revb=1491672; revb = 125 %
1024  bytes, 1000  iterations: flip=11865872, revb=15113872; revb = 127 %
1048576 bytes, 1     iterations: flip=16288272, revb=15925888; revb = 97 %
1048576 bytes, 10    iterations: flip=121957000, revb=157883384; revb = 129 %
1048576 bytes, 100   iterations: flip=1219264992, revb=1621265216; revb = 132 %
1048576 bytes, 1000  iterations: flip=12219520648, revb=15960035856; revb = 130 %

Change-Id: I25029fe7e54c92979fb0119992fb8dc167e1536e
2020-08-02 11:30:31 +02:00
Philipp Maier 6d21448911 gsm_08_58: add missing RSL error cause codes
The define constants for the cause codes "BTS not equipped",
"remote transcoder failure" and "notification overflow" are missing.
Lets add them including value strings.

Change-Id: Ic3e936da00bd256bae03867887851f1a4e30e218
2020-07-31 21:23:49 +00:00
Pau Espin a184701108 vty: Don't match negative values on purely positive ranges
Without this patch, for instance having a range 0-ULONG_MAX would match
if someones types value -3, which would be converted to unsigned but
that's clearly what is expected here from user point of view.

Change-Id: Ia95f6314a2dd3f94d21fc219cf69bb8d39b8e7f0
2020-07-30 21:02:03 +00:00
Pau Espin 9fdc871532 vty: Allow 64 bit values in numeric ranges if system supports it
This fixes commands not being matched due to providing a range with more
than 10 digits.

The last case (passing -4000 matching 0-ULONG_MAX) shows a different bug
which will be fixed in next commit.

Change-Id: I0afa0caabffe36083c36b92ba90696ded00bb7be
2020-07-30 21:02:03 +00:00
Harald Welte 701968f286 gsm0411_{smc,smr}.c: Work around newlib bug
At least on Debian unstable, newlib is [currently?] buggy in that
we need to include sys/types.h before including inttypes.h, otherwise
PRIu64 is not defined.

Change-Id: Ic1c9cdf66cfd5b82bd7e20eaaf05b10e6bdb675e
Closes: OS#4686
2020-07-30 21:35:10 +02:00
Philipp Maier 6509d202d9 i460_mux: correctly reset subchannels
When a subchannel is deleted or created the initalization mainly
consists of a memset over the wohle subchannel struct a message buffer
initailization.

However, when we delete a subchannel we also must take of the resetting
of the related struct. Currently this is done with a memest.
Unfortunately this creates not only a memory leak (there might be still
items in the multiplexer tx queue) but also it makes the application
crash when the message buffer is used the next time since the llist_head
of the tx queue looses its initialization.

Lets fix the memory leak problem and the message buffer problem and put
the reset functionality in a single place.

Change-Id: I937a9d4db95f44a860cd2c5dbb660dc1970b9a49
2020-07-30 10:39:43 +02:00
Alexander Couzens b20d852a95 socket: osmo_sock_local_ip: correct doxygen comment
There is no parameter fd.

Change-Id: I1e31fcbf40d8abf99214b87e70e867b5ab66bd75
2020-07-28 13:58:48 +02:00
Alexander Couzens 03a421359d bts_features: add feature BTS_FEAT_IPV6_NSVC
Previous both the IPA nanobts and the sysmobts has been using the IPv4 only OML
attribute NM_ATT_IPACC_NS_LINK_CFG.
A bts with BTS_FEAT_IPV6_NSVC supports IPv6 for NSVC (PCU<Gb>SGSN) using
the new OML attribute NM_ATT_OSMO_NS_LINK_CFG.

Change-Id: I9ef7949f66764b3c639e45eb440122e318da44a0
2020-07-28 13:58:46 +02:00
Alexander Couzens 9c86a2ce56 gprs_ns: fix typo in comment
Change-Id: Ie9d8decea18542cb0e1641dcb5fca5e4850910eb
2020-07-28 11:44:55 +02:00
Daniel Willmann 1a1de33bf9 stats: Add stats commands related to testing
* Allow to set the reporting interval to 0 for manual reporting
* stats reset command to reset all statistics
* stats report command to manually trigger statistics reporting

Change-Id: I9febcb65650abfd538caedfbca77a787e66d517a
Related: SYS#4877
2020-07-17 16:41:31 +00:00
Daniel Willmann ea71b439ec stat_item: Add function to reset stat items and groups
Change-Id: I80fc0ea8865ec4efdcd4c982e69d863275fd9919
Related: SYS#4877
2020-07-17 16:41:31 +00:00
Daniel Willmann 26a9539e18 rate_ctr: Add functions to reset rate counter (groups)
Change-Id: If2f806d044cd0fb6929dac44ef8f8a15941ffe9b
Related: SYS#4877
2020-07-17 16:41:31 +00:00
Harald Welte bebec218a7 vty: Avoid ultra-long multi-line strings cluttering talloc reports
The talloc_asprintf() series includes an unconditional call to
talloc_set_name_const(), turning the entire long constructed string
into the name of the talloc object.  That simply doesn't work when
creating kilobytes-sized VTY reference strings including linefeeds.

Let's add an explicit talloc_set_name_const() to prevent this.

Change-Id: Ibd77684b88cc3572047daa98c9a6b9119fba041b
Closes: OS#4668
2020-07-15 12:23:46 +02:00
Neels Hofmeyr 9b35e56e56 fixup for gsm0808_create_common_id(): add API doc, use new MI API
Follows patch I353adc1aa72377f7d4b3336d2ff47791fb73d62c that was merged too
soon. Applying my code review in form of this fixup patch.

Change-Id: I979bca0c6aaa8fe4feddda922bd2e6c1cb49585b
2020-07-14 10:36:17 +00:00
Pau Espin 9a5d90ab96 Revert "gsmtap_makemsg_ex: NULL for unknown chan_type"
Reverting due to being completely normal for some applications to submit
usning this channel type when decoding/parsing failed and hence not
being able to determine channel type.

This reverts Change-Id Ib4147a33a75c3cf425c30da8b0678c7fba8a371d
(commit 12f93be6073ed89055862baafbfe0e08e50ed17a.)

Change-Id: I6ebaa89cc3422df1d7fd2365a6176cb2902d1c67
2020-07-09 11:43:48 +00:00
Harald Welte bc1d7152c1 lapd_core: After calling into L3, check if the state has changed
While processing an I-frame we may deliver its payload to L3. After
returning from L3 procesing, we run some additional code, assuming
the LAPD/DL state has not changed meanwhile.

However, if the application destroys the LAPD/DL meanwhile, our state
might be NULL again, and in this state we should not perform any further
action.

This is one of the cases where synchronous in-line dispatch across
various layers is hitting us.  L3 should have an input queue, and only
start processing after all L2 work has completed and we're about to go
back to sleep in select().

Change-Id: I026b64503511002c13c0f4117648c366c48ecc62
Related: OS#1761
Closes: OS#4646
2020-07-04 10:52:13 +02:00
Harald Welte 8617d09ee3 lapd_core: Ensure we always have some tailroom
At some points, e.g. when allocating message buffers from the Tx
history, we used to allocate them exactly as large as the defined
headroom plus the user data.  This means that the underlying PH layer
(E1 mostly) had no tailroom to add anything to the end of the message.

Especially for DAHDI this is a problem, as we need to make space for
two more bytes of frame check sequence (FCS).

So let's simply make sure we always have some extra space at the end
of such buffers.

Change-Id: Id362ce131157c7513d744b0248c7f78fb75c590c
Related: OS#4644
2020-07-03 19:28:53 +02:00
Harald Welte 78af6ba54b gprs_ns: Set sockaddr_in.sin_family for persistent NSVCs
We cannot just set sockaddr_in.sin_addr + sin_port, we also must
initializa sin_family.  The reason this has worked so far is
because we probably always first received a NS packet from the
peer, rather than being the first one to send.

Change-Id: I6cefc2cd5516c7a4c01a2cc040afca454e59dd57
Related: OS#4629
2020-06-26 16:07:15 +00:00
Harald Welte 2d3465fd1c gprs_bssgp: Add bssgp_tx_bvc_reset2()
If a BVC-RESET is sent from SGSN, there must not be a cell ID IE
included.  See "Note 1" of TS 48.018 Section 10.4.12.

Change-Id: I11d4e70d510265b9c09dffccdab10b3f0816715a
2020-06-26 16:07:15 +00:00
Neels Hofmeyr 4247c94abf api comment: fix example of osmo_mobile_identity_encode_msgb
The previous example showed a type == IMSI while setting a TMSI value.
Rather show how to encode IMSI digits.

Change-Id: I41af6bf0d61443465172123297b1228584d791d6
2020-06-24 11:31:56 +00:00
Harald Welte 1bd726a2e4 gsm0808: Add gsm0808_create_common_id()
This function encodes a GSM 08.08 / 48.008 "Common ID" message.

Change-Id: I353adc1aa72377f7d4b3336d2ff47791fb73d62c
Related: OS#2969
2020-06-21 22:06:56 +02:00
Harald Welte 17933347c5 bts_features.h: Introduce BTS_FEAT_PAGING_COORDINATION
This feature indicates if the given BTS supports paging coordination,
that is the transmission of CS paging (received on Abis) to be sent
via PACCH/PCU in PS domain fro MS with active TBF.

Change-Id: Ifb2e83eaf05dd36e5b203ed2de1a74864b039e38
Related: OS#2406
2020-06-21 15:33:55 +02:00
Neels Hofmeyr 83025bf1a6 add osmo_mobile_identity API
Implement better API around 3GPP TS 24.008 Mobile Identity coding.

struct osmo_mobile_identity is a decoded representation of the raw Mobile
Identity, with a string representation as well as dedicated raw uint32_t TMSI.
The aim is to remove all uncertainty about decoded buffer sizes / data types.

I have patches ready for current osmo CNI programs, replacing the Mobile
Identity coding with this new API. Deprecate the old MI API.
osmo-bsc: I71c3b4c65dbfdfa51409e09d4868aea83225338a
osmo-msc: Ic3f969e739654c1e8c387aedeeba5cce07fe2307
osmo-sgsn: I4cacb10bac419633ca0c14f244f9903f7f517b49
Note that some GPRS and SGs related coding is done here in libosmocore and
hence currently remains using the old implementation (see previous version of
this patch: Ic3f969e739654c1e8c387aedeeba5cce07fe2307).

New API functions provide properly size-checking implementations of:
- decoding a raw MI from a bunch of MI octets;
- locating and decoding MI from a full 3GPP TS 24.008 Complete Layer 3 msgb;
- encoding to a buffer;
- encoding to the end of a msgb.

Other than the old gsm48_generate_mid(), omit a TLV tag and length from
encoding. Many callers manually stripped the tag and value after calling
gsm48_generate_mid(). The aim is to leave writing a TL to the caller entirely,
especially since some callers need to use a TvL, i.e. support a variable-size
length of 8 or 16 bit.

New validity checks so far not implemented anywhere else:
- stricter validation of number of digits of IMSI, IMEI, IMEI-SV MI.
- stricter on filler nibbles to be 0xf.
As a result, applications using osmo_mobile_identity will be stricter in
rejecting coding mistakes (some of which we currently have in our test suites,
and which we'll need to fix).

Rationale:

While implementing osmo-bsc's MSC pooling feature in osmo-bsc, this API will be
used to reduce the number of times a Mobile Identity is extracted from a raw
RSL message.

Extracting the Mobile Identity from messages has numerous duplicate
implementations across our code with various levels of specialization.
https://xkcd.com/927/

To name a few:
- libosmocore: gsm48_mi_to_string(), osmo_mi_name_buf()
- osmo-bsc: extract_sub()
- osmo-msc: mm_rx_loc_upd_req(), cm_serv_reuse_conn(), gsm48_rx_mm_serv_req(),
  vlr_proc_acc_req()

We have existing functions to produce a human readable string from a Mobile
Identity, more or less awkward:
- gsm48_mi_to_string() decodes a TMSI as a decimal number. These days we use
  hexadecimal TMSI everywhere.
- osmo_mi_name_buf() decodes the BCD digits from a raw MI every time, so we'd
  need to pass around the raw message bytes. Also, osmo_mi_name_buf() has the
  wrong signature, it should return a length like snprintf().
- osmo-bsc's extract_sub() first uses gsm48_mi_to_string() which encodes the
  raw uint32_t TMSI to a string, and then calls strtoul() via
  tmsi_from_string() to code those back to a raw uint32_t.

Each of the above implementations employ their own size overflow checks, each
invoke osmo_bcd2str() and implement their own TMSI osmo_load32be() handling.
Too much code dup, let's hope that each and every one is correct.

In osmo-bsc, I am now implementing MSC pooling, and need to extract NRI bits
from a TMSI Mobile Identity. Since none of the above functions are general
enough to be re-used, I found myself again copy-pasting Mobile Identity code:
locating the MI in a 24.008 message with proper size checks, decoding MI
octets.

This time I would like it to become a generally re-usable API.

This patch was first merged as Ic3f969e739654c1e8c387aedeeba5cce07fe2307 and
caused test fallout, because it re-implemented old API with the new stricter
decoding. In this patch version, old API remains 1:1 unchanged to avoid such
fallout. Applications will soon switch to the new osmo_mobile_identity API and
become stricter on MI coding when that happens, not implicitly by a new
libosmocore version.

Change-Id: If4f7be606e54cfa1c59084cf169785b1cbda5cf5
2020-06-16 15:17:48 +02:00
Harald Welte a13fb75030 Revert "add osmo_mobile_identity API"
This reverts commit d1ceca9d48, as it
introduces regressions in both osmo-msc and osmo-nitb which have been
causing failing builds for several days now.

Change-Id: I4bd958d0cd2ab4b0c4725e6d114f4404d725fcf7
2020-06-16 09:21:08 +02:00
Neels Hofmeyr d1ceca9d48 add osmo_mobile_identity API
Implement better API around 3GPP TS 24.008 Mobile Identity coding.

struct osmo_mobile_identity is a decoded representation of the raw Mobile
Identity, with a string representation as well as dedicated raw uint32_t TMSI.
The aim is to remove all uncertainty about decoded buffer sizes / data types.

I have patches ready for all osmo programs, completely replacing the Mobile
Identity coding with this new API. Hence deprecate the old MI API.

New API functions provide properly size-checking implementations of:
- decoding a raw MI from a bunch of MI octets;
- locating and decoding MI from a full 3GPP TS 24.008 Complete Layer 3 msgb;
- encoding to a buffer;
- encoding to the end of a msgb.

Other than the old gsm48_generate_mid(), omit a TLV tag and length from
encoding. Many callers manually stripped the tag and value after calling
gsm48_generate_mid(). The aim is to leave writing a TL to the caller entirely,
especially since some callers need to use a TvL, i.e. support a variable-size
length of 8 or 16 bit.

New validity checks so far not implemented anywhere else:
- stricter validation of number of digits of IMSI, IMEI, IMEI-SV MI.
- stricter on filler nibbles to be 0xf.

Rationale:

While implementing osmo-bsc's MSC pooling feature in osmo-bsc, this API will be
used to reduce the number of times a Mobile Identity is extracted from a raw
RSL message.

Extracting the Mobile Identity from messages has numerous duplicate
implementations across our code with various levels of specialization.
https://xkcd.com/927/

To name a few:
- libosmocore: gsm48_mi_to_string(), osmo_mi_name_buf()
- osmo-bsc: extract_sub()
- osmo-msc: mm_rx_loc_upd_req(), cm_serv_reuse_conn(), gsm48_rx_mm_serv_req(),
  vlr_proc_acc_req()

We have existing functions to produce a human readable string from a Mobile
Identity, more or less awkward:
- gsm48_mi_to_string() decodes a TMSI as a decimal number. These days we use
  hexadecimal TMSI everywhere.
- osmo_mi_name_buf() decodes the BCD digits from a raw MI every time, so we'd
  need to pass around the raw message bytes. Also, osmo_mi_name_buf() has the
  wrong signature, it should return a length like snprintf().
- osmo-bsc's extract_sub() first uses gsm48_mi_to_string() which encodes the
  raw uint32_t TMSI to a string, and then calls strtoul() via
  tmsi_from_string() to code those back to a raw uint32_t.

Each of the above implementations employ their own size overflow checks, each
invoke osmo_bcd2str() and implement their own TMSI osmo_load32be() handling.
Too much code dup, let's hope that each and every one is correct.

In osmo-bsc, I am now implementing MSC pooling, and need to extract NRI bits
from a TMSI Mobile Identity. Since none of the above functions are general
enough to be re-used, I found myself again copy-pasting Mobile Identity code:
locating the MI in a 24.008 message with proper size checks, decoding MI
octets.

This time I would like it to become a generally re-usable API.

Change-Id: Ic3f969e739654c1e8c387aedeeba5cce07fe2307
2020-06-12 16:35:26 +02:00
Neels Hofmeyr 0b6a8c8446 osmo_bcd2str: also validate start_nibble parameter
If start_nibble were passed negative, we'd end up accessing invalid memory.
Safeguard against that.

Change-Id: Ied3c1e02c3a01d868e08195cbd8dfa52d2c19ac3
2020-06-12 16:35:26 +02:00
Neels Hofmeyr 7dde1f40a2 add gsm23236: MSC pooling: TMSI and NRI utility functions
These utilities will be used by osmo-bsc to determine the Network Resource
Indicator seen in the TMSI, and (potentially) by osmo-msc to compose a TMSI
with a specific NRI, for osmo-bsc's load balancing between several MSCs.

Add utility functions to:
- extract an NRI value from a TMSI.
- overwrite the NRI value in a TMSI.
- limit an NRI in a (random) TMSI to a given list of ranges.
- add NRI value ranges to a list.
- remove them from a list.
- match NRI value (range) to a list.
- parse NRI values from string, for VTY.
- common VTY functionality of adding/removing NRI values from argv.

Add C tests for the above.

Why we need public API for NRI ranges: In osmo-bsc alone, we need the same NRI
API twice, 1: to manage/list NRI value ranges per-MSC, and 2: to manage/list
NULL-NRI values. If we also consider (potentially) adding NRI support to
osmo-msc, we need the same API twice again there. Hence it is useful to define
re-used API up here in libosmocore.

Related: OS#3682
Change-Id: Icb57a2dd9323c7ea11b34003eccc7e68a0247bf5
2020-06-10 14:20:49 +02:00
Philipp Maier 2908dbfddd gsm0808: fix endieness of call identifier
The call identifier in the ASSIGNMENT COMMAND is encoded in the wrong
endieness. 3GPP TS 48.008, section 3.2.2.105 specifies that the least
significant byte should be transmitted first, which means that the
endieness here is little endian. Lets make sure that the endieness is
correctly transmitted, regardless of the host byte order.

Change-Id: I6468e502f552f99ab54aec9d4b1c169fdc0adfb8
Related: OS#4582
2020-06-09 12:36:38 +02:00
Harald Welte ef5b9b6434 lapd_core: Fix log line being about LAPD and not LAPDm
Change-Id: I92c8a9752e88164eedffb9f9a081288458f6eadb
2020-06-08 21:16:54 +02:00
Harald Welte 00b2faf821 lapd/lapdm: print user-defined string name instead of (dl=%p)
At the moment we print the pointer address to identify the log lines
belonging to a specific connection. Since pointer addresses are
difficult to work with, a human readable ID should be printed instead.

e.g. "This is LAPD instance for SAPI3 on bts0/trx1/ts5/lchan3"

Change-Id: Ie6742843fff809edffcac24c4dce4edf66bc71be
Closes: OS#1938
2020-06-08 21:16:54 +02:00
Harald Welte 68944967b0 NS: replace use of gprs_nsvc_create() with gprs_nsvc_crate2()
Change-Id: I2b10e1707b0976b685d1c14016481d5565888150
2020-06-08 21:16:54 +02:00
Harald Welte 057122e466 NS: Optionally disable NS-{RESET,BLOCK,UNBLOCK} when using UDP/IP
3GPP TS 48.016 is quite clear in that no NS-{RESET,BLOCK,UNBLOCK}
procedures shall be used over an IP based transport.  They are only
for use in Frame Relay based transport.

However, as libosmogb was first developed against ip.access nanoBTS,
and their Gb implementation mandates those procedures, we
unconditionally implemented those procedures back then.  Let's
give the user the option of disabling this behavior to become
more spec compliant (and interoperate with more other vendors out
there).

Change-Id: Ic4eba1b4dcbeac00f5879db295e0a9f1a50f71d8
2020-06-08 21:16:50 +02:00
Harald Welte b795f03faf Implement ITU-T I.460 multiplex / demultiplex
This implements a multiplexer and de-multiplexer for the ITU-T I.460
standard.  The latter covers the transmission of sub-slots of 32/16/8k
inside 64k timeslots.

Change-Id: Id522f06e73b77332b437b7a27e4966872da70eda
2020-05-28 13:08:52 +00:00
Neels Hofmeyr 6d67032d50 fix osmo_mi_name_c() to always return talloced strings, via osmo_mi_name_buf()
Fix osmo_mi_name_buf() to snprintf() into the buf in *all* cases.

osmo_mi_name_c() is implemented via osmo_mi_name_buf(), which returns
compile-time string constants in special cases. That means that
osmo_mi_name_c() does return non-allocated strings in these special cases.
The caller of functions like osmo_mi_name_c() must always be able to rely on
getting a talloced string, or run a danger of deallocating const pointers.

Change-Id: I623959f01b72642bcdd18508097c5c405c59f6f1
2020-05-26 22:30:49 +02:00
Neels Hofmeyr 512bf02e41 api doc: clarify 'returns' of gsm48_mi_to_string()
Change-Id: I81646ff8284061a60c208bd8f9233f66c3e410f8
2020-05-26 22:30:49 +02:00