/* dual-faced port that wraps an IPL4asp port and encodes/decodes GSMTAP
 * (C) 2017 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+
 */

module GSMTAP_PortType {
	import from GSMTAP_Types all;
	import from IPL4asp_PortType all;
	import from IPL4asp_Types all;

	/* just like ASP_ReacFrom but with decoded GsmtapMessage */
	type record GSMTAP_RecvFrom {
		ConnectionId	connId,
		HostName	remName,
		PortNumber	remPort,
		HostName	locName,
		PortNumber	locPort,
		ProtoTuple	proto,
		UserData	userData,
		GsmtapMessage	msg
	}

	/* just like ASP_Send but with decoded GsmtapMessage */
	type record GSMTAP_Send {
		ConnectionId	connId,
		ProtoTuple	proto,
		GsmtapMessage	msg
	}

	/* just like ASP_SendTo but with decoded GsmtapMessage */
	type record GSMTAP_SendTo {
		ConnectionId	connId,
		HostName	remName,
		PortNumber	remPort,
		ProtoTuple	proto,
		GsmtapMessage	msg
	}

	/* Convert RecvFrom from ASP to GSMTAP decoded */
	private function IPL4_to_GSMTAP(in ASP_RecvFrom pin, out GSMTAP_RecvFrom pout) {
		pout.connId := pin.connId;
		pout.remName := pin.remName;
		pout.remPort := pin.remPort;
		pout.locName := pin.locName;
		pout.locPort := pin.locPort;
		pout.proto := pin.proto;
		pout.userData := pin.userData;
		pout.msg := dec_GsmtapMessage(pin.msg);
	} with { extension "prototype(fast)" }

	/* Convert SendTo from GSMTAP to ASP */
	private function GSMTAP_to_IPL4_SendTo(in GSMTAP_SendTo pin, out ASP_SendTo pout) {
		pout.connId := pin.connId;
		pout.remName := pin.remName;
		pout.remPort := pin.remPort;
		pout.proto := pin.proto;
		pout.msg := enc_GsmtapMessage(pin.msg);
	} with { extension "prototype(fast)" }

	/* Convert SendTo from GSMTAP to ASP */
	private function GSMTAP_to_IPL4_Send(in GSMTAP_Send pin, out ASP_Send pout) {
		pout.connId := pin.connId;
		pout.proto := pin.proto;
		pout.msg := enc_GsmtapMessage(pin.msg);
	} with { extension "prototype(fast)" }

	/* dual-faced port that converts from octetstring to decoded
	 * GSMTAP and vice-versa */
	type port GSMTAP_PT message {
		out GSMTAP_Send
		out GSMTAP_SendTo
		in GSMTAP_RecvFrom
		in ASP_Event
		in ASP_ConnId_ReadyToRelease
	} with { extension "user IPL4asp_PT
		out(GSMTAP_Send -> ASP_Send: function(GSMTAP_to_IPL4_Send);
		    GSMTAP_SendTo -> ASP_SendTo: function(GSMTAP_to_IPL4_SendTo))
		in(ASP_RecvFrom -> GSMTAP_RecvFrom: function(IPL4_to_GSMTAP);
		   ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
		   ASP_Event -> ASP_Event: simple)" }

}
