blob: e27783c3114b860748e4c8cec7d83f1fb4a48322 [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
16import from SCCP_Types all;
17import from SCCPasp_Types all;
18import from SCCP_Emulation all;
19
Harald Welteae026692017-12-09 01:03:01 +010020import from SCTPasp_Types all;
21import from SCTPasp_PortType all;
Harald Welte28d943e2017-11-25 15:00:50 +010022
Harald Welteae026692017-12-09 01:03:01 +010023import from BSSAP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010024import from BSSMAP_Templates all;
Harald Welte624f9632017-12-16 19:26:04 +010025import from BSSMAP_Emulation all;
26
Harald Weltea4ca4462018-02-09 00:17:14 +010027type record BSSAP_Adapter {
Harald Welte28d943e2017-11-25 15:00:50 +010028 /* component references */
Harald Weltea4ca4462018-02-09 00:17:14 +010029 M3UA_CT vc_M3UA,
30 SCCP_CT vc_SCCP,
Harald Welteae026692017-12-09 01:03:01 +010031
Harald Weltea4ca4462018-02-09 00:17:14 +010032 MSC_SCCP_MTP3_parameters sccp_pars,
33 SCCP_PAR_Address sccp_addr_own,
34 SCCP_PAR_Address sccp_addr_peer,
Harald Welte624f9632017-12-16 19:26:04 +010035
36 /* handler mode */
Harald Weltea4ca4462018-02-09 00:17:14 +010037 BSSMAP_Emulation_CT vc_BSSMAP
Harald Welte28d943e2017-11-25 15:00:50 +010038}
39
Harald Weltea4ca4462018-02-09 00:17:14 +010040type 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,
47 octetstring sio
48};
Harald Welte28d943e2017-11-25 15:00:50 +010049
Harald Welteae026692017-12-09 01:03:01 +010050/* construct a SCCP_PAR_Address with just PC + SSN and no GT */
Harald Weltea4ca4462018-02-09 00:17:14 +010051template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn, octetstring sio,
52 charstring sccp_srv_type) := {
Harald Welteae026692017-12-09 01:03:01 +010053 addressIndicator := {
54 pointCodeIndic := '1'B,
55 ssnIndicator := '1'B,
56 globalTitleIndic := '0000'B,
57 routingIndicator := '1'B
58 },
Harald Weltea4ca4462018-02-09 00:17:14 +010059 signPointCode := SCCP_SPC_int2bit(pc, sccp_srv_type, sio),
Harald Welteae026692017-12-09 01:03:01 +010060 subsystemNumber := ssn,
61 globalTitle := omit
62}
63
Harald Weltea4ca4462018-02-09 00:17:14 +010064private function init_pars(inout BSSAP_Adapter ba, in BSSAP_Configuration cfg) {
65 ba.sccp_pars := {
Harald Welteae026692017-12-09 01:03:01 +010066 sio := {
Harald Weltea4ca4462018-02-09 00:17:14 +010067 ni := substr(oct2bit(cfg.sio),0,2),
68 prio := substr(oct2bit(cfg.sio),2,2),
69 si := substr(oct2bit(cfg.sio),4,4)
Harald Welteae026692017-12-09 01:03:01 +010070 },
Harald Weltea4ca4462018-02-09 00:17:14 +010071 opc := cfg.own_pc,
72 dpc := cfg.peer_pc,
Harald Welteae026692017-12-09 01:03:01 +010073 sls := 0,
Harald Weltea4ca4462018-02-09 00:17:14 +010074 sccp_serviceType := cfg.sccp_service_type,
75 ssn := cfg.own_ssn
Harald Welteae026692017-12-09 01:03:01 +010076 };
Harald Weltea4ca4462018-02-09 00:17:14 +010077 ba.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(cfg.own_pc, cfg.own_ssn, cfg.sio, cfg.sccp_service_type));
78 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 +010079}
80
81
Harald Weltea4ca4462018-02-09 00:17:14 +010082function f_bssap_init(inout BSSAP_Adapter ba, in BSSAP_Configuration cfg, charstring id,
83 template BssmapOps ops) {
84 init_pars(ba, cfg);
85 ops.sccp_addr_local := ba.sccp_addr_own;
86 ops.sccp_addr_peer := ba.sccp_addr_peer;
Harald Welteae026692017-12-09 01:03:01 +010087
Harald Welte28d943e2017-11-25 15:00:50 +010088 /* create components */
Harald Weltea4ca4462018-02-09 00:17:14 +010089 ba.vc_M3UA := M3UA_CT.create(id & "-M3UA");
90 ba.vc_SCCP := SCCP_CT.create(id & "-SCCP");
Harald Welte67089ee2018-01-17 22:19:03 +010091 if (isvalue(ops)) {
Harald Weltea4ca4462018-02-09 00:17:14 +010092 ba.vc_BSSMAP := BSSMAP_Emulation_CT.create(id & "-BSSMAP");
Harald Welte624f9632017-12-16 19:26:04 +010093 }
Harald Welte28d943e2017-11-25 15:00:50 +010094
Harald Weltea4ca4462018-02-09 00:17:14 +010095 map(ba.vc_M3UA:SCTP_PORT, system:sctp);
Harald Welte28d943e2017-11-25 15:00:50 +010096
Harald Welteae026692017-12-09 01:03:01 +010097 /* connect MTP3 service provider (M3UA) to lower side of SCCP */
Harald Weltea4ca4462018-02-09 00:17:14 +010098 connect(ba.vc_M3UA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
Harald Welte28d943e2017-11-25 15:00:50 +010099
Harald Weltea4ca4462018-02-09 00:17:14 +0100100 ba.vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr));
101 ba.vc_SCCP.start(SCCPStart(ba.sccp_pars));
Harald Welteb0ec4ee2018-01-21 13:53:17 +0100102
Harald Welte67089ee2018-01-17 22:19:03 +0100103 if (isvalue(ops)) {
Harald Welteb0ec4ee2018-01-21 13:53:17 +0100104 timer T := 5.0;
105 T.start;
Harald Weltea4ca4462018-02-09 00:17:14 +0100106 //T.timeout;
107 log("Connecting BSSMAP Emulation to SCCP_SP_PORT and starting emulation");
Harald Welteb0ec4ee2018-01-21 13:53:17 +0100108 /* connect BSSNAP component to upposer side of SCCP */
Harald Weltea4ca4462018-02-09 00:17:14 +0100109 connect(ba.vc_BSSMAP:BSSAP, ba.vc_SCCP:SCCP_SP_PORT);
Harald Welteb0ec4ee2018-01-21 13:53:17 +0100110 /* start the BSSMAP emulation */
Harald Weltea4ca4462018-02-09 00:17:14 +0100111 ba.vc_BSSMAP.start(BSSMAP_Emulation.main(valueof(ops), ""));
Harald Welteae026692017-12-09 01:03:01 +0100112 }
113}
114
115
Harald Welte28d943e2017-11-25 15:00:50 +0100116}