Harald Welte | a803b72 | 2020-08-21 15:42:26 +0200 | [diff] [blame] | 1 | module 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 | |
| 18 | import from General_Types all; |
| 19 | import from Osmocom_Types all; |
| 20 | |
| 21 | import from M3UA_Emulation all; |
| 22 | import from MTP3asp_Types all; |
| 23 | import from MTP3asp_PortType all; |
| 24 | |
| 25 | import from IPA_Emulation all; |
| 26 | |
| 27 | import from SCCP_Types all; |
| 28 | import from SCCPasp_Types all; |
| 29 | import from SCCP_Emulation all; |
| 30 | import from SCCP_Templates all; |
| 31 | |
| 32 | import from SCTPasp_Types all; |
| 33 | import from SCTPasp_PortType all; |
| 34 | |
| 35 | import from BSSMAP_LE_Templates all; |
| 36 | import from BSSAP_LE_Emulation all; |
| 37 | |
| 38 | type 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 | |
| 51 | type 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 Welte | 843917e | 2023-04-15 02:54:34 +0800 | [diff] [blame] | 59 | integer rctx optional |
Harald Welte | a803b72 | 2020-08-21 15:42:26 +0200 | [diff] [blame] | 60 | }; |
| 61 | type record of BSSAP_LE_Configuration BSSAP_LE_Configurations; |
| 62 | |
| 63 | private 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 | |
| 81 | function 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 Welte | 843917e | 2023-04-15 02:54:34 +0800 | [diff] [blame] | 87 | var template (omit) integer rctx; |
| 88 | if (not ispresent(cfg.rctx)) { |
| 89 | rctx := omit; |
| 90 | } else { |
| 91 | rctx := cfg.rctx; |
| 92 | } |
| 93 | |
Harald Welte | a803b72 | 2020-08-21 15:42:26 +0200 | [diff] [blame] | 94 | /* create components */ |
Harald Welte | 7138913 | 2021-12-09 21:58:18 +0100 | [diff] [blame] | 95 | ba.vc_SCCP := SCCP_CT.create(id & "-SCCP") alive; |
Harald Welte | a803b72 | 2020-08-21 15:42:26 +0200 | [diff] [blame] | 96 | if (isvalue(ops)) { |
Harald Welte | 7138913 | 2021-12-09 21:58:18 +0100 | [diff] [blame] | 97 | ba.vc_BSSAP_LE := BSSAP_LE_Emulation_CT.create(id & "-BSSAP_LE") alive; |
Harald Welte | a803b72 | 2020-08-21 15:42:26 +0200 | [diff] [blame] | 98 | } else { |
| 99 | ba.vc_BSSAP_LE := null; |
| 100 | } |
Harald Welte | 7138913 | 2021-12-09 21:58:18 +0100 | [diff] [blame] | 101 | ba.vc_M3UA := M3UA_CT.create(id & "-M3UA") alive; |
Harald Welte | a803b72 | 2020-08-21 15:42:26 +0200 | [diff] [blame] | 102 | 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 Welte | 843917e | 2023-04-15 02:54:34 +0800 | [diff] [blame] | 105 | ba.vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr, rctx)); |
Harald Welte | a803b72 | 2020-08-21 15:42:26 +0200 | [diff] [blame] | 106 | |
| 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 | |
| 121 | function f_bssap_le_adapter_start(inout BSSAP_LE_Adapter ba) { |
| 122 | ba.vc_SCCP.start(SCCPStart(ba.sccp_pars)); |
| 123 | } |
| 124 | |
| 125 | function 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 | } |