blob: 9305c63bc12622a724a8b8b2e2c6a811018027f9 [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,
Harald Welte843917e2023-04-15 02:54:34 +080059 integer rctx optional
Harald Weltea803b722020-08-21 15:42:26 +020060};
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
Harald Welte843917e2023-04-15 02:54:34 +080087 var template (omit) integer rctx;
88 if (not ispresent(cfg.rctx)) {
89 rctx := omit;
90 } else {
91 rctx := cfg.rctx;
92 }
93
Harald Weltea803b722020-08-21 15:42:26 +020094 /* create components */
Harald Welte71389132021-12-09 21:58:18 +010095 ba.vc_SCCP := SCCP_CT.create(id & "-SCCP") alive;
Harald Weltea803b722020-08-21 15:42:26 +020096 if (isvalue(ops)) {
Harald Welte71389132021-12-09 21:58:18 +010097 ba.vc_BSSAP_LE := BSSAP_LE_Emulation_CT.create(id & "-BSSAP_LE") alive;
Harald Weltea803b722020-08-21 15:42:26 +020098 } else {
99 ba.vc_BSSAP_LE := null;
100 }
Harald Welte71389132021-12-09 21:58:18 +0100101 ba.vc_M3UA := M3UA_CT.create(id & "-M3UA") alive;
Harald Weltea803b722020-08-21 15:42:26 +0200102 map(ba.vc_M3UA:SCTP_PORT, system:sctp);
103 /* connect MTP3 service provider (M3UA) to lower side of SCCP */
104 connect(ba.vc_M3UA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
Harald Welte843917e2023-04-15 02:54:34 +0800105 ba.vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr, rctx));
Harald Weltea803b722020-08-21 15:42:26 +0200106
107 if (isvalue(ops)) {
108 timer T := 5.0;
109 T.start;
110 //T.timeout;
111 /* connect BSSNAP component to upper side of SCCP */
112 log("Connecting BSSAP_LE_Emulation to SCCP_SP_PORT");
113 connect(ba.vc_BSSAP_LE:BSSAP_LE, ba.vc_SCCP:SCCP_SP_PORT);
114 log("Starting BSSAP_LE_Emulation");
115 ba.vc_BSSAP_LE.start(BSSAP_LE_Emulation.main(valueof(ops), ""));
116 }
117
118
119}
120
121function f_bssap_le_adapter_start(inout BSSAP_LE_Adapter ba) {
122 ba.vc_SCCP.start(SCCPStart(ba.sccp_pars));
123}
124
125function f_bssap_le_adapter_cleanup(inout BSSAP_LE_Adapter ba) {
126 if (ba.vc_BSSAP_LE != null) {
127 disconnect(ba.vc_BSSAP_LE:BSSAP_LE, ba.vc_SCCP:SCCP_SP_PORT);
128 ba.vc_BSSAP_LE.stop;
129 }
130 unmap(ba.vc_M3UA:SCTP_PORT, system:sctp);
131 disconnect(ba.vc_M3UA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
132 ba.vc_M3UA.stop;
133 ba.vc_SCCP.stop;
134}
135
136
137}