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 | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 27 | type component BSSAP_Adapter_CT { |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 28 | /* component references */ |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 29 | var M3UA_CT vc_M3UA; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 30 | var SCCP_CT vc_SCCP; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 31 | /* test port to SCCP emulation */ |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 32 | port BSSAP_CODEC_PT BSSAP; |
| 33 | |
| 34 | var octetstring g_sio; |
| 35 | var MSC_SCCP_MTP3_parameters g_sccp_pars; |
| 36 | var SCCP_PAR_Address g_sccp_addr_own, g_sccp_addr_peer; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 37 | |
| 38 | /* handler mode */ |
| 39 | var BSSMAP_Emulation_CT vc_BSSMAP; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | modulepar { |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 43 | charstring mp_sccp_service_type := "mtp3_itu"; |
| 44 | |
| 45 | SCTP_Association_Address mp_sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" }; |
| 46 | integer mp_own_pc := 185; /* 0.23.1 */ |
| 47 | integer mp_own_ssn := 254; |
| 48 | |
| 49 | integer mp_peer_pc := 187; |
| 50 | integer mp_peer_ssn := 254; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 53 | /* construct a SCCP_PAR_Address with just PC + SSN and no GT */ |
| 54 | template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn) := { |
| 55 | addressIndicator := { |
| 56 | pointCodeIndic := '1'B, |
| 57 | ssnIndicator := '1'B, |
| 58 | globalTitleIndic := '0000'B, |
| 59 | routingIndicator := '1'B |
| 60 | }, |
| 61 | signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, '83'O), |
| 62 | //signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, g_sio), |
| 63 | subsystemNumber := ssn, |
| 64 | globalTitle := omit |
| 65 | } |
| 66 | |
| 67 | private function init_pars() runs on BSSAP_Adapter_CT { |
| 68 | g_sio := '83'O; |
| 69 | g_sccp_pars := { |
| 70 | sio := { |
| 71 | ni := substr(oct2bit(g_sio),0,2), |
| 72 | prio := substr(oct2bit(g_sio),2,2), |
| 73 | si := substr(oct2bit(g_sio),4,4) |
| 74 | }, |
| 75 | opc := mp_own_pc, |
| 76 | dpc := mp_peer_pc, |
| 77 | sls := 0, |
| 78 | sccp_serviceType := mp_sccp_service_type, |
| 79 | ssn := mp_own_ssn |
| 80 | }; |
| 81 | g_sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(mp_own_pc, mp_own_ssn)); |
| 82 | g_sccp_addr_peer := valueof(ts_SccpAddr_PC_SSN(mp_peer_pc, mp_peer_ssn)); |
| 83 | } |
| 84 | |
| 85 | |
Harald Welte | 67089ee | 2018-01-17 22:19:03 +0100 | [diff] [blame] | 86 | function f_bssap_init(charstring id, template BssmapOps ops) runs on BSSAP_Adapter_CT |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 87 | { |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 88 | init_pars(); |
| 89 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 90 | /* create components */ |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 91 | vc_M3UA := M3UA_CT.create(id & "-M3UA"); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 92 | vc_SCCP := SCCP_CT.create(id & "-SCCP"); |
Harald Welte | 67089ee | 2018-01-17 22:19:03 +0100 | [diff] [blame] | 93 | if (isvalue(ops)) { |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 94 | vc_BSSMAP := BSSMAP_Emulation_CT.create(id & "-BSSMAP"); |
| 95 | } |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 96 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 97 | map(vc_M3UA:SCTP_PORT, system:sctp); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 98 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 99 | /* connect MTP3 service provider (M3UA) to lower side of SCCP */ |
| 100 | connect(vc_M3UA:MTP3_SP_PORT, vc_SCCP:MTP3_SCCP_PORT); |
Harald Welte | b0ec4ee | 2018-01-21 13:53:17 +0100 | [diff] [blame] | 101 | /* connect ourselves to upper side of SCCP */ |
| 102 | connect(self:BSSAP, vc_SCCP:SCCP_SP_PORT); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 103 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 104 | vc_M3UA.start(f_M3UA_Emulation(mp_sctp_addr)); |
| 105 | vc_SCCP.start(SCCPStart(g_sccp_pars)); |
Harald Welte | b0ec4ee | 2018-01-21 13:53:17 +0100 | [diff] [blame] | 106 | |
Harald Welte | 67089ee | 2018-01-17 22:19:03 +0100 | [diff] [blame] | 107 | if (isvalue(ops)) { |
Harald Welte | b0ec4ee | 2018-01-21 13:53:17 +0100 | [diff] [blame] | 108 | timer T := 5.0; |
| 109 | T.start; |
| 110 | T.timeout; |
| 111 | /* Perform reset procedure */ |
| 112 | f_bssap_reset(); |
| 113 | /* disconect ourselves */ |
| 114 | disconnect(self:BSSAP, vc_SCCP:SCCP_SP_PORT); |
| 115 | /* connect BSSNAP component to upposer side of SCCP */ |
| 116 | connect(vc_BSSMAP:BSSAP, vc_SCCP:SCCP_SP_PORT); |
| 117 | /* start the BSSMAP emulation */ |
Harald Welte | 67089ee | 2018-01-17 22:19:03 +0100 | [diff] [blame] | 118 | vc_BSSMAP.start(BSSMAP_Emulation.main(valueof(ops), "")); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 119 | } |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 120 | } |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 121 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 122 | private altstep as_reset_ack() runs on BSSAP_Adapter_CT { |
| 123 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 124 | [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind { |
| 125 | log("Respoding to inbound RESET with RESET-ACK"); |
| 126 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress, |
| 127 | ts_BSSMAP_ResetAck)); |
Harald Welte | 8b20f7c | 2017-12-22 20:39:20 +0100 | [diff] [blame] | 128 | repeat; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame] | 132 | |
| 133 | function f_bssap_wait_for_reset() runs on BSSAP_Adapter_CT { |
| 134 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 135 | timer T := 20.0; |
| 136 | |
| 137 | T.start; |
| 138 | alt { |
| 139 | [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind { |
| 140 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress, |
| 141 | ts_BSSMAP_ResetAck)); |
| 142 | } |
| 143 | [] as_reset_ack(); |
| 144 | [] BSSAP.receive { |
| 145 | repeat; |
| 146 | } |
| 147 | [] T.timeout { |
| 148 | setverdict(fail); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | function f_bssap_reset() runs on BSSAP_Adapter_CT { |
| 154 | timer T := 5.0; |
| 155 | |
| 156 | BSSAP.send(ts_BSSAP_UNITDATA_req(g_sccp_addr_peer, g_sccp_addr_own, ts_BSSMAP_Reset(0))); |
| 157 | T.start; |
| 158 | alt { |
| 159 | [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_sccp_addr_own, g_sccp_addr_peer, tr_BSSMAP_ResetAck)) { |
| 160 | log("Received RESET-ACK in response to RESET, we're ready to go!"); |
| 161 | } |
| 162 | [] as_reset_ack(); |
| 163 | [] BSSAP.receive { repeat }; |
| 164 | [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 169 | } |