///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2023 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
//  File:         SCCP_Mapping.ttcnpp
//  Description:  SCCP <-> MTP3 dual faced port definition
//  Rev:          R7A
//  Prodnr:       CNL 113 341
//  Updated:      2012-11-05
//  Contact:      http://ttcn.ericsson.se
module SCCP_Mapping
{
import from MTP3asp_Types all;
import from MTP3asp_PortType all;
import from SCCP_Types  all;
import from SCCPasp_Types all;

// *************************************************************************
// *************************************************************************
//SCCP Component related declarations
// *************************************************************************
// *************************************************************************

type integer UnhandledProtocol;

//   SCCPasp_SP_PT SCCP_SP_PORT
//+-----------------+-----------------+
//|              SCCP_CT              /
//|                                   /
//+-----------------+-----------------+
//MTP3asp_SCCP_PT MTP3_SCCP_PORT
//                  |
//

#ifdef USE_MTP3_DISTRIBUTOR
//Version to internal port
type port MTP3asp_SCCP_PT  message
{
  in  PDU_SCCP,
      ASP_MTP3_PAUSE,
      ASP_MTP3_RESUME,
      ASP_MTP3_STATUS;
  out ASP_MTP3_TRANSFERreq_sccp;
}
with
{ extension
   "internal user MTP3asp_PT
    out(ASP_MTP3_TRANSFERreq_sccp
         -> ASP_MTP3_TRANSFERreq: function(f_enc_SCCP_to_MTP))
    in( ASP_MTP3_TRANSFERind
         -> PDU_SCCP: function(f_dec_MTP_to_SCCP),
            - : discard;
	      ASP_MTP3_PAUSE -> ASP_MTP3_PAUSE: simple;
	      ASP_MTP3_RESUME -> ASP_MTP3_RESUME: simple;
        ASP_MTP3_STATUS -> ASP_MTP3_STATUS: simple)
   "
}
#else
//Version to external port
type port MTP3asp_SCCP_PT  message
{
  in  PDU_SCCP,
      ASP_MTP3_PAUSE,
      ASP_MTP3_RESUME,
      ASP_MTP3_STATUS;
  in  UnhandledProtocol;
  out ASP_MTP3_TRANSFERreq_sccp;
}
with
{ extension
   "user MTP3asp_PT
    out(ASP_MTP3_TRANSFERreq_sccp
         -> ASP_MTP3_TRANSFERreq: function(f_enc_SCCP_to_MTP))
    in( ASP_MTP3_TRANSFERind ->
          PDU_SCCP: function(f_dec_MTP_to_SCCP),
          UnhandledProtocol: function(f_dec_MTP_to_UnhandledProtocol);
	      ASP_MTP3_PAUSE -> ASP_MTP3_PAUSE: simple;
	      ASP_MTP3_RESUME -> ASP_MTP3_RESUME: simple;
        ASP_MTP3_STATUS -> ASP_MTP3_STATUS: simple)
   "
}

function f_dec_MTP_to_UnhandledProtocol(in ASP_MTP3_TRANSFERind pl_in, out UnhandledProtocol pl_out) return integer
{
  pl_out := 1;
  return 0;
} with {extension "prototype(backtrack)" }

#endif

function f_enc_SCCP_to_MTP
 (in  ASP_MTP3_TRANSFERreq_sccp pl_in,
  out ASP_MTP3_TRANSFERreq pl_out) return integer
{
  var bitstring vl_sio_bit := oct2bit(pl_in.sio);
  var MTP3_Field_sio vl_sio_struct;
  vl_sio_struct.ni := substr(vl_sio_bit,0,2);
  vl_sio_struct.prio := substr(vl_sio_bit,2,2);
  vl_sio_struct.si := substr(vl_sio_bit,4,4);

  pl_out :=
  {
    sio := vl_sio_struct,
    opc := pl_in.opc,
    dpc := pl_in.dpc,
    sls := pl_in.sls,
    data:= enc_PDU_SCCP(pl_in.data)
  }
  return 0;
} with {extension "prototype(backtrack)" }

function f_dec_MTP_to_SCCP
 (in  ASP_MTP3_TRANSFERind pl_in,
  out PDU_SCCP pl_out) return integer
{
  if (pl_in.sio.si != '0011'B)
  {
    log("The received message is not SCCP. Ignored.");
    return 1;
  }
  pl_out := dec_PDU_SCCP(pl_in.data);

  return 0;
} with {extension "prototype(backtrack)" }



}
