Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 1 | module BSSAP_Adapter { |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 2 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 3 | /* This module implements a 'dumb' BSSAP adapter. It creates the M3UA and SCCP components and stacks a BSSAP |
| 4 | * codec port on top. As a result, it provides the ability to transceive SCCP-User-SAP primitives with |
| 5 | * deoded BSSAP payload. Use this if you want to have full control about what you transmit or receive, |
| 6 | * without any automatisms in place. Allows you to refuse connections or other abnormal behavior. */ |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 7 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 8 | import from General_Types all; |
| 9 | import from Osmocom_Types all; |
| 10 | |
| 11 | import from M3UA_Types all; |
| 12 | import from M3UA_Emulation all; |
| 13 | import from MTP3asp_Types all; |
| 14 | import from MTP3asp_PortType all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 15 | |
| 16 | import from SCCP_Types all; |
| 17 | import from SCCPasp_Types all; |
| 18 | import from SCCP_Emulation all; |
| 19 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 20 | import from SCTPasp_Types all; |
| 21 | import from SCTPasp_PortType all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 22 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 23 | import from BSSAP_CodecPort all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 24 | import from BSSMAP_Templates all; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 25 | import from BSSMAP_Emulation all; |
| 26 | |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 27 | type record BSSAP_Adapter { |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 28 | /* component references */ |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 29 | M3UA_CT vc_M3UA, |
| 30 | SCCP_CT vc_SCCP, |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 31 | |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 32 | MSC_SCCP_MTP3_parameters sccp_pars, |
| 33 | SCCP_PAR_Address sccp_addr_own, |
| 34 | SCCP_PAR_Address sccp_addr_peer, |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 35 | |
| 36 | /* handler mode */ |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 37 | BSSMAP_Emulation_CT vc_BSSMAP |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 38 | } |
| 39 | |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 40 | type record BSSAP_Configuration { |
| 41 | charstring sccp_service_type, |
| 42 | SCTP_Association_Address sctp_addr, |
| 43 | integer own_pc, |
| 44 | integer own_ssn, |
| 45 | integer peer_pc, |
| 46 | integer peer_ssn, |
Philipp Maier | 7593298 | 2018-03-27 14:52:35 +0200 | [diff] [blame] | 47 | octetstring sio, |
| 48 | integer rctx |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 49 | }; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 50 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 51 | /* construct a SCCP_PAR_Address with just PC + SSN and no GT */ |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 52 | template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn, octetstring sio, |
| 53 | charstring sccp_srv_type) := { |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 54 | addressIndicator := { |
| 55 | pointCodeIndic := '1'B, |
| 56 | ssnIndicator := '1'B, |
| 57 | globalTitleIndic := '0000'B, |
| 58 | routingIndicator := '1'B |
| 59 | }, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 60 | signPointCode := SCCP_SPC_int2bit(pc, sccp_srv_type, sio), |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 61 | subsystemNumber := ssn, |
| 62 | globalTitle := omit |
| 63 | } |
| 64 | |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 65 | private function init_pars(inout BSSAP_Adapter ba, in BSSAP_Configuration cfg) { |
| 66 | ba.sccp_pars := { |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 67 | sio := { |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 68 | ni := substr(oct2bit(cfg.sio),0,2), |
| 69 | prio := substr(oct2bit(cfg.sio),2,2), |
| 70 | si := substr(oct2bit(cfg.sio),4,4) |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 71 | }, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 72 | opc := cfg.own_pc, |
| 73 | dpc := cfg.peer_pc, |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 74 | sls := 0, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 75 | sccp_serviceType := cfg.sccp_service_type, |
| 76 | ssn := cfg.own_ssn |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 77 | }; |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 78 | ba.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(cfg.own_pc, cfg.own_ssn, cfg.sio, cfg.sccp_service_type)); |
| 79 | ba.sccp_addr_peer := valueof(ts_SccpAddr_PC_SSN(cfg.peer_pc, cfg.peer_ssn, cfg.sio, cfg.sccp_service_type)); |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 83 | function f_bssap_init(inout BSSAP_Adapter ba, in BSSAP_Configuration cfg, charstring id, |
| 84 | template BssmapOps ops) { |
| 85 | init_pars(ba, cfg); |
| 86 | ops.sccp_addr_local := ba.sccp_addr_own; |
| 87 | ops.sccp_addr_peer := ba.sccp_addr_peer; |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 88 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 89 | /* create components */ |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 90 | ba.vc_M3UA := M3UA_CT.create(id & "-M3UA"); |
| 91 | ba.vc_SCCP := SCCP_CT.create(id & "-SCCP"); |
Harald Welte | 67089ee | 2018-01-17 22:19:03 +0100 | [diff] [blame] | 92 | if (isvalue(ops)) { |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 93 | ba.vc_BSSMAP := BSSMAP_Emulation_CT.create(id & "-BSSMAP"); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 94 | } |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 95 | |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 96 | map(ba.vc_M3UA:SCTP_PORT, system:sctp); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 97 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 98 | /* connect MTP3 service provider (M3UA) to lower side of SCCP */ |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 99 | connect(ba.vc_M3UA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 100 | |
Philipp Maier | 7593298 | 2018-03-27 14:52:35 +0200 | [diff] [blame] | 101 | ba.vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr, cfg.rctx)); |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 102 | ba.vc_SCCP.start(SCCPStart(ba.sccp_pars)); |
Harald Welte | b0ec4ee | 2018-01-21 13:53:17 +0100 | [diff] [blame] | 103 | |
Harald Welte | 67089ee | 2018-01-17 22:19:03 +0100 | [diff] [blame] | 104 | if (isvalue(ops)) { |
Harald Welte | b0ec4ee | 2018-01-21 13:53:17 +0100 | [diff] [blame] | 105 | timer T := 5.0; |
| 106 | T.start; |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 107 | //T.timeout; |
| 108 | log("Connecting BSSMAP Emulation to SCCP_SP_PORT and starting emulation"); |
Harald Welte | b0ec4ee | 2018-01-21 13:53:17 +0100 | [diff] [blame] | 109 | /* connect BSSNAP component to upposer side of SCCP */ |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 110 | connect(ba.vc_BSSMAP:BSSAP, ba.vc_SCCP:SCCP_SP_PORT); |
Harald Welte | b0ec4ee | 2018-01-21 13:53:17 +0100 | [diff] [blame] | 111 | /* start the BSSMAP emulation */ |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 112 | ba.vc_BSSMAP.start(BSSMAP_Emulation.main(valueof(ops), "")); |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 117 | } |