aboutsummaryrefslogtreecommitdiffstats
path: root/library/M3UA_CodecPort.ttcn
blob: e88b6a0d9aea67902520b29b2fe0aa4f77685896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
module M3UA_CodecPort {

/* Simple M3UA Codec Port, translating between raw SCTP primitives with
 * octetstring payload towards the IPL4asp provider, and M3UA primitives
 * which carry the decoded M3UA data types as payload.
 *
 * (C) 2019 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

	import from IPL4asp_PortType all;
	import from IPL4asp_Types all;
	import from M3UA_CodecPort_CtrlFunct all;
	import from M3UA_Types all;

	type record M3UA_RecvFrom {
		ConnectionId	connId,
		HostName	remName,
		PortNumber	remPort,
		HostName	locName,
		PortNumber	locPort,
		PDU_M3UA	msg
	};

	template M3UA_RecvFrom t_M3UA_RecvFrom(template PDU_M3UA msg) := {
		connId := ?,
		remName := ?,
		remPort := ?,
		locName := ?,
		locPort := ?,
		msg := msg
	}

	type record M3UA_Send {
		ConnectionId	connId,
		integer		stream optional,
		PDU_M3UA	msg
	}

	template M3UA_Send t_M3UA_Send(template ConnectionId connId, template PDU_M3UA msg,
					template (omit) integer stream := omit) := {
		connId := connId,
		stream := stream,
		msg := msg
	}

	private function IPL4_to_M3UA_RecvFrom(in ASP_RecvFrom pin, out M3UA_RecvFrom pout) {
		pout.connId := pin.connId;
		pout.remName := pin.remName;
		pout.remPort := pin.remPort;
		pout.locName := pin.locName;
		pout.locPort := pin.locPort;
		pout.msg := dec_PDU_M3UA(pin.msg);
	} with { extension "prototype(fast)" };

	private function M3UA_to_IPL4_Send(in M3UA_Send pin, out ASP_Send pout) {
		pout.connId := pin.connId;
		if (ispresent(pin.stream)) {
			pout.proto := {
				sctp := {
					sinfo_stream := pin.stream,
					sinfo_ppid := 3,
					remSocks := omit,
					assocId := omit
				}
			};
		} else {
			pout.proto := { tcp := { } };
		}
		pout.msg := enc_PDU_M3UA(pin.msg);
	} with { extension "prototype(fast)" };

	type port M3UA_CODEC_PT message {
		out	M3UA_Send;
		in	M3UA_RecvFrom,
			ASP_ConnId_ReadyToRelease,
			ASP_Event;
	} with { extension "user IPL4asp_PT
		out(M3UA_Send -> ASP_Send:function(M3UA_to_IPL4_Send))
		in(ASP_RecvFrom -> M3UA_RecvFrom: function(IPL4_to_M3UA_RecvFrom);
		   ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
		   ASP_Event -> ASP_Event: simple)"
	};

	function f_set_tcp_segmentation(M3UA_CODEC_PT pt, ConnectionId connId) {
		/* Set function for dissecting the binary stream into packets */
		var f_IPL4_getMsgLen vl_f := refers(f_IPL4_fixedMsgLen);
		/* Offset: 4, size of length: 4, delta: 0, multiplier: 1, big-endian */
		M3UA_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(pt, connId, vl_f, {4, 4, 0, 1, 0});
	}
}