blob: e88b6a0d9aea67902520b29b2fe0aa4f77685896 [file] [log] [blame]
Harald Welte0db44132019-10-17 11:09:05 +02001module M3UA_CodecPort {
2
3/* Simple M3UA Codec Port, translating between raw SCTP primitives with
4 * octetstring payload towards the IPL4asp provider, and M3UA primitives
5 * which carry the decoded M3UA data types as payload.
6 *
7 * (C) 2019 by Harald Welte <laforge@gnumonks.org>
8 * All rights reserved.
9 *
10 * Released under the terms of GNU General Public License, Version 2 or
11 * (at your option) any later version.
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 */
15
16 import from IPL4asp_PortType all;
17 import from IPL4asp_Types all;
Vadim Yanitskiyf197ed22024-02-18 19:26:35 +070018 import from M3UA_CodecPort_CtrlFunct all;
Harald Welte0db44132019-10-17 11:09:05 +020019 import from M3UA_Types all;
20
21 type record M3UA_RecvFrom {
22 ConnectionId connId,
23 HostName remName,
24 PortNumber remPort,
25 HostName locName,
26 PortNumber locPort,
27 PDU_M3UA msg
28 };
29
30 template M3UA_RecvFrom t_M3UA_RecvFrom(template PDU_M3UA msg) := {
31 connId := ?,
32 remName := ?,
33 remPort := ?,
34 locName := ?,
35 locPort := ?,
36 msg := msg
37 }
38
39 type record M3UA_Send {
40 ConnectionId connId,
Vadim Yanitskiyf197ed22024-02-18 19:26:35 +070041 integer stream optional,
Harald Welte0db44132019-10-17 11:09:05 +020042 PDU_M3UA msg
43 }
44
45 template M3UA_Send t_M3UA_Send(template ConnectionId connId, template PDU_M3UA msg,
46 template (omit) integer stream := omit) := {
47 connId := connId,
48 stream := stream,
49 msg := msg
50 }
51
52 private function IPL4_to_M3UA_RecvFrom(in ASP_RecvFrom pin, out M3UA_RecvFrom pout) {
53 pout.connId := pin.connId;
54 pout.remName := pin.remName;
55 pout.remPort := pin.remPort;
56 pout.locName := pin.locName;
57 pout.locPort := pin.locPort;
58 pout.msg := dec_PDU_M3UA(pin.msg);
59 } with { extension "prototype(fast)" };
60
61 private function M3UA_to_IPL4_Send(in M3UA_Send pin, out ASP_Send pout) {
62 pout.connId := pin.connId;
Vadim Yanitskiyf197ed22024-02-18 19:26:35 +070063 if (ispresent(pin.stream)) {
64 pout.proto := {
65 sctp := {
66 sinfo_stream := pin.stream,
67 sinfo_ppid := 3,
68 remSocks := omit,
69 assocId := omit
70 }
71 };
72 } else {
73 pout.proto := { tcp := { } };
74 }
Harald Welte0db44132019-10-17 11:09:05 +020075 pout.msg := enc_PDU_M3UA(pin.msg);
76 } with { extension "prototype(fast)" };
77
78 type port M3UA_CODEC_PT message {
79 out M3UA_Send;
80 in M3UA_RecvFrom,
81 ASP_ConnId_ReadyToRelease,
82 ASP_Event;
83 } with { extension "user IPL4asp_PT
84 out(M3UA_Send -> ASP_Send:function(M3UA_to_IPL4_Send))
85 in(ASP_RecvFrom -> M3UA_RecvFrom: function(IPL4_to_M3UA_RecvFrom);
86 ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
87 ASP_Event -> ASP_Event: simple)"
Vadim Yanitskiyf197ed22024-02-18 19:26:35 +070088 };
89
90 function f_set_tcp_segmentation(M3UA_CODEC_PT pt, ConnectionId connId) {
91 /* Set function for dissecting the binary stream into packets */
92 var f_IPL4_getMsgLen vl_f := refers(f_IPL4_fixedMsgLen);
93 /* Offset: 4, size of length: 4, delta: 0, multiplier: 1, big-endian */
94 M3UA_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(pt, connId, vl_f, {4, 4, 0, 1, 0});
Harald Welte0db44132019-10-17 11:09:05 +020095 }
96}