Commit Graph

36 Commits

Author SHA1 Message Date
Neels Hofmeyr f9b0746d7d fixup for: add osmo_scu_prim_name_c() / _buf()
I would like to tweak the names for the recently added functions, so
that they are more clear -- quickly before we release it or anyone uses
these.

Depends: libosmocore I9f43428af654a5674ac3035fe4db1394aac7a7af
Related: I4c1998fd7fee7282d107846dae2cff4b5ceb3a7b
Change-Id: If381f537ab91af1feef7f0e51921217f27e18e6a
2023-02-22 16:02:51 +01:00
Neels Hofmeyr 4c761ba304 add osmo_scu_prim_name_c() / _buf()
Add non-legacy string functions for osmo_scu_prim_name in the form of
_buf() and _c() signatures.

So far there is only osmo_scu_prim_name() using a static buffer.
Implement that using osmo_scu_prim_name_buf().

Change-Id: I4c1998fd7fee7282d107846dae2cff4b5ceb3a7b
2023-02-18 02:45:14 +01:00
Max f4301b7f45 [cosmetic] sccp_scoc.c: constify function parameters
Related: OS#5579
Change-Id: I398e3efa3e097de8907617cfdf363e1d3b96f666
2022-08-21 21:52:45 +07:00
Oliver Smith ebccb824a0 osmo_ss7_vty: add osmo_sccp_addr_by_name_local
Add a new function similar to osmo_sccp_addr_by_name, but search in a
specific ss7 instance's addressbook instead of searching in the global
address book. This is needed for osmo-bsc-nat, which uses two separate
instances at the same time.

Related: SYS#5560
Change-Id: I0f38b0d038b0dd8cd355e7284e5b56d438811bd9
2022-02-01 11:08:34 +00:00
Oliver Smith e3e79e2806 include/osmocom/sigtran/sccp_sap.h: cosmetic fixes
Move return type to the same line as the name of the function to follow
coding guidelines.

Change-Id: I10475aa395a1cfd49ff62c758f99f9689a0038d0
2022-02-01 11:08:34 +00:00
Harald Welte 943affdd48 sccp: Notify users of point code available/unavailable
* add N-PCSTATE.ind and N-STATE.ind definitions to SCCP user SAP
* add minimal SCMG (SCCP Management) and LBCS (Local Broadcast)
* generate MTP-PAUSE.ind/MTP-RESUME.ind based on received xUA DUNA/DAVA
* generate N-PCSTATE.ind towards the local SCCP users

Change-Id: Idb799f7d7ab329ad12f07b7cbe6336da0891ae92
Related: OS#2623, OS#3403, OS#4701
2021-02-08 18:00:56 +01:00
Neels Hofmeyr b114b73e5d add OSMO_SCCP_ADDR_T_MASK for osmo_sccp_addr_cmp()
Avoid magic number 0xffffffff and rather provide a mask value for all address
components.

Change-Id: I13ff0858e496c4392b8e1590d62f7eb80f191a07
2020-09-05 00:10:01 +02:00
Neels Hofmeyr ec3e7e43ab enum osmo_sccp_ssn: rename to OSMO_SCCP_SSN_SMLC_BSSAP_LE
Quoting 3GPP TS 23.003 8.2:

 1111 1010 BSC (BSSAP-LE);
 1111 1011 MSC (BSSAP-LE);
 1111 1100 SMLC (BSSAP-LE);

Hence the SMLC one should also be named *_BSSAP_LE.

I'm certain no other osmocom code is using this SSN yet, but anyway keep a
backwards compat shim #define.

Change-Id: I3e0c1be0ebbd3883d024174d1e7e9167a8281cfb
2020-09-03 23:56:13 +02:00
Neels Hofmeyr d25ba11eef add osmo_sccp_user_find() as public API
To allow osmo-bsc to add more than one MSC peer on a single SCCP instance, it
must add a local SCCP user only once per SCCP instance. The first configured
MSC adds a local user, all subsequent MSC should use the same local SCCP user.
So, it is most convenient to provide a public function to return such user if
it exists.

Add as thin wrapper instead of renaming and moving the internal
sccp_user_find(): to keep the patch smaller, and to match the way
osmo_sccp_user_bind_pc() is a 1:1 wrapper for sccp_user_bind_pc().

Related: OS#3682
Change-Id: I9ecbab16b45268f626950303d6ff8296dd6acda0
2020-05-22 23:15:55 +02:00
Neels Hofmeyr 21ff9ae426 add osmo_sccp_addr_cmp(), osmo_sccp_addr_ri_cmp()
osmo-msc identifies its BSC and RNC peers by SCCP address, and compares those
by memcmp(), which is not really accurate. Rather provide a meaningful
osmo_sccp_addr_cmp() API to determine whether SCCP addresses are identical.

Go for a full cmp that would also allow sorting.

Change-Id: Ie9e2add7bbfae651c04e230d62e37cebeb91b0f5
2019-04-12 06:28:34 +02:00
Neels Hofmeyr ac729eb5a8 add caller-owns-msgb variant osmo_sccp_user_sap_down_nofree()
Add osmo_sccp_user_sap_down_nofree(), which is identical to
osmo_sccp_user_sap_down(), but doesn't imply a msgb_free().

To implement that, sccp_sclc_user_sap_down_nofree() with the same msgb
semantics is required.

Rationale:

Avoiding msgb leaks is easiest if the caller retains ownership of the msgb.
Take this hypothetical chain where leaks are obviously avoided:

  void send()
  {
  	msg = msgb_alloc();
	dispatch(msg);
	msgb_free(msg);
  }

  void dispatch(msg)
  {
  	osmo_fsm_inst_dispatch(fi, msg);
  }

  void fi_on_event(fi, data)
  {
	if (socket_is_ok)
		socket_write((struct msgb*)data);
  }

  void socket_write(msgb)
  {
  	if (!ok1)
		return;
	if (ok2) {
		if (!ok3)
			return;
		write(sock, msg->data);
	}
  }

However, if the caller passes ownership down to the msgb consumer, things
become nightmarishly complex:

  void send()
  {
  	msg = msgb_alloc();
	rc = dispatch(msg);
	/* dispatching event failed? */
	if (rc)
		msgb_free(msg);
  }

  int dispatch(msg)
  {
  	if (osmo_fsm_inst_dispatch(fi, msg))
		return -1;
	if (something_else())
		return -1; // <-- double free!
  }

  void fi_on_event(fi, data)
  {
	if (socket_is_ok) {
		socket_write((struct msgb*)data);
	else
		/* socket didn't consume? */
		msgb_free(data);
  }

  int socket_write(msgb)
  {
  	if (!ok1)
		return -1; // <-- leak!
	if (ok2) {
		if (!ok3)
			goto out;
		write(sock, msg->data);
	}
  out:
        msgb_free(msg);
	return -2;
  }

If any link in this call chain fails to be aware of the importance to return a
failed RC or to free a msgb if the chain is broken, or to not return a failed
RC if the msgb is consumed, we have a hidden msgb leak or double free.

This is the case with osmo_sccp_user_sap_down(). In new osmo-msc, passing data
through various FSM instances, there is high potential for leak/double-free
bugs. A very large brain is required to track down every msgb path.

osmo_sccp_user_sap_down_nofree() makes this problem trivial to solve even for
humans.

Change-Id: Ic818efa78b90f727e1a94c18b60d9a306644f340
2019-04-12 06:27:10 +02:00
Neels Hofmeyr e4a77d4673 add osmo_sccp_user_name()
There is a naming dilemma: though the osmo_ prefix is now reserved for
libosmocore, all surrounding API already has the osmo_ prefix.

This will be used by osmo-hnbgw's VTY 'show cnlink' command.

Change-Id: Ib7abf69cfcf4c56273223054b280458451e6c2f6
2017-12-24 20:32:03 +01:00
Harald Welte 769e9354ab sccp_sap.h: Fix SSN for BSSAP and BSSAP-LE
* BSSAP is 254 on both MSC and BSC side: Add missing define
* BSSAP-LE (LCS Extension) has 250/251, adjust name to add -LE suffix

Change-Id: Iccec75cfc0cf16bd717a9bd4606d1e772c332ccc
2017-09-03 21:20:32 +02:00
Philipp Maier 3219e52dcf sccp: fixup for osmo_sccp_get_ss7()
osmo_sccp_get_ss7() has the risk of a nullpointer dereference, when
sccp is NULL.

Return NULL when the sccp instance is NULL.

Add doxygen comment

Change-Id: I84d484e4441fd37443fff8c67e17df8fb15d5b2e
2017-08-11 17:49:38 +02:00
Philipp Maier c34bcd42e4 sccp: function to get sccp instance from sccp user
It is currently impossible to find out which SCCP instance handles
a particular user.

Introduce function to lookup the SCCP instance from a given SCCP
user.

Change-Id: I9562c4f1d00e2ebb3252c5dea598b643aa393719
2017-08-11 17:42:35 +02:00
Neels Hofmeyr 603e065f43 add osmo_sccp_addr_name() and three value_string[]s
osmo_sccp_addr_dump() just prints the raw values. In osmo_sccp_addr_name(), use
osmo_ss7_pointcode_print() and newly added RI, SSN and GT value_string[] to
print more human readable log output.

Change-Id: Ie1aedd7894acd69ddc887cd65a8a0df4b888838c
2017-08-09 13:54:44 +02:00
Neels Hofmeyr c881c49127 introduce OSMO_SCCP_RI_NONE to indicate unset RI
Allows to automatically set an RI in future change
I75c67d289693f1c2a049ac61cf2b2097d6e5687d
"sccp-addr vty: set RI to SSN_PC when setting a point-code"

Change-Id: I6e2f31b023b08cba2f2ee8234e6108efcaca41c0
2017-08-09 13:54:44 +02:00
Philipp Maier 81a029a4e4 sccp: add function to check sccp addresses
In order to catch invalid CS7 configurations, It is necessary
to check if sccp addresses contain plausible address data.

Change-Id: Ic6245288b0171eae10aa708403c1ddb584c92f38
2017-08-09 09:53:35 +00:00
Philipp Maier 882f340b6c sccp: derive local address from given sccp instance
The most important parts of an SCCP address are the routing
indicator and the pointcode. The latter one is always available
via the SS7 instance, so a basic local address can be derived
from there.

Add function osmo_sccp_local_addr_by_instance() to derive a basic
local SCCP address from a given SCCP instance

Change-Id: I371dc9132871aad3d8321ea13cf9fd69d76eff8f
2017-08-01 11:08:05 +00:00
Philipp Maier 9fc351de69 sccp: global addressbook search + api fix
The sccp-addressbook only allows defining addresses for a specific
ss7 instance. It is not possible to use an sscp-address, that is
defined in the one ss7 instance in another ss7 instance.

Add a second global list where all sscp-addresses are added,
regardless on which instance they are defined.

Fixup the search functions so that they always search the global
list.

Change the API, so that the address data is written to a
destination pointer. This protects the stored address from
unintentional changes. Also return the ss7 instance, where the
address is associated with.

Change-Id: I5acc1e5abc3b3081149a9f476038e4e53d23b763
2017-07-20 12:38:37 +02:00
Philipp Maier 34cb3c16a5 sccp: add addressbook functionality for sccp addresses
SCCP addresses are defined through a number of compoinents, not
just an IP-Address, there is also point code, ssn and more. To
simplify and unify the handling of such objects, this patch
introduces an addressbook functionality. The user can set up
multiple addresses per ss7 instance and give them names. Later
that name can be used to reference the address at a later point
in the config. This means that the usage of sccp-addresses from
the programmers point of view boils down to a VTY function that
reads the string name of a previously defined address. The
programmer can then use the API to get a pointer to the SCCP
address struct and use it normally.

For this feature, two additional VTY nodes are necessary,
this commit depends libosmocore change:
Change-Id I42aa29c0cccc97f284b85801c5329b015b189640

Change-Id: I068ed7f7d113dab88424a9d47bab7fc703bb7942
2017-06-21 18:02:05 +02:00
Harald Welte c031536808 SCCP: Add VTY interface for SCCP
Change-Id: I100daaa947dbab6a4528c4e9fbd0d30790288f63
2017-04-14 20:25:50 +02:00
Harald Welte 30c2b89925 Add osmo_sccp_get_ss7() accessor function
as 'struct osmo_sccp_instance' is opaque to the user application, it is
useful to have an accessor function that resolves the ss7 instance used
by the SCCP instance.

Change-Id: I8057a6d69584239b9781c5cece42066293ea1dd6
2017-04-10 11:48:35 +02:00
Harald Welte c9c11b6cfd sccp: add osmo_sccp_user_{get,set}_priv() API function
As 'struct osmo_sccp_user' is private, we need this accessor functions
for the SCCP User so it can set and get the 'priv' data.

Change-Id: Ia68a36dc18a7d754d63ae29c86d68e495b5c4134
2017-04-10 11:48:34 +02:00
Harald Welte ee350893cf Add new SCCP implementation
This is an implementation of SCCP as specified in ITO-T Q.71x,
particularly the SCRC (routing), SCLC (Connectionless) and SCOC
(Connection Oriented) portions.  the elaborate state machines of
SCOC are implemented using osmo_fsm, with one state machine for each
connection.

Interfaces to the top (user application) are the SCCP-USER-SAP and on
the bottom (network) side the MTP-USER-SAP as provided by osmo_ss7.

Contrary to a straight-forward implementation, the code internally
always uses a SUA representation of all messages (in struct xua_msg).
This enables us to have one common implementation of all related state
machines and use them for both SUA and SCCP.  If used with real SCCP
wire format, all messages are translated from SCCP to SUA on ingress and
translated from SUA to SCCP on egress.  As SUA is a super-set of SCCP,
this can be done "lossless".

Change-Id: I916e895d9a4914b05483fe12ab5251f206d10dee
2017-04-10 11:48:34 +02:00
Harald Welte d75e8967ef License headers: Should always have been GPLv2-or-later
libosmo-sigtran is GPLv2-or-later, there were some files that
accidentially had an AGPLv3 license header, which was a copy+paste
mistake at that time.

Change-Id: I67dfd0ae6157afafd3873a3baaa4c6107c04ddfd
2017-04-10 10:41:16 +02:00
Harald Welte 3b0abab223 sccp_sap: Add support for N-NOTICE.indication
Change-Id: I6656889b4333e9909cf1c60c24dfc754281547b4
2017-04-10 10:41:16 +02:00
Harald Welte 18d00e046b sccp_sap: Add routing indication (RI) to osmo_sccp_addr
Change-Id: I4dd23150f4c588b6430c22fc0cb66635994ceea9
2017-04-10 10:41:16 +02:00
Harald Welte 3d2aa4a5c0 sccp_sap: Use zero-terminated string for GT digits in osmo_sccp_addr
This is more natural to most application code, so simply go for ASCII
string with NUL-termination rather than an array with explicit length.

Change-Id: I6312208cdfa83184be41157a473c96e9120c63db
2017-04-10 10:41:16 +02:00
Neels Hofmeyr fe19e46783 cosmetic: add comments for GT, PC, SSN to help noobs finding their way
Change-Id: I8f47f855c2718f4922b36229a388fa719c628bf6
2017-01-27 09:59:31 +01:00
Neels Hofmeyr bfdbde2bd8 fix struct member typo: repsonding_addr in osmo_scu_disconn_param
By accident, I already fixed this typo in osmo-iuh, breaking the build. Instead
of reverting there, fix it here.

Change-Id: I4076fb37c0d94be7adff46e76465884a61c54c9a
2016-07-07 15:23:16 +02:00
Harald Welte a5b2fed35b Add more OSMO_SCCP_SSN_ defines
hopefully we should now know all that we ever expect to need.
2016-04-16 13:27:50 +02:00
Neels Hofmeyr 752b39e763 Fix RANAP SSN: it's 142, not 143
143 is actually the SSN for RNSAP. Wireshark displayed a RNSAP message type
and malformed packet warning until I fixed this to 142. Now I get the proper
RANAP and id-Paging reported.

There has been a reallocation for RANAP and RNSAP SSNs, though the old SSN for
RANAP is apparently 32 (seen in a pcap from a real 3G network). When I send 32
instead of 142, wireshark also decodes the message as valid RANAP.
2016-04-16 13:15:59 +02:00
Harald Welte 0b44895a88 Add missing OSMO_SCCP_SSN_RANAP for RANAP SSN 2015-12-25 16:53:57 +01:00
Harald Welte f57a1594b7 Properly define SCCP_SAP_USER without random magic number 2015-12-23 14:16:21 +01:00
Harald Welte bf49cc1c00 Import SUA (SCCP User Adaptation) and SCCP User SAP
... this code originates from the osmo-iuh repository, but is now part
of a new shared libosmo-sigtran.so library generated in this repository.
2015-12-22 23:03:41 +01:00