module NGAP_CodecPort {

/* Simple NGAP Codec Port, translating between raw SCTP primitives with
 * octetstring payload towards the IPL4asp provider, and NGAP primitives
 * which carry the decoded NGAP data types as payload.
 *
 * (C) 2019 by Harald Welte <laforge@gnumonks.org>
 * (C) 2025 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
 * 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 NGAP_PDU_Descriptions all;
	import from NGAP_Types all;

	type record NGAP_RecvFrom {
		ConnectionId	connId,
		HostName	remName,
		PortNumber	remPort,
		HostName	locName,
		PortNumber	locPort,
		NGAP_PDU	msg
	};

	template NGAP_RecvFrom t_NGAP_RecvFrom(template NGAP_PDU msg) := {
		connId := ?,
		remName := ?,
		remPort := ?,
		locName := ?,
		locPort := ?,
		msg := msg
	}

	type record NGAP_Send {
		ConnectionId	connId,
		NGAP_PDU	msg
	}

	template NGAP_Send t_NGAP_Send(template ConnectionId connId, template NGAP_PDU msg) := {
		connId := connId,
		msg := msg
	}

	private function IPL4_to_NGAP_RecvFrom(in ASP_RecvFrom pin, out NGAP_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_NGAP_PDU(pin.msg);
	} with { extension "prototype(fast)" };

	private function NGAP_to_IPL4_Send(in NGAP_Send pin, out ASP_Send pout) {
		pout.connId := pin.connId;
		pout.proto := {
			sctp := {
				sinfo_stream := omit,
				sinfo_ppid := 60,
				remSocks := omit,
				assocId := omit
			}
		};
		pout.msg := enc_NGAP_PDU(pin.msg);
	} with { extension "prototype(fast)" };

	type port NGAP_CODEC_PT message {
		out	NGAP_Send;
		in	NGAP_RecvFrom,
			ASP_ConnId_ReadyToRelease,
			ASP_Event;
	} with { extension "user IPL4asp_PT
		out(NGAP_Send -> ASP_Send:function(NGAP_to_IPL4_Send))
		in(ASP_RecvFrom -> NGAP_RecvFrom: function(IPL4_to_NGAP_RecvFrom);
		   ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
		   ASP_Event -> ASP_Event: simple)"
	}
}
