blob: 256d8fa89597a82891e6e69bac8065364179f8bc [file] [log] [blame]
Harald Weltea803b722020-08-21 15:42:26 +02001module BSSAP_LE_Adapter {
2
3/* This module implements a 'dumb' BSSAP_LE adapter. It creates the M3UA and SCCP components and stacks a
4 * BSSAP_LE codec port on top. As a result, it provides the ability to transceive SCCP-User-SAP primitives
5 * with deoded BSSAP_LE payload. Use this if you want to have full control about what you transmit or
6 * receive, without any automatisms in place. Allows you to refuse connections or other abnormal behavior. */
7
8/* (C) 2017-2020 Harald Welte <laforge@gnumonks.org>
9 * contributions by sysmocom - s.f.m.c. GmbH
10 * All rights reserved.
11 *
12 * Released under the terms of GNU General Public License, Version 2 or
13 * (at your option) any later version.
14 *
15 * SPDX-License-Identifier: GPL-2.0-or-later
16 */
17
18import from General_Types all;
19import from Osmocom_Types all;
20
21import from M3UA_Emulation all;
22import from MTP3asp_Types all;
23import from MTP3asp_PortType all;
24
25import from IPA_Emulation all;
26
27import from SCCP_Types all;
28import from SCCPasp_Types all;
29import from SCCP_Emulation all;
30import from SCCP_Templates all;
31
32import from SCTPasp_Types all;
33import from SCTPasp_PortType all;
34
35import from BSSMAP_LE_Templates all;
36import from BSSAP_LE_Emulation all;
37
38type record BSSAP_LE_Adapter {
39 /* component references */
40 M3UA_CT vc_M3UA, /* only in 3GPP AoIP */
41 SCCP_CT vc_SCCP,
42
43 MSC_SCCP_MTP3_parameters sccp_pars,
44 SCCP_PAR_Address sccp_addr_own,
45 SCCP_PAR_Address sccp_addr_peer,
46
47 /* handler mode */
48 BSSAP_LE_Emulation_CT vc_BSSAP_LE
49}
50
51type record BSSAP_LE_Configuration {
52 charstring sccp_service_type,
53 SCTP_Association_Address sctp_addr,
54 integer own_pc,
55 integer own_ssn,
56 integer peer_pc,
57 integer peer_ssn,
58 octetstring sio,
59 integer rctx
60};
61type record of BSSAP_LE_Configuration BSSAP_LE_Configurations;
62
63private function init_pars(inout BSSAP_LE_Adapter ba, in BSSAP_LE_Configuration cfg) {
64 ba.sccp_pars := {
65 sio := {
66 ni := substr(oct2bit(cfg.sio),0,2),
67 prio := substr(oct2bit(cfg.sio),2,2),
68 si := substr(oct2bit(cfg.sio),4,4)
69 },
70 opc := cfg.own_pc,
71 dpc := cfg.peer_pc,
72 sls := 0,
73 sccp_serviceType := cfg.sccp_service_type,
74 ssn := cfg.own_ssn
75 };
76 ba.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(cfg.own_pc, cfg.own_ssn, cfg.sio, cfg.sccp_service_type));
77 ba.sccp_addr_peer := valueof(ts_SccpAddr_PC_SSN(cfg.peer_pc, cfg.peer_ssn, cfg.sio, cfg.sccp_service_type));
78}
79
80
81function f_bssap_le_adapter_init(inout BSSAP_LE_Adapter ba, in BSSAP_LE_Configuration cfg, charstring id,
82 template BssapLeOps ops) {
83 init_pars(ba, cfg);
84 ops.sccp_addr_local := ba.sccp_addr_own;
85 ops.sccp_addr_peer := ba.sccp_addr_peer;
86
87 /* create components */
Harald Welte71389132021-12-09 21:58:18 +010088 ba.vc_SCCP := SCCP_CT.create(id & "-SCCP") alive;
Harald Weltea803b722020-08-21 15:42:26 +020089 if (isvalue(ops)) {
Harald Welte71389132021-12-09 21:58:18 +010090 ba.vc_BSSAP_LE := BSSAP_LE_Emulation_CT.create(id & "-BSSAP_LE") alive;
Harald Weltea803b722020-08-21 15:42:26 +020091 } else {
92 ba.vc_BSSAP_LE := null;
93 }
Harald Welte71389132021-12-09 21:58:18 +010094 ba.vc_M3UA := M3UA_CT.create(id & "-M3UA") alive;
Harald Weltea803b722020-08-21 15:42:26 +020095 map(ba.vc_M3UA:SCTP_PORT, system:sctp);
96 /* connect MTP3 service provider (M3UA) to lower side of SCCP */
97 connect(ba.vc_M3UA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
98 ba.vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr, cfg.rctx));
99
100 if (isvalue(ops)) {
101 timer T := 5.0;
102 T.start;
103 //T.timeout;
104 /* connect BSSNAP component to upper side of SCCP */
105 log("Connecting BSSAP_LE_Emulation to SCCP_SP_PORT");
106 connect(ba.vc_BSSAP_LE:BSSAP_LE, ba.vc_SCCP:SCCP_SP_PORT);
107 log("Starting BSSAP_LE_Emulation");
108 ba.vc_BSSAP_LE.start(BSSAP_LE_Emulation.main(valueof(ops), ""));
109 }
110
111
112}
113
114function f_bssap_le_adapter_start(inout BSSAP_LE_Adapter ba) {
115 ba.vc_SCCP.start(SCCPStart(ba.sccp_pars));
116}
117
118function f_bssap_le_adapter_cleanup(inout BSSAP_LE_Adapter ba) {
119 if (ba.vc_BSSAP_LE != null) {
120 disconnect(ba.vc_BSSAP_LE:BSSAP_LE, ba.vc_SCCP:SCCP_SP_PORT);
121 ba.vc_BSSAP_LE.stop;
122 }
123 unmap(ba.vc_M3UA:SCTP_PORT, system:sctp);
124 disconnect(ba.vc_M3UA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
125 ba.vc_M3UA.stop;
126 ba.vc_SCCP.stop;
127}
128
129
130}