blob: 1a9fdb4252a4daff1eb1cd41843b1e1915e492e7 [file] [log] [blame]
Harald Welteae026692017-12-09 01:03:01 +01001module BSSAP_Adapter {
Harald Welte28d943e2017-11-25 15:00:50 +01002
Harald Welteae026692017-12-09 01:03:01 +01003/* 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 Welte28d943e2017-11-25 15:00:50 +01007
Harald Welteae026692017-12-09 01:03:01 +01008import from General_Types all;
9import from Osmocom_Types all;
10
11import from M3UA_Types all;
12import from M3UA_Emulation all;
13import from MTP3asp_Types all;
14import from MTP3asp_PortType all;
Harald Welte28d943e2017-11-25 15:00:50 +010015
Harald Welte7ef51aa2018-04-16 19:16:01 +020016import from IPA_Emulation all;
17
Harald Welte28d943e2017-11-25 15:00:50 +010018import from SCCP_Types all;
19import from SCCPasp_Types all;
20import from SCCP_Emulation all;
21
Harald Welteae026692017-12-09 01:03:01 +010022import from SCTPasp_Types all;
23import from SCTPasp_PortType all;
Harald Welte28d943e2017-11-25 15:00:50 +010024
Harald Welteae026692017-12-09 01:03:01 +010025import from BSSAP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010026import from BSSMAP_Templates all;
Harald Welte624f9632017-12-16 19:26:04 +010027import from BSSMAP_Emulation all;
28
Harald Weltea4ca4462018-02-09 00:17:14 +010029type record BSSAP_Adapter {
Harald Welte28d943e2017-11-25 15:00:50 +010030 /* component references */
Harald Welte7ef51aa2018-04-16 19:16:01 +020031 M3UA_CT vc_M3UA, /* only in 3GPP AoIP */
32 IPA_Emulation_CT vc_IPA, /* only in SCCPliste */
Harald Weltea4ca4462018-02-09 00:17:14 +010033 SCCP_CT vc_SCCP,
Harald Welteae026692017-12-09 01:03:01 +010034
Harald Weltea4ca4462018-02-09 00:17:14 +010035 MSC_SCCP_MTP3_parameters sccp_pars,
36 SCCP_PAR_Address sccp_addr_own,
37 SCCP_PAR_Address sccp_addr_peer,
Harald Welte624f9632017-12-16 19:26:04 +010038
39 /* handler mode */
Harald Weltea4ca4462018-02-09 00:17:14 +010040 BSSMAP_Emulation_CT vc_BSSMAP
Harald Welte28d943e2017-11-25 15:00:50 +010041}
42
Harald Welte7ef51aa2018-04-16 19:16:01 +020043type enumerated BSSAP_Transport {
44 BSSAP_TRANSPORT_AoIP, /* 3GPP AoIP: SCCP over M3UA over SCTP */
45 BSSAP_TRANSPORT_SCCPlite_SERVER, /* SCCPlite: SCCP over IPA over TCP */
46 BSSAP_TRANSPORT_SCCPlite_CLIENT /* SCCPlite: SCCP over IPA over TCP */
47};
48
Harald Weltea4ca4462018-02-09 00:17:14 +010049type record BSSAP_Configuration {
Harald Welte7ef51aa2018-04-16 19:16:01 +020050 BSSAP_Transport transport,
Harald Weltea4ca4462018-02-09 00:17:14 +010051 charstring sccp_service_type,
52 SCTP_Association_Address sctp_addr,
53 integer own_pc,
54 integer own_ssn,
55 integer peer_pc,
56 integer peer_ssn,
Philipp Maier75932982018-03-27 14:52:35 +020057 octetstring sio,
58 integer rctx
Harald Weltea4ca4462018-02-09 00:17:14 +010059};
Harald Welte28d943e2017-11-25 15:00:50 +010060
Harald Welteae026692017-12-09 01:03:01 +010061/* construct a SCCP_PAR_Address with just PC + SSN and no GT */
Harald Weltea4ca4462018-02-09 00:17:14 +010062template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn, octetstring sio,
63 charstring sccp_srv_type) := {
Harald Welteae026692017-12-09 01:03:01 +010064 addressIndicator := {
65 pointCodeIndic := '1'B,
66 ssnIndicator := '1'B,
67 globalTitleIndic := '0000'B,
68 routingIndicator := '1'B
69 },
Harald Weltea4ca4462018-02-09 00:17:14 +010070 signPointCode := SCCP_SPC_int2bit(pc, sccp_srv_type, sio),
Harald Welteae026692017-12-09 01:03:01 +010071 subsystemNumber := ssn,
72 globalTitle := omit
73}
74
Harald Weltea4ca4462018-02-09 00:17:14 +010075private function init_pars(inout BSSAP_Adapter ba, in BSSAP_Configuration cfg) {
76 ba.sccp_pars := {
Harald Welteae026692017-12-09 01:03:01 +010077 sio := {
Harald Weltea4ca4462018-02-09 00:17:14 +010078 ni := substr(oct2bit(cfg.sio),0,2),
79 prio := substr(oct2bit(cfg.sio),2,2),
80 si := substr(oct2bit(cfg.sio),4,4)
Harald Welteae026692017-12-09 01:03:01 +010081 },
Harald Weltea4ca4462018-02-09 00:17:14 +010082 opc := cfg.own_pc,
83 dpc := cfg.peer_pc,
Harald Welteae026692017-12-09 01:03:01 +010084 sls := 0,
Harald Weltea4ca4462018-02-09 00:17:14 +010085 sccp_serviceType := cfg.sccp_service_type,
86 ssn := cfg.own_ssn
Harald Welteae026692017-12-09 01:03:01 +010087 };
Harald Weltea4ca4462018-02-09 00:17:14 +010088 ba.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(cfg.own_pc, cfg.own_ssn, cfg.sio, cfg.sccp_service_type));
89 ba.sccp_addr_peer := valueof(ts_SccpAddr_PC_SSN(cfg.peer_pc, cfg.peer_ssn, cfg.sio, cfg.sccp_service_type));
Harald Welteae026692017-12-09 01:03:01 +010090}
91
92
Harald Weltea4ca4462018-02-09 00:17:14 +010093function f_bssap_init(inout BSSAP_Adapter ba, in BSSAP_Configuration cfg, charstring id,
94 template BssmapOps ops) {
95 init_pars(ba, cfg);
96 ops.sccp_addr_local := ba.sccp_addr_own;
97 ops.sccp_addr_peer := ba.sccp_addr_peer;
Harald Welteae026692017-12-09 01:03:01 +010098
Harald Welte28d943e2017-11-25 15:00:50 +010099 /* create components */
Harald Weltea4ca4462018-02-09 00:17:14 +0100100 ba.vc_SCCP := SCCP_CT.create(id & "-SCCP");
Harald Welte67089ee2018-01-17 22:19:03 +0100101 if (isvalue(ops)) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100102 ba.vc_BSSMAP := BSSMAP_Emulation_CT.create(id & "-BSSMAP");
Harald Welte624f9632017-12-16 19:26:04 +0100103 }
Harald Welte7ef51aa2018-04-16 19:16:01 +0200104 select (cfg.transport) {
105 case (BSSAP_TRANSPORT_AoIP) {
106 ba.vc_M3UA := M3UA_CT.create(id & "-M3UA");
107 map(ba.vc_M3UA:SCTP_PORT, system:sctp);
108 /* connect MTP3 service provider (M3UA) to lower side of SCCP */
109 connect(ba.vc_M3UA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
110 ba.vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr, cfg.rctx));
111 }
112 case (BSSAP_TRANSPORT_SCCPlite_SERVER) {
113 ba.vc_IPA := IPA_Emulation_CT.create(id & "-IPA");
114 map(ba.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
115 /* connect MTP3 service provider (IPA) to lower side of SCCP */
116 connect(ba.vc_IPA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
117 ba.vc_IPA.start(IPA_Emulation.main_server(cfg.sctp_addr.local_ip_addr,
118 cfg.sctp_addr.local_sctp_port));
119 }
120 case (BSSAP_TRANSPORT_SCCPlite_CLIENT) {
121 ba.vc_IPA := IPA_Emulation_CT.create(id & "-IPA");
122 map(ba.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
123 /* connect MTP3 service provider (IPA) to lower side of SCCP */
124 connect(ba.vc_IPA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
125 ba.vc_IPA.start(IPA_Emulation.main_client(cfg.sctp_addr.remote_ip_addr,
126 cfg.sctp_addr.remote_sctp_port,
127 cfg.sctp_addr.local_ip_addr,
128 cfg.sctp_addr.local_sctp_port));
129 }
130 case else {
131 setverdict(fail, "Unsuppored BSSAP_Transport");
132 self.stop;
133 }
134 }
Harald Welte28d943e2017-11-25 15:00:50 +0100135
Harald Weltea4ca4462018-02-09 00:17:14 +0100136 ba.vc_SCCP.start(SCCPStart(ba.sccp_pars));
Harald Welteb0ec4ee2018-01-21 13:53:17 +0100137
Harald Welte67089ee2018-01-17 22:19:03 +0100138 if (isvalue(ops)) {
Harald Welteb0ec4ee2018-01-21 13:53:17 +0100139 timer T := 5.0;
140 T.start;
Harald Weltea4ca4462018-02-09 00:17:14 +0100141 //T.timeout;
142 log("Connecting BSSMAP Emulation to SCCP_SP_PORT and starting emulation");
Harald Welteb0ec4ee2018-01-21 13:53:17 +0100143 /* connect BSSNAP component to upposer side of SCCP */
Harald Weltea4ca4462018-02-09 00:17:14 +0100144 connect(ba.vc_BSSMAP:BSSAP, ba.vc_SCCP:SCCP_SP_PORT);
Harald Welteb0ec4ee2018-01-21 13:53:17 +0100145 /* start the BSSMAP emulation */
Harald Weltea4ca4462018-02-09 00:17:14 +0100146 ba.vc_BSSMAP.start(BSSMAP_Emulation.main(valueof(ops), ""));
Harald Welteae026692017-12-09 01:03:01 +0100147 }
148}
149
150
Harald Welte28d943e2017-11-25 15:00:50 +0100151}