Commit Graph

1475 Commits

Author SHA1 Message Date
Harald Welte a6f896232e gsm_08_18.h: Add #defines for [extended] feature bits
Change-Id: I7743cb901988c8fddd91127cfdca6e54b3d44ea8
2020-12-08 12:27:38 +00:00
Harald Welte 8f82528bf7 bssgp: Add osmo_tlv_prot_def for BSSGP
Change-Id: I7e4226463f3c935134b5c2c737696fbfd1dd5815
2020-12-08 12:27:38 +00:00
Harald Welte 30a9294306 tlv: Introduce enum with error codes for TLV parser functions
Change-Id: I0b352792089c5c0c714712d2ea237beb92e1d73f
2020-12-08 12:27:38 +00:00
Harald Welte 9510992c53 Introduce 'osmo_tlv_prot' abstraction for validation of TLV protocols
This extends our existing TLV parser with the ability to
* validate that mandatory IEs of a given message are present
* validate that all present IEs are of required minimum length

Introducing this generic layer will help us to reduce open-coded
imperative verification across virtually all the protocols we
implement, as well as add validation to those protocols where we
don't properly perform related input validation yet.

Change-Id: If1e1d9adfa141ca86001dbd62a6a339f9bf9a912
2020-12-08 12:27:38 +00:00
Pau Espin Pedrol 896a9bb2ed Include mnl.h iif --enable-libmnl
Change-Id: I06016e3a6e90b09b76634a00081d0d40a8e2f94b
2020-12-07 13:24:30 +01:00
Harald Welte 7fc88b3248 log2.h: Avoid redefining __always_inline
/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h:10:0: error: "__always_inline" redefined [-Werror]
 #define __always_inline               inline __attribute__((always_inline))
/usr/include/x86_64-linux-gnu/sys/cdefs.h:311:0: note: this is the location of the previous definition
 # define __always_inline __inline __attribute__ ((__always_inline__))

Change-Id: I738d2a72f835a29e30b8ba20456e5c4c9aa844c9
2020-12-06 15:45:52 +01:00
Harald Welte c172d9fe8d log2.h: Use uintXX_t instead of kernel specific types
Change-Id: Ieb872551bdbe514f2c77f9aeb2b9ee42f6573909
2020-12-06 15:14:35 +01:00
Harald Welte 622cda3802 hash/log2: Add generic implementations of fls() and fls64()
When importing the hashtable code in I8ef73a62fe9846ce45058eb21cf999dd3eed5741
I didn't import actual implementations of the fls() and fls64()
implementations, as at least gcc-10 was smart enough to detect
we only use it on constant types and hence the computation can happen
at build time via const_ilog2()

However, in our jenkins build verification' this doesn't appear to
happen, as we get below errors:

/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h: In function ‘__ilog2_u32’:
/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h:20:9: error: implicit declaration of function ‘fls’ [-Werror=implicit-function-declaration]
  return fls(n) - 1;
         ^~~
/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h: In function ‘__ilog2_u64’:
/build/deps/install/stow/libosmocore/include/osmocom/core/log2.h:28:9: error: implicit declaration of function ‘fls64’ [-Werror=implicit-function-declaration]
  return fls64(n) - 1;
         ^~~~~

Let's provide some generic implementations for this case.  If needed
one could also introduce architecture-specific assembly implementations
like in the Linux kernel, but so far we managed to keep libosmocore free
of any assembly tweaks.

Change-Id: Ifa4898eb66c8d949618edd47961b7a0330ed35b5
2020-12-06 14:40:55 +01:00
Harald Welte c22e002890 gsm_08_18.h: Add some PDU definitions still missing
In I7da8b25c9a89a7e3ae6c1680ba838e136d7d5293 I seem to have failed
to realize that 3GPP TS 48.018 v15.0.0.0 Table 11.3.26 continues
on yet another page.  Let's add those missing PDU types definitions.

Change-Id: I9173c35240ff78048b2b76a1155d90467ef16b2d
2020-12-06 12:56:29 +01:00
Harald Welte 77530b4619 Use explicit type-casting in hlist_del() for C++ compatibility
/usr/local/include/osmocom/core/linuxlist.h:479:12: error: invalid conversion from ‘void*’ to ‘hlist_node*’ [-fpermissive]
  479 |  n->next = LLIST_POISON1;

Fixes: I8ef73a62fe9846ce45058eb21cf999dd3eed5741
Change-Id: I75b0a5fe097562007c53987d8d41811e9f35798d
2020-12-05 20:16:51 +01:00
Vadim Yanitskiy 59e13e4d25 core/linuxlist: do not use 'new' as a parameter name
'new' is a reserved keyword in C++, so including this header from
a C++ project (like osmo-pcu) breaks compilation.  Let's rename
it in the same way as it's already done in this file: add '_'.

Change-Id: I7f7d9143edca75ce932601386a8766b0a62c0e24
Fixes: I8ef73a62fe9846ce45058eb21cf999dd3eed5741
2020-12-05 15:07:51 +01:00
Harald Welte 7101ca2751 Add hlist and hashtable from Linux kernel
For more than a decade we've used the linuxlist.h for double-linked
lists.  Let's also add the hlist (double-linked lists with single
pointer sized head, and the hashtable that builds on top of it.

This reflects the versions included in Linux 5.8 with some modifications
to make them build in userspace (remove RCU versions, adjust for
userspace include files and types, convert to doxygen).

Change-Id: I8ef73a62fe9846ce45058eb21cf999dd3eed5741
2020-12-05 11:39:42 +01:00
Harald Welte e3b20edec5 bssgp: Fix typo in BSSGP Message Type enum
Change-Id: I63941f8b38485e569f56ba5065c2c00232703028
2020-12-04 18:20:15 +00: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
Harald Welte 6e887ebd3e gsm_08_18.h: Update enums for message types and IEs with Release 15
Lots of newly introduced message types and information elements.

Change-Id: I7da8b25c9a89a7e3ae6c1680ba838e136d7d5293
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
Daniel Willmann fd3478ca4f logging: Calculate LOG_MAX_{CTX,FILTERS} from the enum
Change-Id: I1ee1278b029e42321932b87f94aa3e0eeed4108a
Related: SYS#5232
2020-12-02 18:14:17 +01:00
Harald Welte a20248a361 cosmetic: frame_relay: Fix typos
Change-Id: Ifc29ddb43745571096b458393692a68052898daa
2020-12-01 18:01:43 +01:00
Pau Espin bfcce40618 gsm: Add enum for Network Feature Support IE
Change-Id: Ie409fd163b612bc3e2d7b8bf22d720705f0f6af1
2020-12-01 11:26:57 +00: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
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
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
Philipp Maier 595908aab1 gsm_08_58: add rxqual field to RSL_IE_OSMO_REP_ACCH_CAP
In order to transfer an RXQUAL threshold to the BTS as well, the struct
that defines the contents of RSL_IE_OSMO_REP_ACCH_CAP needs to be
updated with a 3 bit field to contain the RXQUAL value.

Change-Id: I6dda239e9cd7033297bed1deb5eb1d9f87b8433f
Related: SYS#5114 OS#4796 OS#4794 OS#4795
2020-11-20 20:21:43 +00:00
Harald Welte 465c9a5937 bssgp: Input argument to bssgp_tlv_parse() should be 'const'
Change-Id: I397b32a6e6ea3e9d218446138cceafa9b27685dd
2020-11-18 12:22:25 +01:00
Philipp Maier 439ddbe7a1 gsm_08_58: add struct for RSL_IE_OSMO_REP_ACCH_CAP
The recently added IE is used to transfer a bitfield, lets add a struct
that describes the bitfield. This makes the IE easier to use.

Change-Id: I326e66dae25acfab0b3fddc7278b39a8cbf7d385
Related: SYS#5114, OS#4796, OS#4794, OS#4795
2020-11-17 09:45:42 +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
Philipp Maier aa718462bf bts_features: add feature BTS_FEAT_ACCH_REP
Change-Id: Ib4d1d8d8a1a1d58bc320a1c0eff2d52100267f09
Related: SYS#5114, OS#4796, OS#4794, OS#4795
2020-11-16 14:29:31 +00: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
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
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
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
Daniel Willmann 07a923ff14 Add exported function btsctx_alloc to public header
Change-Id: Iddfb8e42d5d9e856c7165d3cff6c39191c86a4a5
2020-11-03 21:26:48 +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
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
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
Vadim Yanitskiy f36b76211f application: do not document unrelated forward-declarations
Change-Id: Ic04caab15abbd0c0d3a01f6e128935a3ceed903e
2020-10-24 04:08:19 +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 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 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
Harald Welte fa2d66ca18 ns2: More verbose comments on gprs_ns2_vc_mode
Change-Id: I647b9d883c1acc47cd352196a819a9c9bf8dc6ff
2020-10-17 13:10: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
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
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 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
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
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
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
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 e566bddaff vty: introduce and use VTY_CMD_USR_ATTR_NUM
Change-Id: Ib4327835f5be264ef67a01d8f4733dd2d091eaf1
Related: SYS#4937
2020-10-06 21:01:08 +00: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 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
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
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 e9069ebfec gsm_12_21: add osmo_oml_nsvc_address_type for OML NM_ATT_OSMO_NS_LINK_CFG
The NM_ATT_OSMO_NS_LINK_CFG is used for NSVC configuration of osmocom based BTS to support
IPv6 NSVCs.

Change-Id: I9e279bb20940c66eea5196f281184cb4f8a5cc5f
2020-09-30 11:59:28 +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 4a96b7c7b9 vty/command: introduce new attribute CMD_ATTR_IMMEDIATE
This attribute indicates that a VTY command applies immediately.

Change-Id: Ia185dfd0c89214dc893af70736ff01dca3a7627e
Related: SYS#4937
2020-09-28 12:44:33 +07:00
Daniel Willmann 4fb27a80d2 gprs_ns2: Make reason const
Change-Id: Ia0db18703d9fd137a5c5fe4474e2d76868a9af9d
2020-09-25 15:39:46 +02: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
Daniel Willmann 4692a1c3bf gsm_08_16.h: Add missing header
utils.h is needed for struct value_string
This probably never caused a problem because every file including
gsm_08_16.h also included utils.h, but we should still include the file
here.

Change-Id: Iae09b4e8e42be6c371fb34279b7981db2af8cf4c
2020-09-21 16:06:37 +02:00
Vadim Yanitskiy 7f1ecd9eb4 vty: add program specific attributes to VTY commands
Change-Id: I2c6c7b317b2b28ce70784c0cabd1b913e721be02
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 158143f0fa ipaccess.h: Add more enum values and 'official' names
Originally we only learned about the protocol from looking at hexdumps
without any specification or the like.

Due to a GPL request to ip.acecss, we actually do have an 'official'
resource: The packet-ipa.c from their wireshark-1.0.6ipa27.tar.gz

Let's use its contents to complete our definitions here.

Change-Id: Ic1f2b32c72d162f31b422293d2a361d528443f01
2020-09-18 16:11:38 +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
Neels Hofmeyr f6db765327 bitXXgen: add osmo_loadXXbe_ext_2() to get right-adjusted values
As shown in the recently added bitgen_test.c, using osmo_loadXXbe_ext() with a
smaller n produces results aligned on the most significant bytes, which is
cumbersome, since it does not return a previously stored value. This problem
exists only for the big-endian functions, the little-endian osmo_loadXXle_ext()
properly return values adjusted on the least significant octets.

Add osmo_loadXXbe_ext_2() variants that properly right-adjust the returned
value. Prominently highlight this behavior in API doc. Test the new functions
in bitgen_test.c.

For example, this eases handling of 24bit integers (e.g. loaded from buffer to
uint32_t, and stored into buffer from uint32_t). Also explicitly show this 24
bit case in bitgen_test.c

Change-Id: I2806df6f0f7bf1ad705d52fa386d4525b892b928
2020-09-14 11:53:46 +00:00
Neels Hofmeyr c0ac4e37c9 bitXXgen: ensure not reading/storing past valid size
Add OSMO_ASSERT()s to ensure bounds checking.

For example, for osmo_store32le_ext(), passing n > 5 would read past the end of
the uint32_t. Similarly, osmo_load32le_ext() for n > 4 would write past the
uint32_t's end.

Change-Id: I2dc21582cd8a679b6624cefbc0c1678b093a3d08
2020-09-14 11:53:46 +00: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 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 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
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 e9fd7ff9d9 l1sap.h: Fix typo in doxygen documentation
Change-Id: I5772d02704ef289945b8b70d1ebe8a8aa8b79362
2020-08-25 11:42:46 +00:00