Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 1 | module IPA_Emulation { |
| 2 | |
| 3 | import from IPA_Types all; |
| 4 | import from IPA_CodecPort all; |
| 5 | import from IPA_CodecPort_CtrlFunct all; |
| 6 | import from IPL4asp_Types all; |
Harald Welte | 1218883 | 2017-11-29 11:47:13 +0100 | [diff] [blame] | 7 | import from IPL4asp_PortType all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 8 | import from MTP3asp_Types all; |
| 9 | import from MTP3asp_PortType all; |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 10 | import from RSL_Types all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 11 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 12 | import from MGCP_Types all; |
| 13 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 14 | modulepar { |
Harald Welte | 92632e1 | 2017-11-25 02:31:20 +0100 | [diff] [blame] | 15 | /* Use Osmocom extended IPA mux header */ |
| 16 | boolean mp_ipa_mgcp_uses_osmo_ext := true; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 17 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 18 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 19 | type enumerated IpaMode { |
| 20 | IPA_MODE_CLIENT, |
| 21 | IPA_MODE_SERVER |
| 22 | } |
| 23 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 24 | type record ASP_IPA_Unitdata { |
| 25 | IpaStreamId streamId, |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 26 | IpaExtStreamId streamIdExt optional, |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 27 | octetstring payload |
| 28 | } |
| 29 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 30 | type enumerated ASP_IPA_EventUpDown { |
| 31 | ASP_IPA_EVENT_DOWN, |
| 32 | ASP_IPA_EVENT_UP, |
| 33 | ASP_IPA_EVENT_ID_ACK |
| 34 | } |
| 35 | |
| 36 | type union ASP_IPA_Event { |
| 37 | ASP_IPA_EventUpDown up_down |
| 38 | } |
| 39 | |
| 40 | template ASP_IPA_Event t_ASP_IPA_EVT_UD(ASP_IPA_EventUpDown ud) := { |
| 41 | up_down := ud |
| 42 | } |
| 43 | |
Harald Welte | 1dd8f37 | 2017-11-25 02:25:27 +0100 | [diff] [blame] | 44 | template ASP_IPA_Unitdata t_ASP_IPA_UD(IpaStreamId sid, octetstring pl, |
| 45 | template IpaExtStreamId esid := omit) := { |
| 46 | streamId := sid, |
| 47 | streamIdExt := esid, |
| 48 | payload := pl |
| 49 | } |
| 50 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 51 | type record ASP_RSL_Unitdata { |
| 52 | IpaStreamId streamId, |
| 53 | RSL_Message rsl |
| 54 | }; |
| 55 | |
Harald Welte | 7ae019e | 2017-12-09 00:54:15 +0100 | [diff] [blame] | 56 | 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] | 57 | streamId := sid, |
| 58 | rsl := valueof(rsl) |
| 59 | } |
| 60 | |
Harald Welte | 7ae019e | 2017-12-09 00:54:15 +0100 | [diff] [blame] | 61 | template ASP_RSL_Unitdata tr_ASP_RSL_UD(IpaStreamId sid, template RSL_Message rsl) := { |
| 62 | streamId := sid, |
| 63 | rsl := rsl |
| 64 | } |
| 65 | |
| 66 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 67 | template IpaStreamId t_IpaSidRSL := ( IPAC_PROTO_RSL_TRX0, IPAC_PROTO_RSL_TRX1, |
| 68 | IPAC_PROTO_RSL_TRX2, IPAC_PROTO_RSL_TRX3 ); |
| 69 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 70 | type port IPA_SP_PT message { |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 71 | inout ASP_IPA_Unitdata, ASP_IPA_Event; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 72 | } with { extension "internal" } |
| 73 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 74 | type port IPA_MGCP_PT message { |
| 75 | inout MgcpCommand, MgcpResponse; |
| 76 | } with { extension "internal" } |
| 77 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 78 | type port IPA_RSL_PT message { |
| 79 | inout ASP_RSL_Unitdata, ASP_IPA_Event; |
| 80 | } with { extension "internal" } |
| 81 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 82 | type component IPA_Emulation_CT { |
| 83 | /* down-facing port to IPA codec port */ |
| 84 | port IPA_CODEC_PT IPA_PORT; |
| 85 | /* up-facing port to SCCP */ |
| 86 | port MTP3asp_SP_PT MTP3_SP_PORT; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 87 | /* up-facing port for MGCP */ |
| 88 | port IPA_MGCP_PT IPA_MGCP_PORT; |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 89 | /* up-facing port for RSL */ |
| 90 | port IPA_RSL_PT IPA_RSL_PORT; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 91 | /* up-facing port for other streams */ |
| 92 | port IPA_SP_PT IPA_SP_PORT; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 93 | |
| 94 | var boolean g_initialized := false; |
| 95 | var ConnectionId g_ipa_conn_id := -1; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 96 | /* Are we a BSC/MGW (truel) or MSC (false) */ |
| 97 | var boolean g_is_bsc_mgw; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 98 | |
| 99 | var IpaMode g_mode; |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 100 | var IPA_CCM_Parameters g_ccm_pars := c_IPA_default_ccm_pars; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 103 | type record IPA_CCM_Parameters { |
| 104 | charstring ser_nr optional, |
| 105 | charstring name optional, |
| 106 | charstring location1 optional, |
| 107 | charstring location2 optional, |
| 108 | charstring equip_version optional, |
| 109 | charstring sw_version optional, |
| 110 | charstring ip_addr optional, |
| 111 | charstring mac_addr optional, |
| 112 | charstring unit_id optional, |
| 113 | charstring osmo_rand optional |
| 114 | } |
| 115 | |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 116 | const IPA_CCM_Parameters c_IPA_default_ccm_pars := { |
| 117 | ser_nr := "", |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 118 | name := "mahlzeit", |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 119 | location1 := "", |
| 120 | location2 := "", |
| 121 | equip_version := "", |
| 122 | sw_version := "", |
| 123 | ip_addr := "", |
| 124 | mac_addr := "", |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 125 | unit_id := "0/1/2", |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 126 | osmo_rand := "" |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 129 | function f_connect(charstring remote_host, PortNumber remote_port, |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 130 | charstring local_host, PortNumber local_port, |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 131 | IPA_CCM_Parameters ccm_pars := c_IPA_default_ccm_pars) runs on IPA_Emulation_CT { |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 132 | var Result res; |
| 133 | res := IPA_CodecPort_CtrlFunct.f_IPL4_connect(IPA_PORT, remote_host, remote_port, |
| 134 | local_host, local_port, 0, { tcp:={} }); |
| 135 | g_ipa_conn_id := res.connId; |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 136 | g_ccm_pars := ccm_pars; |
Harald Welte | 1218883 | 2017-11-29 11:47:13 +0100 | [diff] [blame] | 137 | /* Set function for dissecting the binary */ |
| 138 | var f_IPL4_getMsgLen vl_f := refers(f_IPL4_fixedMsgLen); |
| 139 | IPA_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(IPA_PORT, g_ipa_conn_id, vl_f, {0, 2, 3, 1, 0}); |
| 140 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 141 | g_is_bsc_mgw := true; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 142 | } |
| 143 | |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 144 | function f_bind(charstring local_host, PortNumber local_port, |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 145 | IPA_CCM_Parameters ccm_pars := c_IPA_default_ccm_pars) runs on IPA_Emulation_CT { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 146 | var Result res; |
| 147 | res := IPA_CodecPort_CtrlFunct.f_IPL4_listen(IPA_PORT, |
| 148 | local_host, local_port, { tcp:={} }); |
| 149 | g_ipa_conn_id := res.connId; |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 150 | g_ccm_pars := ccm_pars; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 151 | g_is_bsc_mgw := false; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 154 | template ASP_MTP3_TRANSFERind ts_MTP3_XFER_ind(integer opc, octetstring data) := { |
| 155 | sio := { '10'B, '00'B, '0011'B }, |
| 156 | opc := opc, |
| 157 | dpc := 0, |
| 158 | sls := 0, |
| 159 | data := data |
| 160 | } |
| 161 | |
| 162 | |
| 163 | private template IpaCcmRespPart t_IdRespPart(IpaCcmIdTag tag, charstring payload) := { |
| 164 | len := 0, /* overwritten by codec */ |
| 165 | tag := tag, |
| 166 | data := payload |
| 167 | } |
| 168 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 169 | private function f_send_IPA_EVT(template ASP_IPA_Event evt) runs on IPA_Emulation_CT { |
| 170 | IPA_RSL_PORT.send(evt); |
| 171 | /* FIXME: to other ports */ |
| 172 | } |
| 173 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 174 | /* build IPA CCM ID RESP response from IPA CCM GET */ |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 175 | 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] | 176 | var integer i; |
| 177 | var PDU_IPA_CCM resp := { |
| 178 | msg_type := IPAC_MSGT_ID_RESP, |
| 179 | u := { |
| 180 | resp := {} |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | for (i := 0; i < sizeof(get.u.get); i := i + 1) { |
| 185 | var IpaCcmIdTag tag := get.u.get[i].tag; |
| 186 | var charstring foo; |
| 187 | select (tag) { |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 188 | case (IPAC_IDTAG_SERNR) { |
| 189 | foo := g_ccm_pars.ser_nr; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 190 | } |
| 191 | case (IPAC_IDTAG_UNITNAME) { |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 192 | foo := g_ccm_pars.name; |
| 193 | } |
| 194 | case (IPAC_IDTAG_LOCATION1) { |
| 195 | foo := g_ccm_pars.location1; |
| 196 | } |
| 197 | case (IPAC_IDTAG_LOCATION2) { |
| 198 | foo := g_ccm_pars.location2; |
| 199 | } |
| 200 | case (IPAC_IDTAG_EQUIPVERS) { |
| 201 | foo := g_ccm_pars.equip_version; |
| 202 | } |
| 203 | case (IPAC_IDTAG_SWVERSION) { |
| 204 | foo := g_ccm_pars.sw_version; |
| 205 | } |
| 206 | case (IPAC_IDTAG_IPADDR) { |
| 207 | foo := g_ccm_pars.ip_addr; |
| 208 | } |
| 209 | case (IPAC_IDTAG_MACADDR) { |
| 210 | foo := g_ccm_pars.mac_addr; |
| 211 | } |
| 212 | case (IPAC_IDTAG_UNIT) { |
| 213 | foo := g_ccm_pars.unit_id; |
| 214 | } |
| 215 | case (IPAC_IDTAG_OSMO_RAND) { |
| 216 | foo := g_ccm_pars.osmo_rand; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 217 | } |
| 218 | case else { |
Harald Welte | e21096d | 2017-12-04 20:45:12 +0100 | [diff] [blame] | 219 | foo := "unknown"; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | resp.u.resp[sizeof(resp.u.resp)] := valueof(t_IdRespPart(tag, foo)); |
| 223 | } |
| 224 | |
| 225 | return resp; |
| 226 | } |
| 227 | |
| 228 | /* transmit IPA CCM message */ |
| 229 | 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] | 230 | 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] | 231 | log("CCM Tx:", ccm); |
| 232 | IPA_PORT.send(ipa_tx); |
| 233 | } |
| 234 | |
| 235 | template PDU_IPA_CCM ts_IPA_PONG := { |
| 236 | msg_type := IPAC_MSGT_PONG, |
| 237 | u := omit |
| 238 | } |
| 239 | |
| 240 | template PDU_IPA_CCM ts_IPA_ACK := { |
| 241 | msg_type := IPAC_MSGT_ID_ACK, |
| 242 | u := omit |
| 243 | } |
| 244 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 245 | template PDU_IPA_CCM ts_IPA_ID_GET := { |
| 246 | msg_type := IPAC_MSGT_ID_GET, |
| 247 | u := { |
| 248 | get := { |
| 249 | { 1, IPAC_IDTAG_UNITNAME } |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 254 | /* receive IPA CCM message */ |
| 255 | private function f_ccm_rx(PDU_IPA_CCM ccm) runs on IPA_Emulation_CT { |
| 256 | select (ccm.msg_type) { |
| 257 | case (IPAC_MSGT_PING) { |
| 258 | f_ccm_tx(valueof(ts_IPA_PONG)); |
| 259 | } |
| 260 | case (IPAC_MSGT_ID_ACK) { |
| 261 | f_ccm_tx(valueof(ts_IPA_ACK)); |
| 262 | } |
| 263 | case (IPAC_MSGT_ID_GET) { |
| 264 | f_ccm_tx(f_ccm_make_id_resp(ccm)); |
| 265 | } |
| 266 | case else { |
| 267 | log("Unknown/unsupported IPA CCM message type", ccm); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 272 | private function f_to_asp(IPA_RecvFrom ipa_rx) return ASP_IPA_Unitdata { |
| 273 | var ASP_IPA_Unitdata ret := { |
| 274 | streamId := ipa_rx.streamId, |
Harald Welte | 2a8f847 | 2017-11-23 21:11:34 +0100 | [diff] [blame] | 275 | streamIdExt := ipa_rx.streamIdExt, |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 276 | payload := ipa_rx.msg |
| 277 | } |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | private function f_from_asp(ConnectionId connId, ASP_IPA_Unitdata ipa_tx) return IPA_Send { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 282 | var IPA_Send ret := valueof(t_IPA_Send(connId, ipa_tx.streamId, ipa_tx.payload, |
| 283 | ipa_tx.streamIdExt)); |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 284 | return ret; |
| 285 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 286 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 287 | private function f_from_rsl(ConnectionId connId, ASP_RSL_Unitdata rsl_tx) return IPA_Send { |
| 288 | var octetstring payload := enc_RSL_Message(rsl_tx.rsl); |
| 289 | var IPA_Send ret := valueof(t_IPA_Send(connId, rsl_tx.streamId, payload)); |
| 290 | return ret; |
| 291 | } |
| 292 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 293 | function main_client(charstring remote_host, PortNumber remote_port, |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 294 | charstring local_host, PortNumber local_port, |
| 295 | IPA_CCM_Parameters ccm_pars := c_IPA_default_ccm_pars) runs on IPA_Emulation_CT { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 296 | g_mode := IPA_MODE_CLIENT; |
Harald Welte | e09921f | 2017-12-07 17:49:00 +0100 | [diff] [blame] | 297 | f_connect(remote_host, remote_port, local_host, local_port, ccm_pars); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 298 | ScanEvents(); |
| 299 | } |
| 300 | |
| 301 | function main_server(charstring local_host, PortNumber local_port) runs on IPA_Emulation_CT { |
| 302 | g_mode := IPA_MODE_SERVER; |
| 303 | f_bind(local_host, local_port); |
| 304 | ScanEvents(); |
| 305 | } |
| 306 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 307 | private function f_mgcp_to_user(octetstring msg) runs on IPA_Emulation_CT { |
| 308 | var charstring msg_ch := oct2char(msg); |
| 309 | if (g_is_bsc_mgw) { |
| 310 | log("============"); |
| 311 | log(msg_ch); |
| 312 | IPA_MGCP_PORT.send(dec_MgcpCommand(msg_ch)); |
| 313 | } else { |
| 314 | IPA_MGCP_PORT.send(dec_MgcpResponse(msg_ch)); |
| 315 | } |
| 316 | } |
| 317 | |
Harald Welte | 92632e1 | 2017-11-25 02:31:20 +0100 | [diff] [blame] | 318 | private function f_mgcp_to_ud(octetstring payload) runs on IPA_Emulation_CT return ASP_IPA_Unitdata { |
| 319 | if (mp_ipa_mgcp_uses_osmo_ext) { |
| 320 | return valueof(t_ASP_IPA_UD(IPAC_PROTO_MGCP_OLD, payload)); |
| 321 | } else { |
| 322 | return valueof(t_ASP_IPA_UD(IPAC_PROTO_OSMO, payload, IPAC_PROTO_EXT_MGCP)); |
| 323 | } |
| 324 | } |
| 325 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 326 | private function ScanEvents() runs on IPA_Emulation_CT { |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 327 | var IPA_RecvFrom ipa_rx; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 328 | var ASP_IPA_Unitdata ipa_ud; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 329 | var ASP_MTP3_TRANSFERreq mtp_req; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 330 | var ASP_Event asp_evt; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 331 | var MgcpCommand mgcp_cmd; |
| 332 | var MgcpResponse mgcp_rsp; |
Harald Welte | 1dd8f37 | 2017-11-25 02:25:27 +0100 | [diff] [blame] | 333 | var octetstring payload; |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 334 | var ASP_RSL_Unitdata rsl; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 335 | |
| 336 | while (true) { |
| 337 | alt { |
| 338 | /* Received IPA -> up into SCCP stack */ |
| 339 | [] IPA_PORT.receive(IPA_RecvFrom: ?) -> value ipa_rx { |
| 340 | select (ipa_rx.streamId) { |
| 341 | case (IPAC_PROTO_CCM) { |
| 342 | var PDU_IPA_CCM ccm := dec_PDU_IPA_CCM(ipa_rx.msg); |
| 343 | log("CCM Rx:", ccm); |
| 344 | f_ccm_rx(ccm); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 345 | } case (IPAC_PROTO_SCCP) { |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 346 | var ASP_MTP3_TRANSFERind mtp; |
| 347 | mtp := valueof(ts_MTP3_XFER_ind(0, ipa_rx.msg)); |
| 348 | MTP3_SP_PORT.send(mtp); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 349 | } case (IPAC_PROTO_MGCP_OLD) { |
| 350 | f_mgcp_to_user(ipa_rx.msg); |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 351 | } case (t_IpaSidRSL) { |
| 352 | rsl := { |
| 353 | streamId := ipa_rx.streamId, |
| 354 | rsl := dec_RSL_Message(ipa_rx.msg) |
| 355 | }; |
| 356 | IPA_RSL_PORT.send(rsl); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 357 | } case (IPAC_PROTO_OSMO) { |
| 358 | select (ipa_rx.streamIdExt) { |
| 359 | case (IPAC_PROTO_EXT_MGCP) { |
| 360 | f_mgcp_to_user(ipa_rx.msg); |
| 361 | } case else { |
| 362 | IPA_SP_PORT.send(f_to_asp(ipa_rx)); |
| 363 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 364 | } |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 365 | } case else { |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 366 | IPA_SP_PORT.send(f_to_asp(ipa_rx)); |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 371 | /* server only */ |
| 372 | [] IPA_PORT.receive(ASP_Event:{connOpened:=?}) -> value asp_evt { |
| 373 | log("IPA: Connected"); |
| 374 | g_ipa_conn_id := asp_evt.connOpened.connId; |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 375 | 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] | 376 | if (g_mode == IPA_MODE_SERVER) { |
| 377 | f_ccm_tx(valueof(ts_IPA_ID_GET)); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | [] IPA_PORT.receive(ASP_Event:{connClosed:=?}) -> value asp_evt { |
| 382 | log("IPA: Closed"); |
| 383 | g_ipa_conn_id := -1; |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 384 | 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] | 385 | self.stop; |
| 386 | } |
| 387 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 388 | /* Received SCCP -> down into IPA */ |
| 389 | [] MTP3_SP_PORT.receive(ASP_MTP3_TRANSFERreq: ?) -> value mtp_req { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 390 | var IPA_Send ipa_tx := valueof(t_IPA_Send(g_ipa_conn_id, IPAC_PROTO_SCCP, |
| 391 | mtp_req.data)); |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 392 | IPA_PORT.send(ipa_tx); |
| 393 | } |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 394 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 395 | /* Received MGCP -> down into IPA */ |
| 396 | [] IPA_MGCP_PORT.receive(MgcpCommand:?) -> value mgcp_cmd { |
Harald Welte | 92632e1 | 2017-11-25 02:31:20 +0100 | [diff] [blame] | 397 | payload := char2oct(enc_MgcpCommand(mgcp_cmd)); |
| 398 | ipa_ud := f_mgcp_to_ud(payload); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 399 | IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud)); |
| 400 | } |
| 401 | [] IPA_MGCP_PORT.receive(MgcpResponse:?) -> value mgcp_rsp { |
Harald Welte | 1dd8f37 | 2017-11-25 02:25:27 +0100 | [diff] [blame] | 402 | payload := char2oct(enc_MgcpResponse(mgcp_rsp)); |
Harald Welte | 92632e1 | 2017-11-25 02:31:20 +0100 | [diff] [blame] | 403 | ipa_ud := f_mgcp_to_ud(payload); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 404 | IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud)); |
| 405 | } |
| 406 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 407 | /* Received RSL -> down into IPA */ |
| 408 | [] IPA_RSL_PORT.receive(ASP_RSL_Unitdata:?) -> value rsl { |
| 409 | IPA_PORT.send(f_from_rsl(g_ipa_conn_id, rsl)); |
| 410 | } |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 411 | |
Harald Welte | 0d846a7 | 2017-12-07 17:58:28 +0100 | [diff] [blame] | 412 | |
| 413 | /* Received MISC (OML/CTRL) -> down into IPA */ |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 414 | [] IPA_SP_PORT.receive(ASP_IPA_Unitdata: ?) -> value ipa_ud { |
| 415 | IPA_PORT.send(f_from_asp(g_ipa_conn_id, ipa_ud)); |
| 416 | } |
| 417 | |
| 418 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | } |