Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 1 | module IPA_Emulation { |
| 2 | |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 3 | /* This module implements the IPA multiplex protocol on top of TCP, using the IPL4asp |
| 4 | * test-port as provider. It implements both client and server roles, as well was the CCM |
Pau Espin Pedrol | 76ba541 | 2019-06-10 11:00:33 +0200 | [diff] [blame] | 5 | * handshake for establishing the identity of the client to the server. |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 6 | * |
| 7 | * It already knows certain well-known sub-protocols such as A-bis RSL, MGCP and SCCP and |
| 8 | * GSUP. IT hence transcodes messages so the user can work with abstract data types rather |
| 9 | * than binary messages. It handles multiple packets inside one TCP segment. |
| 10 | * |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 11 | * (C) 2017-2019 by Harald Welte <laforge@gnumonks.org> |
| 12 | * contributions by sysmocom - s.f.m.c. GmbH |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 13 | * All rights reserved. |
| 14 | * |
| 15 | * Released under the terms of GNU General Public License, Version 2 or |
| 16 | * (at your option) any later version. |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 17 | * |
| 18 | * SPDX-License-Identifier: GPL-2.0-or-later |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 19 | */ |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 20 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 21 | import from IPA_Types all; |
| 22 | import from IPA_CodecPort all; |
| 23 | import from IPA_CodecPort_CtrlFunct all; |
| 24 | import from IPL4asp_Types all; |
Harald Welte | 1218883 | 2017-11-29 11:47:13 +0100 | [diff] [blame] | 25 | import from IPL4asp_PortType all; |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 26 | import from Socket_API_Definitions all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 27 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 28 | #ifdef IPA_EMULATION_SCCP |
| 29 | import from MTP3asp_Types all; |
| 30 | import from MTP3asp_PortType all; |
| 31 | #endif |
| 32 | |
| 33 | #ifdef IPA_EMULATION_RSL |
| 34 | import from RSL_Types all; |
| 35 | #endif |
| 36 | |
Harald Welte | c682666 | 2019-02-06 22:26:46 +0100 | [diff] [blame] | 37 | #ifdef IPA_EMULATION_OML |
| 38 | import from AbisOML_Types all; |
| 39 | #endif |
| 40 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 41 | #ifdef IPA_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 42 | import from MGCP_Types all; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 43 | #endif |
| 44 | |
| 45 | #ifdef IPA_EMULATION_GSUP |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 46 | import from GSUP_Types all; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 47 | #endif |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 48 | |
Harald Welte | 7460a72 | 2018-10-10 12:28:27 +0200 | [diff] [blame] | 49 | #ifdef IPA_EMULATION_RSPRO |
| 50 | import from RSPRO all; |
| 51 | import from RSPRO_Types all; |
| 52 | #endif |
| 53 | |
| 54 | |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 55 | import from Osmocom_CTRL_Types all; |
| 56 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 57 | modulepar { |
Harald Welte | 92632e1 | 2017-11-25 02:31:20 +0100 | [diff] [blame] | 58 | /* Use Osmocom extended IPA mux header */ |
| 59 | boolean mp_ipa_mgcp_uses_osmo_ext := true; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 60 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 61 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 62 | type enumerated IpaMode { |
| 63 | IPA_MODE_CLIENT, |
| 64 | IPA_MODE_SERVER |
| 65 | } |
| 66 | |
Neels Hofmeyr | 3bf31d2 | 2018-08-24 14:44:32 +0200 | [diff] [blame] | 67 | type enumerated IpaInitBehavior { |
| 68 | IPA_INIT_SEND_IPA_ID_GET, |
| 69 | IPA_INIT_SEND_IPA_ID_ACK |
| 70 | } |
| 71 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 72 | type record ASP_IPA_Unitdata { |
| 73 | IpaStreamId streamId, |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 74 | IpaExtStreamId streamIdExt optional, |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 75 | octetstring payload |
| 76 | } |
| 77 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 78 | type enumerated ASP_IPA_EventUpDown { |
| 79 | ASP_IPA_EVENT_DOWN, |
| 80 | ASP_IPA_EVENT_UP, |
| 81 | ASP_IPA_EVENT_ID_ACK |
| 82 | } |
| 83 | |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 84 | /* an event indicating us whether or not a connection is physically up or down, |
| 85 | * and whether we have received an ID_ACK */ |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 86 | type union ASP_IPA_Event { |
| 87 | ASP_IPA_EventUpDown up_down |
| 88 | } |
| 89 | |
| 90 | template ASP_IPA_Event t_ASP_IPA_EVT_UD(ASP_IPA_EventUpDown ud) := { |
| 91 | up_down := ud |
| 92 | } |
| 93 | |
Harald Welte | 1dd8f37 | 2017-11-25 02:25:27 +0100 | [diff] [blame] | 94 | template ASP_IPA_Unitdata t_ASP_IPA_UD(IpaStreamId sid, octetstring pl, |
| 95 | template IpaExtStreamId esid := omit) := { |
| 96 | streamId := sid, |
| 97 | streamIdExt := esid, |
| 98 | payload := pl |
| 99 | } |
| 100 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 101 | #ifdef IPA_EMULATION_RSL |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 102 | /* like ASP_IPA_Unitdata, but with RSL_Message abstract type instead of octetstring */ |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 103 | type record ASP_RSL_Unitdata { |
| 104 | IpaStreamId streamId, |
| 105 | RSL_Message rsl |
| 106 | }; |
| 107 | |
Harald Welte | 7ae019e | 2017-12-09 00:54:15 +0100 | [diff] [blame] | 108 | template ASP_RSL_Unitdata ts_ASP_RSL_UD(IpaStreamId sid, template RSL_Message rsl) := { |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 109 | streamId := sid, |
| 110 | rsl := valueof(rsl) |
| 111 | } |
| 112 | |
Harald Welte | 7ae019e | 2017-12-09 00:54:15 +0100 | [diff] [blame] | 113 | template ASP_RSL_Unitdata tr_ASP_RSL_UD(IpaStreamId sid, template RSL_Message rsl) := { |
| 114 | streamId := sid, |
| 115 | rsl := rsl |
| 116 | } |
| 117 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 118 | template IpaStreamId t_IpaSidRSL := ( IPAC_PROTO_RSL_TRX0, IPAC_PROTO_RSL_TRX1, |
| 119 | IPAC_PROTO_RSL_TRX2, IPAC_PROTO_RSL_TRX3 ); |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 120 | #endif |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 121 | |
Harald Welte | c682666 | 2019-02-06 22:26:46 +0100 | [diff] [blame] | 122 | |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 123 | /* Client port for general IPA messages, not further decoded */ |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 124 | type port IPA_SP_PT message { |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 125 | inout ASP_IPA_Unitdata, ASP_IPA_Event; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 126 | } with { extension "internal" } |
| 127 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 128 | #ifdef IPA_EMULATION_MGCP |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 129 | /* Client port for MGCP inside IPA */ |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 130 | type port IPA_MGCP_PT message { |
| 131 | inout MgcpCommand, MgcpResponse; |
| 132 | } with { extension "internal" } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 133 | #endif |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 134 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 135 | #ifdef IPA_EMULATION_RSL |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 136 | /* Client port for A-bis RSL inside IPA */ |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 137 | type port IPA_RSL_PT message { |
| 138 | inout ASP_RSL_Unitdata, ASP_IPA_Event; |
| 139 | } with { extension "internal" } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 140 | #endif |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 141 | |
Harald Welte | c682666 | 2019-02-06 22:26:46 +0100 | [diff] [blame] | 142 | #ifdef IPA_EMULATION_OML |
| 143 | /* Client port for A-bis OML inside IPA */ |
| 144 | type port IPA_OML_PT message { |
| 145 | inout OML_PDU, octetstring, ASP_IPA_Event; |
| 146 | } with { extension "internal" } |
| 147 | #endif |
| 148 | |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 149 | /* Client port for CTRL inside IPA */ |
| 150 | type port IPA_CTRL_PT message { |
| 151 | inout CtrlMessage, ASP_IPA_Event; |
| 152 | } with { extension "internal" } |
| 153 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 154 | #ifdef IPA_EMULATION_GSUP |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 155 | /* Client port for CTRL inside IPA */ |
| 156 | type port IPA_GSUP_PT message { |
| 157 | inout GSUP_PDU, ASP_IPA_Event; |
| 158 | } with { extension "internal" } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 159 | #endif |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 160 | |
Harald Welte | 7460a72 | 2018-10-10 12:28:27 +0200 | [diff] [blame] | 161 | #ifdef IPA_EMULATION_RSPRO |
| 162 | type port IPA_RSPRO_PT message { |
| 163 | inout RsproPDU, ASP_IPA_Event; |
| 164 | } with { extension "internal" } |
| 165 | #endif |
| 166 | |
| 167 | |
| 168 | |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 169 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 170 | type component IPA_Emulation_CT { |
| 171 | /* down-facing port to IPA codec port */ |
| 172 | port IPA_CODEC_PT IPA_PORT; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 173 | #ifdef IPA_EMULATION_SCCP |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 174 | /* up-facing port to SCCP */ |
| 175 | port MTP3asp_SP_PT MTP3_SP_PORT; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 176 | #endif |
| 177 | #ifdef IPA_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 178 | /* up-facing port for MGCP */ |
| 179 | port IPA_MGCP_PT IPA_MGCP_PORT; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 180 | #endif |
| 181 | #ifdef IPA_EMULATION_RSL |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 182 | /* up-facing port for RSL */ |
| 183 | port IPA_RSL_PT IPA_RSL_PORT; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 184 | #endif |
Harald Welte | c682666 | 2019-02-06 22:26:46 +0100 | [diff] [blame] | 185 | #ifdef IPA_EMULATION_OML |
| 186 | /* up-facing port for OML */ |
| 187 | port IPA_OML_PT IPA_OML_PORT; |
| 188 | #endif |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 189 | /* up-facing port for CTRL */ |
| 190 | port IPA_CTRL_PT IPA_CTRL_PORT; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 191 | #ifdef IPA_EMULATION_GSUP |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 192 | /* up-facing port for GSUP */ |
| 193 | port IPA_GSUP_PT IPA_GSUP_PORT; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 194 | #endif |
Harald Welte | 7460a72 | 2018-10-10 12:28:27 +0200 | [diff] [blame] | 195 | #ifdef IPA_EMULATION_RSPRO |
| 196 | /* up-facing port for RSPRO */ |
| 197 | port IPA_RSPRO_PT IPA_RSPRO_PORT; |
| 198 | #endif |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 199 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 200 | /* up-facing port for other streams */ |
| 201 | port IPA_SP_PT IPA_SP_PORT; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 202 | |
| 203 | var boolean g_initialized := false; |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 204 | var IPL4asp_Types.ConnectionId g_ipa_conn_id := -1; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 205 | /* Are we a BSC/MGW (truel) or MSC (false) */ |
| 206 | var boolean g_is_bsc_mgw; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 207 | |
| 208 | var IpaMode g_mode; |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 209 | var boolean g_ccm_enabled; |
Neels Hofmeyr | 3bf31d2 | 2018-08-24 14:44:32 +0200 | [diff] [blame] | 210 | var IpaInitBehavior g_init_behavior; |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 211 | var IPA_CCM_Parameters g_ccm_pars := c_IPA_default_ccm_pars; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 212 | } |
| 213 | |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 214 | type record IPA_CCM_Parameters { |
| 215 | charstring ser_nr optional, |
| 216 | charstring name optional, |
| 217 | charstring location1 optional, |
| 218 | charstring location2 optional, |
| 219 | charstring equip_version optional, |
| 220 | charstring sw_version optional, |
| 221 | charstring ip_addr optional, |
| 222 | charstring mac_addr optional, |
| 223 | charstring unit_id optional, |
| 224 | charstring osmo_rand optional |
| 225 | } |
| 226 | |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 227 | const IPA_CCM_Parameters c_IPA_default_ccm_pars := { |
| 228 | ser_nr := "", |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 229 | name := "mahlzeit", |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 230 | location1 := "", |
| 231 | location2 := "", |
| 232 | equip_version := "", |
| 233 | sw_version := "", |
| 234 | ip_addr := "", |
| 235 | mac_addr := "", |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 236 | unit_id := "0/1/2", |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 237 | osmo_rand := "" |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 238 | }; |
| 239 | |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 240 | /* Function to use to connect as client to a remote IPA Server */ |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 241 | function f_connect(charstring remote_host, IPL4asp_Types.PortNumber remote_port, |
| 242 | charstring local_host, IPL4asp_Types.PortNumber local_port, |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 243 | IPA_CCM_Parameters ccm_pars := c_IPA_default_ccm_pars) runs on IPA_Emulation_CT { |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 244 | var IPL4asp_Types.Result res; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 245 | res := IPA_CodecPort_CtrlFunct.f_IPL4_connect(IPA_PORT, remote_host, remote_port, |
| 246 | local_host, local_port, 0, { tcp:={} }); |
Harald Welte | 9220f63 | 2018-05-23 20:27:02 +0200 | [diff] [blame] | 247 | if (not ispresent(res.connId)) { |
Stefan Sperling | 6a90be4 | 2018-08-31 15:05:39 +0200 | [diff] [blame] | 248 | setverdict(fail, "Could not connect IPA socket from ", local_host, " port ", local_port, |
| 249 | " to ", remote_host, " port ", remote_port, "; check your configuration"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 250 | mtc.stop; |
Harald Welte | 9220f63 | 2018-05-23 20:27:02 +0200 | [diff] [blame] | 251 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 252 | g_ipa_conn_id := res.connId; |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 253 | g_ccm_pars := ccm_pars; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 254 | g_is_bsc_mgw := true; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 255 | } |
| 256 | |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 257 | /* Function to use to bind to a local port as IPA server, accepting remote clients */ |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 258 | function f_bind(charstring local_host, IPL4asp_Types.PortNumber local_port, |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 259 | IPA_CCM_Parameters ccm_pars := c_IPA_default_ccm_pars) runs on IPA_Emulation_CT { |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 260 | var IPL4asp_Types.Result res; |
Pau Espin Pedrol | 76ba541 | 2019-06-10 11:00:33 +0200 | [diff] [blame] | 261 | res := IPA_CodecPort_CtrlFunct.f_IPL4_listen(IPA_PORT, |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 262 | local_host, local_port, { tcp:={} }); |
Harald Welte | 9220f63 | 2018-05-23 20:27:02 +0200 | [diff] [blame] | 263 | if (not ispresent(res.connId)) { |
Max | b7aae8b | 2019-03-11 15:22:02 +0100 | [diff] [blame] | 264 | setverdict(fail, "Could not listen IPA socket ", local_host, ":", local_port, ", check your configuration"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 265 | mtc.stop; |
Harald Welte | 9220f63 | 2018-05-23 20:27:02 +0200 | [diff] [blame] | 266 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 267 | g_ipa_conn_id := res.connId; |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 268 | g_ccm_pars := ccm_pars; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 269 | g_is_bsc_mgw := false; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 272 | #ifdef IPA_EMULATION_SCCP |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 273 | template ASP_MTP3_TRANSFERind ts_MTP3_XFER_ind(integer opc, octetstring data) := { |
| 274 | sio := { '10'B, '00'B, '0011'B }, |
| 275 | opc := opc, |
| 276 | dpc := 0, |
| 277 | sls := 0, |
| 278 | data := data |
| 279 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 280 | #endif |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 281 | |
| 282 | |
| 283 | private template IpaCcmRespPart t_IdRespPart(IpaCcmIdTag tag, charstring payload) := { |
| 284 | len := 0, /* overwritten by codec */ |
| 285 | tag := tag, |
Harald Welte | 95686e0 | 2018-08-02 15:05:43 +0200 | [diff] [blame] | 286 | data := char2oct(payload) & '00'O |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 287 | } |
| 288 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 289 | private function f_send_IPA_EVT(template ASP_IPA_Event evt) runs on IPA_Emulation_CT { |
Harald Welte | 2e32e43 | 2018-05-24 20:00:00 +0200 | [diff] [blame] | 290 | if (IPA_SP_PORT.checkstate("Connected")) { |
| 291 | IPA_SP_PORT.send(evt); |
| 292 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 293 | #ifdef IPA_EMULATION_RSL |
Harald Welte | 5819b55 | 2017-12-09 02:55:46 +0100 | [diff] [blame] | 294 | if (IPA_RSL_PORT.checkstate("Connected")) { |
| 295 | IPA_RSL_PORT.send(evt); |
| 296 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 297 | #endif |
Harald Welte | c682666 | 2019-02-06 22:26:46 +0100 | [diff] [blame] | 298 | #ifdef IPA_EMULATION_OML |
| 299 | if (IPA_OML_PORT.checkstate("Connected")) { |
| 300 | IPA_OML_PORT.send(evt); |
| 301 | } |
| 302 | #endif |
Harald Welte | 5819b55 | 2017-12-09 02:55:46 +0100 | [diff] [blame] | 303 | if (IPA_CTRL_PORT.checkstate("Connected")) { |
| 304 | IPA_CTRL_PORT.send(evt); |
| 305 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 306 | #ifdef IPA_EMULATION_GSUP |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 307 | if (IPA_GSUP_PORT.checkstate("Connected")) { |
| 308 | IPA_GSUP_PORT.send(evt); |
| 309 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 310 | #endif |
Harald Welte | 7460a72 | 2018-10-10 12:28:27 +0200 | [diff] [blame] | 311 | #ifdef IPA_EMULATION_RSPRO |
| 312 | if (IPA_RSPRO_PORT.checkstate("Connected")) { |
| 313 | IPA_RSPRO_PORT.send(evt); |
| 314 | } |
| 315 | #endif |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 316 | /* FIXME: to other ports */ |
| 317 | } |
| 318 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 319 | /* build IPA CCM ID RESP response from IPA CCM GET */ |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 320 | private function f_ccm_make_id_resp(PDU_IPA_CCM get) runs on IPA_Emulation_CT return PDU_IPA_CCM { |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 321 | var integer i; |
| 322 | var PDU_IPA_CCM resp := { |
| 323 | msg_type := IPAC_MSGT_ID_RESP, |
| 324 | u := { |
| 325 | resp := {} |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | for (i := 0; i < sizeof(get.u.get); i := i + 1) { |
| 330 | var IpaCcmIdTag tag := get.u.get[i].tag; |
| 331 | var charstring foo; |
| 332 | select (tag) { |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 333 | case (IPAC_IDTAG_SERNR) { |
| 334 | foo := g_ccm_pars.ser_nr; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 335 | } |
| 336 | case (IPAC_IDTAG_UNITNAME) { |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 337 | foo := g_ccm_pars.name; |
| 338 | } |
| 339 | case (IPAC_IDTAG_LOCATION1) { |
| 340 | foo := g_ccm_pars.location1; |
| 341 | } |
| 342 | case (IPAC_IDTAG_LOCATION2) { |
| 343 | foo := g_ccm_pars.location2; |
| 344 | } |
| 345 | case (IPAC_IDTAG_EQUIPVERS) { |
| 346 | foo := g_ccm_pars.equip_version; |
| 347 | } |
| 348 | case (IPAC_IDTAG_SWVERSION) { |
| 349 | foo := g_ccm_pars.sw_version; |
| 350 | } |
| 351 | case (IPAC_IDTAG_IPADDR) { |
| 352 | foo := g_ccm_pars.ip_addr; |
| 353 | } |
| 354 | case (IPAC_IDTAG_MACADDR) { |
| 355 | foo := g_ccm_pars.mac_addr; |
| 356 | } |
| 357 | case (IPAC_IDTAG_UNIT) { |
| 358 | foo := g_ccm_pars.unit_id; |
| 359 | } |
| 360 | case (IPAC_IDTAG_OSMO_RAND) { |
| 361 | foo := g_ccm_pars.osmo_rand; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 362 | } |
| 363 | case else { |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 364 | foo := "unknown"; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | resp.u.resp[sizeof(resp.u.resp)] := valueof(t_IdRespPart(tag, foo)); |
| 368 | } |
| 369 | |
| 370 | return resp; |
| 371 | } |
| 372 | |
| 373 | /* transmit IPA CCM message */ |
| 374 | private function f_ccm_tx(PDU_IPA_CCM ccm) runs on IPA_Emulation_CT { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 375 | var IPA_Send ipa_tx := valueof(t_IPA_Send(g_ipa_conn_id, IPAC_PROTO_CCM, enc_PDU_IPA_CCM(ccm))); |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 376 | log("CCM Tx:", ccm); |
| 377 | IPA_PORT.send(ipa_tx); |
| 378 | } |
| 379 | |
| 380 | template PDU_IPA_CCM ts_IPA_PONG := { |
| 381 | msg_type := IPAC_MSGT_PONG, |
| 382 | u := omit |
| 383 | } |
| 384 | |
| 385 | template PDU_IPA_CCM ts_IPA_ACK := { |
| 386 | msg_type := IPAC_MSGT_ID_ACK, |
| 387 | u := omit |
| 388 | } |
| 389 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 390 | template PDU_IPA_CCM ts_IPA_ID_GET := { |
| 391 | msg_type := IPAC_MSGT_ID_GET, |
| 392 | u := { |
| 393 | get := { |
| 394 | { 1, IPAC_IDTAG_UNITNAME } |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 399 | /* receive IPA CCM message */ |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 400 | private function f_ccm_rx_client(PDU_IPA_CCM ccm) runs on IPA_Emulation_CT { |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 401 | select (ccm.msg_type) { |
| 402 | case (IPAC_MSGT_PING) { |
| 403 | f_ccm_tx(valueof(ts_IPA_PONG)); |
| 404 | } |
| 405 | case (IPAC_MSGT_ID_ACK) { |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 406 | f_send_IPA_EVT(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_ID_ACK)); |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 407 | } |
| 408 | case (IPAC_MSGT_ID_GET) { |
| 409 | f_ccm_tx(f_ccm_make_id_resp(ccm)); |
| 410 | } |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 411 | case else { |
| 412 | log("Unknown/unsupported IPA CCM message type", ccm); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | private function f_ccm_rx_server(PDU_IPA_CCM ccm) runs on IPA_Emulation_CT { |
| 418 | select (ccm.msg_type) { |
| 419 | case (IPAC_MSGT_PING) { |
| 420 | f_ccm_tx(valueof(ts_IPA_PONG)); |
| 421 | } |
| 422 | case (IPAC_MSGT_ID_ACK) { |
| 423 | /* the IPA server should at some point receive an ID_ACK from the client, |
| 424 | * in case of RSL/OML from nanoBTS, this is actually the first message after |
| 425 | * the TCP connection is established. Other implementations may differ. |
| 426 | * We currently ignore it completely - but actually we should make sure that |
| 427 | * one ID_ACK is received by the server at some point */ |
Harald Welte | 2e32e43 | 2018-05-24 20:00:00 +0200 | [diff] [blame] | 428 | f_send_IPA_EVT(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_ID_ACK)); |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 429 | } |
Harald Welte | 3bc387f | 2018-02-21 12:18:46 +0100 | [diff] [blame] | 430 | case (IPAC_MSGT_ID_RESP) { |
| 431 | log("IPA ID RESP: ", ccm.u.resp); |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 432 | /* acknowledge any identity that the client may have sent */ |
| 433 | f_ccm_tx(valueof(ts_IPA_ACK)); |
Harald Welte | 3bc387f | 2018-02-21 12:18:46 +0100 | [diff] [blame] | 434 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 435 | case else { |
| 436 | log("Unknown/unsupported IPA CCM message type", ccm); |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 441 | private function f_to_asp(IPA_RecvFrom ipa_rx) return ASP_IPA_Unitdata { |
| 442 | var ASP_IPA_Unitdata ret := { |
| 443 | streamId := ipa_rx.streamId, |
Harald Welte | 2a8f847 | 2017-11-23 21:11:34 +0100 | [diff] [blame] | 444 | streamIdExt := ipa_rx.streamIdExt, |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 445 | payload := ipa_rx.msg |
| 446 | } |
| 447 | return ret; |
| 448 | } |
| 449 | |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 450 | private function f_from_asp(IPL4asp_Types.ConnectionId connId, ASP_IPA_Unitdata ipa_tx) return IPA_Send { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 451 | var IPA_Send ret := valueof(t_IPA_Send(connId, ipa_tx.streamId, ipa_tx.payload, |
| 452 | ipa_tx.streamIdExt)); |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 453 | return ret; |
| 454 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 455 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 456 | #ifdef IPA_EMULATION_RSL |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 457 | private function f_from_rsl(IPL4asp_Types.ConnectionId connId, ASP_RSL_Unitdata rsl_tx) return IPA_Send { |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 458 | var octetstring payload := enc_RSL_Message(rsl_tx.rsl); |
| 459 | var IPA_Send ret := valueof(t_IPA_Send(connId, rsl_tx.streamId, payload)); |
| 460 | return ret; |
| 461 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 462 | #endif |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 463 | |
Harald Welte | c682666 | 2019-02-06 22:26:46 +0100 | [diff] [blame] | 464 | #ifdef IPA_EMULATION_OML |
| 465 | private function f_from_oml(IPL4asp_Types.ConnectionId connId, OML_PDU oml_tx) return IPA_Send { |
| 466 | var octetstring payload := enc_OML_PDU(oml_tx); |
| 467 | var IPA_Send ret := valueof(t_IPA_Send(connId, IPAC_PROTO_OML, payload)); |
| 468 | return ret; |
| 469 | } |
| 470 | #endif |
| 471 | |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 472 | /* main function to use for a client-side IPA implementation */ |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 473 | function main_client(charstring remote_host, IPL4asp_Types.PortNumber remote_port, |
| 474 | charstring local_host, IPL4asp_Types.PortNumber local_port, |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 475 | IPA_CCM_Parameters ccm_pars := c_IPA_default_ccm_pars, |
| 476 | boolean ccm_enabled := true) runs on IPA_Emulation_CT { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 477 | g_mode := IPA_MODE_CLIENT; |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 478 | g_ccm_enabled := ccm_enabled; |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 479 | f_connect(remote_host, remote_port, local_host, local_port, ccm_pars); |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 480 | if (g_ccm_enabled) { |
| 481 | /* we're a client: Send ID_ACK immediately after connect */ |
| 482 | f_ccm_tx(valueof(ts_IPA_ACK)); |
| 483 | } |
Harald Welte | 03c0e56 | 2017-12-09 02:55:12 +0100 | [diff] [blame] | 484 | f_send_IPA_EVT(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_UP)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 485 | ScanEvents(); |
| 486 | } |
| 487 | |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 488 | /* main function to use for a server-side IPA implementation */ |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 489 | function main_server(charstring local_host, IPL4asp_Types.PortNumber local_port, |
Neels Hofmeyr | 3bf31d2 | 2018-08-24 14:44:32 +0200 | [diff] [blame] | 490 | boolean ccm_enabled := true, |
| 491 | IpaInitBehavior init_behavior := IPA_INIT_SEND_IPA_ID_GET) |
| 492 | runs on IPA_Emulation_CT { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 493 | g_mode := IPA_MODE_SERVER; |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 494 | g_ccm_enabled := ccm_enabled; |
Neels Hofmeyr | 3bf31d2 | 2018-08-24 14:44:32 +0200 | [diff] [blame] | 495 | g_init_behavior := init_behavior; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 496 | f_bind(local_host, local_port); |
| 497 | ScanEvents(); |
| 498 | } |
| 499 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 500 | private function f_ctrl_to_user(octetstring msg) runs on IPA_Emulation_CT { |
| 501 | var charstring msg_ch := oct2char(msg); |
| 502 | IPA_CTRL_PORT.send(dec_CtrlMessage(msg_ch)); |
| 503 | } |
| 504 | |
| 505 | #ifdef IPA_EMULATION_GSUP |
| 506 | private function f_gsup_to_user(octetstring msg) runs on IPA_Emulation_CT { |
| 507 | var GSUP_PDU gsup := dec_GSUP_PDU(msg); |
| 508 | f_gsup_postprocess_decoded(gsup); |
| 509 | IPA_GSUP_PORT.send(gsup); |
| 510 | } |
| 511 | #endif |
| 512 | |
Harald Welte | 7460a72 | 2018-10-10 12:28:27 +0200 | [diff] [blame] | 513 | #ifdef IPA_EMULATION_RSPRO |
| 514 | private function f_rspro_to_user(octetstring msg) runs on IPA_Emulation_CT { |
| 515 | var RsproPDU rspro := dec_RsproPDU(msg); |
| 516 | IPA_RSPRO_PORT.send(rspro); |
| 517 | } |
| 518 | #endif |
| 519 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 520 | #ifdef IPA_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 521 | private function f_mgcp_to_user(octetstring msg) runs on IPA_Emulation_CT { |
| 522 | var charstring msg_ch := oct2char(msg); |
| 523 | if (g_is_bsc_mgw) { |
| 524 | log("============"); |
| 525 | log(msg_ch); |
| 526 | IPA_MGCP_PORT.send(dec_MgcpCommand(msg_ch)); |
| 527 | } else { |
| 528 | IPA_MGCP_PORT.send(dec_MgcpResponse(msg_ch)); |
| 529 | } |
| 530 | } |
| 531 | |
Harald Welte | 92632e1 | 2017-11-25 02:31:20 +0100 | [diff] [blame] | 532 | private function f_mgcp_to_ud(octetstring payload) runs on IPA_Emulation_CT return ASP_IPA_Unitdata { |
| 533 | if (mp_ipa_mgcp_uses_osmo_ext) { |
| 534 | return valueof(t_ASP_IPA_UD(IPAC_PROTO_MGCP_OLD, payload)); |
| 535 | } else { |
| 536 | return valueof(t_ASP_IPA_UD(IPAC_PROTO_OSMO, payload, IPAC_PROTO_EXT_MGCP)); |
| 537 | } |
| 538 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 539 | #endif |
Harald Welte | 92632e1 | 2017-11-25 02:31:20 +0100 | [diff] [blame] | 540 | |
Harald Welte | bdb6370 | 2017-12-09 01:15:44 +0100 | [diff] [blame] | 541 | /* main loop function for both client and server. 'thread' of the component */ |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 542 | private function ScanEvents() runs on IPA_Emulation_CT { |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 543 | var IPA_RecvFrom ipa_rx; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 544 | var ASP_Event asp_evt; |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 545 | var Socket_API_Definitions.PortEvent port_evt; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 546 | var octetstring payload; |
| 547 | var CtrlMessage ctrl_msg; |
| 548 | var ASP_IPA_Unitdata ipa_ud; |
| 549 | #ifdef IPA_EMULATION_SCCP |
| 550 | var ASP_MTP3_TRANSFERreq mtp_req; |
| 551 | #endif |
| 552 | #ifdef IPA_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 553 | var MgcpCommand mgcp_cmd; |
| 554 | var MgcpResponse mgcp_rsp; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 555 | #endif |
| 556 | #ifdef IPA_EMULATION_GSUP |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 557 | var GSUP_PDU gsup_msg; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 558 | #endif |
| 559 | #ifdef IPA_EMULATION_RSL |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 560 | var ASP_RSL_Unitdata rsl; |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 561 | #endif |
Harald Welte | c682666 | 2019-02-06 22:26:46 +0100 | [diff] [blame] | 562 | #ifdef IPA_EMULATION_OML |
| 563 | var OML_PDU oml; |
| 564 | #endif |
Harald Welte | 7460a72 | 2018-10-10 12:28:27 +0200 | [diff] [blame] | 565 | #ifdef IPA_EMULATION_RSPRO |
| 566 | var RsproPDU rspro; |
| 567 | #endif |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 568 | |
Harald Welte | 3e6ad89 | 2017-12-12 14:39:46 +0100 | [diff] [blame] | 569 | /* Set function for dissecting the binary */ |
| 570 | var f_IPL4_getMsgLen vl_f := refers(f_IPL4_fixedMsgLen); |
| 571 | IPA_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(IPA_PORT, g_ipa_conn_id, vl_f, {0, 2, 3, 1, 0}); |
| 572 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 573 | while (true) { |
| 574 | alt { |
| 575 | /* Received IPA -> up into SCCP stack */ |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 576 | [g_ccm_enabled] IPA_PORT.receive(IPA_RecvFrom:{?,IPAC_PROTO_CCM,omit,?}) -> value ipa_rx { |
| 577 | var PDU_IPA_CCM ccm := dec_PDU_IPA_CCM(ipa_rx.msg); |
| 578 | log("CCM Rx:", ccm); |
| 579 | select (g_mode) { |
| 580 | case (IPA_MODE_CLIENT) { |
| 581 | f_ccm_rx_client(ccm); |
| 582 | } |
| 583 | case (IPA_MODE_SERVER) { |
| 584 | f_ccm_rx_server(ccm); |
| 585 | } |
| 586 | case else { |
| 587 | setverdict(fail, "Unknown mode"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 588 | mtc.stop; |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 589 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 590 | } |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 591 | } |
| 592 | [] IPA_PORT.receive(IPA_RecvFrom:?) -> value ipa_rx { |
| 593 | select (ipa_rx.streamId) { |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 594 | #ifdef IPA_EMULATION_SCCP |
| 595 | case (IPAC_PROTO_SCCP) { |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 596 | var ASP_MTP3_TRANSFERind mtp; |
| 597 | mtp := valueof(ts_MTP3_XFER_ind(0, ipa_rx.msg)); |
| 598 | MTP3_SP_PORT.send(mtp); |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 599 | } |
| 600 | #endif |
| 601 | #ifdef IPA_EMULATION_MGCP |
| 602 | case (IPAC_PROTO_MGCP_OLD) { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 603 | f_mgcp_to_user(ipa_rx.msg); |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 604 | } |
| 605 | #endif |
| 606 | #ifdef IPA_EMULATION_RSL |
| 607 | case (t_IpaSidRSL) { |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 608 | rsl := { |
| 609 | streamId := ipa_rx.streamId, |
| 610 | rsl := dec_RSL_Message(ipa_rx.msg) |
| 611 | }; |
| 612 | IPA_RSL_PORT.send(rsl); |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 613 | } |
| 614 | #endif |
Harald Welte | c682666 | 2019-02-06 22:26:46 +0100 | [diff] [blame] | 615 | #ifdef IPA_EMULATION_OML |
| 616 | case (IPAC_PROTO_OML) { |
| 617 | oml := dec_OML_PDU(ipa_rx.msg) |
| 618 | IPA_OML_PORT.send(oml); |
| 619 | } |
| 620 | #endif |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 621 | case (IPAC_PROTO_OSMO) { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 622 | select (ipa_rx.streamIdExt) { |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 623 | #ifdef IPA_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 624 | case (IPAC_PROTO_EXT_MGCP) { |
| 625 | f_mgcp_to_user(ipa_rx.msg); |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 626 | } |
| 627 | #endif |
| 628 | case (IPAC_PROTO_EXT_CTRL) { |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 629 | f_ctrl_to_user(ipa_rx.msg); |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 630 | } |
| 631 | #ifdef IPA_EMULATION_GSUP |
| 632 | case (IPAC_PROTO_EXT_GSUP) { |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 633 | f_gsup_to_user(ipa_rx.msg); |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 634 | } |
| 635 | #endif |
Harald Welte | 7460a72 | 2018-10-10 12:28:27 +0200 | [diff] [blame] | 636 | #ifdef IPA_EMULATION_RSPRO |
| 637 | case (IPAC_PROTO_EXT_RSPRO) { |
| 638 | f_rspro_to_user(ipa_rx.msg); |
| 639 | } |
| 640 | #endif |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 641 | case else { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 642 | IPA_SP_PORT.send(f_to_asp(ipa_rx)); |
| 643 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 644 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 645 | } |
| 646 | case else { |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 647 | IPA_SP_PORT.send(f_to_asp(ipa_rx)); |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 652 | /* server only */ |
| 653 | [] IPA_PORT.receive(ASP_Event:{connOpened:=?}) -> value asp_evt { |
| 654 | log("IPA: Connected"); |
| 655 | g_ipa_conn_id := asp_evt.connOpened.connId; |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 656 | f_send_IPA_EVT(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_UP)); |
Harald Welte | 2d86aff | 2018-04-17 11:23:04 +0200 | [diff] [blame] | 657 | if (g_mode == IPA_MODE_SERVER and g_ccm_enabled) { |
Neels Hofmeyr | 3bf31d2 | 2018-08-24 14:44:32 +0200 | [diff] [blame] | 658 | select (g_init_behavior) { |
| 659 | case (IPA_INIT_SEND_IPA_ID_GET) { |
| 660 | f_ccm_tx(valueof(ts_IPA_ID_GET)); |
| 661 | } |
| 662 | case (IPA_INIT_SEND_IPA_ID_ACK) { |
| 663 | f_ccm_tx(valueof(ts_IPA_ACK)); |
| 664 | } |
| 665 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
| 669 | [] IPA_PORT.receive(ASP_Event:{connClosed:=?}) -> value asp_evt { |
| 670 | log("IPA: Closed"); |
| 671 | g_ipa_conn_id := -1; |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 672 | f_send_IPA_EVT(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_DOWN)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 673 | self.stop; |
| 674 | } |
| 675 | |
Stefan Sperling | 830dc9d | 2018-02-12 21:08:28 +0100 | [diff] [blame] | 676 | [] IPA_PORT.receive(Socket_API_Definitions.PortEvent:{result:={errorCode:=ERROR_SOCKET, connId:=?, os_error_code:=?, os_error_text:=?}}) -> value port_evt { |
| 677 | log("PortEvent: ERROR_SOCKET: ", port_evt); |
| 678 | g_ipa_conn_id := -1; |
| 679 | f_send_IPA_EVT(t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_DOWN)); |
| 680 | self.stop; |
| 681 | } |
| 682 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 683 | #ifdef IPA_EMULATION_SCCP |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 684 | /* Received SCCP -> down into IPA */ |
| 685 | [] MTP3_SP_PORT.receive(ASP_MTP3_TRANSFERreq: ?) -> value mtp_req { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 686 | var IPA_Send ipa_tx := valueof(t_IPA_Send(g_ipa_conn_id, IPAC_PROTO_SCCP, |
| 687 | mtp_req.data)); |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 688 | IPA_PORT.send(ipa_tx); |
| 689 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 690 | #endif |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 691 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 692 | #ifdef IPA_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 693 | /* Received MGCP -> down into IPA */ |
| 694 | [] IPA_MGCP_PORT.receive(MgcpCommand:?) -> value mgcp_cmd { |
Harald Welte | 92632e1 | 2017-11-25 02:31:20 +0100 | [diff] [blame] | 695 | payload := char2oct(enc_MgcpCommand(mgcp_cmd)); |
| 696 | ipa_ud := f_mgcp_to_ud(payload); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 697 | IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud)); |
| 698 | } |
| 699 | [] IPA_MGCP_PORT.receive(MgcpResponse:?) -> value mgcp_rsp { |
Harald Welte | 1dd8f37 | 2017-11-25 02:25:27 +0100 | [diff] [blame] | 700 | payload := char2oct(enc_MgcpResponse(mgcp_rsp)); |
Harald Welte | 92632e1 | 2017-11-25 02:31:20 +0100 | [diff] [blame] | 701 | ipa_ud := f_mgcp_to_ud(payload); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 702 | IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud)); |
| 703 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 704 | #endif |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 705 | |
Harald Welte | a76c4bb | 2017-12-09 02:06:07 +0100 | [diff] [blame] | 706 | [] IPA_CTRL_PORT.receive(CtrlMessage:?) -> value ctrl_msg { |
| 707 | payload := char2oct(enc_CtrlMessage(ctrl_msg)); |
| 708 | ipa_ud := valueof(t_ASP_IPA_UD(IPAC_PROTO_OSMO, payload, IPAC_PROTO_EXT_CTRL)); |
| 709 | IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud)); |
| 710 | } |
| 711 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 712 | #ifdef IPA_EMULATION_GSUP |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 713 | [] IPA_GSUP_PORT.receive(GSUP_PDU:?) -> value gsup_msg { |
Harald Welte | 2f562b1 | 2018-01-24 20:52:38 +0100 | [diff] [blame] | 714 | f_gsup_preprocess_encoded(gsup_msg); |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 715 | payload := enc_GSUP_PDU(gsup_msg); |
| 716 | ipa_ud := valueof(t_ASP_IPA_UD(IPAC_PROTO_OSMO, payload, IPAC_PROTO_EXT_GSUP)); |
| 717 | IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud)); |
| 718 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 719 | #endif |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 720 | |
Harald Welte | 7460a72 | 2018-10-10 12:28:27 +0200 | [diff] [blame] | 721 | #ifdef IPA_EMULATION_RSPRO |
| 722 | [] IPA_RSPRO_PORT.receive(RsproPDU:?) -> value rspro { |
| 723 | payload := enc_RsproPDU(rspro); |
| 724 | ipa_ud := valueof(t_ASP_IPA_UD(IPAC_PROTO_OSMO, payload, IPAC_PROTO_EXT_RSPRO)); |
| 725 | IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud)); |
| 726 | } |
| 727 | #endif |
| 728 | |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 729 | #ifdef IPA_EMULATION_RSL |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 730 | /* Received RSL -> down into IPA */ |
| 731 | [] IPA_RSL_PORT.receive(ASP_RSL_Unitdata:?) -> value rsl { |
| 732 | IPA_PORT.send(f_from_rsl(g_ipa_conn_id, rsl)); |
| 733 | } |
Harald Welte | df27725 | 2018-02-20 15:49:30 +0100 | [diff] [blame] | 734 | #endif |
Harald Welte | c682666 | 2019-02-06 22:26:46 +0100 | [diff] [blame] | 735 | #ifdef IPA_EMULATION_OML |
| 736 | /* Received OML -> down into IPA */ |
| 737 | [] IPA_OML_PORT.receive(OML_PDU:?) -> value oml { |
| 738 | IPA_PORT.send(f_from_oml(g_ipa_conn_id, oml)); |
| 739 | } |
| 740 | [] IPA_OML_PORT.receive(octetstring:?) -> value payload { |
| 741 | IPA_PORT.send(t_IPA_Send(g_ipa_conn_id, IPAC_PROTO_OML, payload)); |
| 742 | } |
| 743 | #endif |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 744 | /* Received MISC (OML/CTRL) -> down into IPA */ |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 745 | [] IPA_SP_PORT.receive(ASP_IPA_Unitdata: ?) -> value ipa_ud { |
| 746 | IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud)); |
| 747 | } |
| 748 | |
| 749 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | } |
| 753 | |
Harald Welte | 2e32e43 | 2018-05-24 20:00:00 +0200 | [diff] [blame] | 754 | /*********************************************************************** |
| 755 | * IPA Event waiter component. Wait for ASP_IPA_EVENT_ID_ACK |
| 756 | ***********************************************************************/ |
| 757 | |
| 758 | type component IPA_EventWaiter_CT { |
| 759 | port IPA_SP_PT IPA_SP_PORT; |
| 760 | } |
| 761 | |
| 762 | function waiter_main(template ASP_IPA_Event wait_for := t_ASP_IPA_EVT_UD(ASP_IPA_EVENT_ID_ACK)) |
| 763 | runs on IPA_EventWaiter_CT { |
| 764 | |
| 765 | alt { |
| 766 | [] IPA_SP_PORT.receive(wait_for) { |
| 767 | setverdict(pass); |
| 768 | } |
| 769 | [] IPA_SP_PORT.receive { repeat; } |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 774 | } |