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, |
| 59 | integer rctx |
| 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 | |
| 87 | /* create components */ |
Harald Welte | 7138913 | 2021-12-09 21:58:18 +0100 | [diff] [blame] | 88 | ba.vc_SCCP := SCCP_CT.create(id & "-SCCP") alive; |
Harald Welte | a803b72 | 2020-08-21 15:42:26 +0200 | [diff] [blame] | 89 | if (isvalue(ops)) { |
Harald Welte | 7138913 | 2021-12-09 21:58:18 +0100 | [diff] [blame] | 90 | 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] | 91 | } else { |
| 92 | ba.vc_BSSAP_LE := null; |
| 93 | } |
Harald Welte | 7138913 | 2021-12-09 21:58:18 +0100 | [diff] [blame] | 94 | ba.vc_M3UA := M3UA_CT.create(id & "-M3UA") alive; |
Harald Welte | a803b72 | 2020-08-21 15:42:26 +0200 | [diff] [blame] | 95 | 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 | |
| 114 | function f_bssap_le_adapter_start(inout BSSAP_LE_Adapter ba) { |
| 115 | ba.vc_SCCP.start(SCCPStart(ba.sccp_pars)); |
| 116 | } |
| 117 | |
| 118 | function 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 | } |