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