///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2019 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:               IPL4asp_Types.ttcn
//  Reference:

module IPL4asp_Types {

import from Socket_API_Definitions all;

//////////////////////////////////////////////////////////
// Type: ConnectionId
//
// Purpose:
//  ConnectionId
//
// Elements:
//   Type alias of <Socket_API_Definitions.ConnectionId>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.ConnectionId ConnectionId;

//////////////////////////////////////////////////////////
// Type: ro_ConnectionId
//
// Purpose:
//  ro_ConnectionId
//
// Elements:
//   Type alias of <Socket_API_Definitions.ro_ConnectionId>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.ro_ConnectionId ro_ConnectionId;

//////////////////////////////////////////////////////////
// Type: AssociationId
//
// Purpose:
//  AssociationId
//
// Elements:
//   Type alias of <Socket_API_Definitions.AssociationId>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.AssociationId AssociationId;

//////////////////////////////////////////////////////////
// Type: ro_AssociationId
//
// Purpose:
//  ro_AssociationId
//
// Elements:
//   Type alias of <Socket_API_Definitions.ro_AssociationId>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.ro_AssociationId ro_AssociationId;

//////////////////////////////////////////////////////////
// Type: HostName
//
// Purpose:
//  HostName
//
// Elements:
//   Type alias of <Socket_API_Definitions.HostName>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.HostName HostName;

//////////////////////////////////////////////////////////
// Type: PortNumber
//
// Purpose:
//  PortNumber
//
// Elements:
//   Type alias of <Socket_API_Definitions.PortNumber>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.PortNumber PortNumber;

//////////////////////////////////////////////////////////
// Type: Socket
//
// Purpose:
//  Socket
//
// Elements:
//   Type alias of <Socket_API_Definitions.Socket>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.Socket Socket;

//////////////////////////////////////////////////////////
// Type: SocketList
//
// Purpose:
//  SocketList
//
// Elements:
//   Type alias of <Socket_API_Definitions.SocketList>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SocketList SocketList;

//////////////////////////////////////////////////////////
// Type: UdpTuple
//
// Purpose:
//  UdpTuple
//
// Elements:
//   Type alias of <Socket_API_Definitions.UdpTuple>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.UdpTuple UdpTuple;

//////////////////////////////////////////////////////////
// Type: TcpTuple
//
// Purpose:
//  TcpTuple
//
// Elements:
//   Type alias of <Socket_API_Definitions.TcpTuple>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.TcpTuple TcpTuple;

//////////////////////////////////////////////////////////
// Type: SctpTuple
//
// Purpose:
//  SctpTuple
//
// Elements:
//   Type alias of <Socket_API_Definitions.SctpTuple>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SctpTuple SctpTuple;

//////////////////////////////////////////////////////////
// Type: SslTuple
//
// Purpose:
//  SslTuple
//
// Elements:
//   Type alias of <Socket_API_Definitions.SslTuple>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SslTuple SslTuple;

//////////////////////////////////////////////////////////
// Type: UnspecifiedTuple
//
// Purpose:
//  UnspecifiedTuple
//
// Elements:
//   Type alias of <Socket_API_Definitions.UnspecifiedTuple>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.UnspecifiedTuple UnspecifiedTuple;

//////////////////////////////////////////////////////////
// Type: ProtoTuple
//
// Purpose:
//  ProtoTuple
//
// Elements:
//   Type alias of <Socket_API_Definitions.ProtoTuple>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.ProtoTuple ProtoTuple;

//////////////////////////////////////////////////////////
// Type: Result
//
// Purpose:
//  Result
//
// Elements:
//   Type alias of <Socket_API_Definitions.Result>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.Result Result;

//////////////////////////////////////////////////////////
// Type: Extended_Result
//
// Purpose:
//  Extended Result
//
// Elements:
//   Type alias of <Socket_API_Definitions.Result>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.Extended_Result Extended_Result;

//////////////////////////////////////////////////////////
// Type: UserData
//
// Purpose:
//  UserData
//
// Elements:
//   Type alias of <Socket_API_Definitions.UserData>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.UserData UserData;

//////////////////////////////////////////////////////////
// Type: PortError
//
// Purpose:
//  PortError
//
// Elements:
//   Type alias of <Socket_API_Definitions.PortError>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.PortError PortError;

//////////////////////////////////////////////////////////
// Type: ConnectionOpenedEvent
//
// Purpose:
//  ConnectionOpenedEvent
//
// Elements:
//   Type alias of <Socket_API_Definitions.ConnectionOpenedEvent>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.ConnectionOpenedEvent ConnectionOpenedEvent;

//////////////////////////////////////////////////////////
// Type: ConnectionClosedEvent
//
// Purpose:
//  ConnectionClosedEvent
//
// Elements:
//   Type alias of <Socket_API_Definitions.ConnectionClosedEvent>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.ConnectionClosedEvent ConnectionClosedEvent;

//////////////////////////////////////////////////////////
// Type: SctpEvent
//
// Purpose:
//  SctpEvent
//
// Elements:
//   Type alias of <Socket_API_Definitions.SctpEvent>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SctpEvent SctpEvent;

//////////////////////////////////////////////////////////
// Type: PortEvent
//
// Purpose:
//  PortEvent
//
// Elements:
//   Type alias of <Socket_API_Definitions.PortEvent>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.PortEvent PortEvent;

//////////////////////////////////////////////////////////
// Type: SAC_STATE
//
// Purpose:
//  SAC_STATE
//
// Elements:
//   Type alias of <Socket_API_Definitions.SAC_STATE>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SAC_STATE SAC_STATE;

//////////////////////////////////////////////////////////
// Type: SctpAssocChange
//
// Purpose:
//  SctpAssocChange
//
// Elements:
//   Type alias of <Socket_API_Definitions.SctpAssocChange>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SctpAssocChange SctpAssocChange;

//////////////////////////////////////////////////////////
// Type: SPC_STATE
//
// Purpose:
//  SPC_STATE
//
// Elements:
//   Type alias of <Socket_API_Definitions.SPC_STATE>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SPC_STATE SPC_STATE;

//////////////////////////////////////////////////////////
// Type: SctpPeerAddrChange
//
// Purpose:
//  SctpPeerAddrChange
//
// Elements:
//   Type alias of <Socket_API_Definitions.SctpPeerAddrChange>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SctpPeerAddrChange SctpPeerAddrChange;

//////////////////////////////////////////////////////////
// Type: SctpSendFailed
//
// Purpose:
//  SctpSendFailed
//
// Elements:
//   Type alias of <Socket_API_Definitions.SctpSendFailed>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SctpSendFailed SctpSendFailed;

//////////////////////////////////////////////////////////
// Type: SctpRemoteError
//
// Purpose:
//  SctpRemoteError
//
// Elements:
//   Type alias of <Socket_API_Definitions.SctpRemoteError>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SctpRemoteError SctpRemoteError;

//////////////////////////////////////////////////////////
// Type: SctpShutDownEvent
//
// Purpose:
//  SctpShutDownEvent
//
// Elements:
//   Type alias of <Socket_API_Definitions.SctpShutDownEvent>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SctpShutDownEvent SctpShutDownEvent;

//////////////////////////////////////////////////////////
// Type: SctpPartialDeliveryEvent
//
// Purpose:
//  SctpPartialDeliveryEvent
//
// Elements:
//   Type alias of <Socket_API_Definitions.SctpPartialDeliveryEvent>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SctpPartialDeliveryEvent SctpPartialDeliveryEvent;

//////////////////////////////////////////////////////////
// Type: SctpAdaptationIndication
//
// Purpose:
//  SctpAdaptationIndication
//
// Elements:
//   Type alias of <Socket_API_Definitions.SctpAdaptationIndication>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.SctpAdaptationIndication SctpAdaptationIndication;

//////////////////////////////////////////////////////////
// Type: ro_integer
//
// Purpose:
//  ro_integer
//
// Elements:
//   Type alias of <Socket_API_Definitions.ro_integer>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.ro_integer ro_integer;

//////////////////////////////////////////////////////////
// Type: f_getMsgLen
//
// Purpose:
//  f_getMsgLen
//
// Elements:
//   Type alias of <Socket_API_Definitions.f_getMsgLen>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.f_getMsgLen f_getMsgLen;

//////////////////////////////////////////////////////////
// Type: ro_charstring
//
// Purpose:
//  ro_charstring
//
// Elements:
//   Type alias of <Socket_API_Definitions.ro_charstring>
///////////////////////////////////////////////////////////
type Socket_API_Definitions.ro_charstring ro_charstring;

/* A list of options can be specified on global or protocol level,
in listen or connect or for an opened connection.
There are restrictions on the usage of options.
*/
/* TcpKeepAlive is valid only for TCP. */
type record TcpKeepAlive {
  boolean enable optional,
  integer count optional,
  integer idle optional,
  integer interval optional
}
/* ReuseAddress should be specified in listen or connect.
It is supported for TCP.
Support for other protocols may be platform dependent. */
type record ReuseAddress {
  boolean enable optional   // default is TRUE
}
/* SCTPEvent should be specified in listen or connect.
It is supported for SCTP. */
type record SctpEventHandle {
  boolean sctp_data_io_event optional,   // default is TRUE
  boolean sctp_association_event optional,   // default is TRUE
  boolean sctp_address_event optional,   // default is TRUE
  boolean sctp_send_failure_event optional,   // default is TRUE
  boolean sctp_peer_error_event optional,   // default is TRUE
  boolean sctp_shutdown_event optional,   // default is TRUE
  boolean sctp_partial_delivery_event optional,   // default is TRUE
  boolean sctp_adaptation_layer_event optional,   // default is TRUE
  boolean sctp_authentication_event optional,   // default is TRUE
  boolean sctp_sender_dry_event optional // default is FALSE
}

type record Linger_opt {
  integer l_onoff,
  integer l_linger
}

type union SSL_protocols{
  boolean SSLv2_supported,
  boolean SSLv3_supported,
  boolean TLSv1_supported,
  boolean TLSv1_1_supported,
  boolean TLSv1_2_supported,
  boolean DTLSv1_supported,
  boolean DTLSv1_2_supported

}

type record of SSL_protocols SSL_proto_support

type record SSL_cert_options {
  charstring  ssl_key_file optional,
  charstring  ssl_certificate_file optional,
  charstring  ssl_trustedCAlist_file optional,
  charstring  ssl_cipher_list optional,
  charstring  ssl_password optional
}

type record PSK_options {
  charstring  psk_identity optional,
  charstring  psk_identity_hint optional,
  charstring  psk_key optional
}

type enumerated MTU_discover {
  PMTUDISC_DONT,    //Never do Path MTU Discovery.
  PMTUDISC_WANT,    //Use per-route settings.
  PMTUDISC_DO,      //Always do Path MTU Discovery.
  MTU               //GET ONLY! Returns the current path MTU
};

// dtlsSrtpProfiles: colon separated list, ie. "SRTP_AES128_CM_SHA1_32:SRTP_AES128_CM_SHA1_80"
type union Option {
  ReuseAddress  reuseAddress,
  TcpKeepAlive  tcpKeepAlive,
  SctpEventHandle   sctpEventHandle,
  TcpKeepAlive   sslKeepAlive,
  HostList       sctpAdditionalLocalAddresses ,
  integer        sctpEINConfigGroup,
  Linger_opt     solinger,
  SSL_proto_support ssl_support,
  boolean        no_delay,
  charstring     dtlsSrtpProfiles,
  SSL_cert_options  cert_options,
  boolean        freebind,
  record of charstring  alpn_list,
  charstring     tls_hostname,
  UDP_ENCAP_Param udp_encap,
  integer         dscp,
  MTU_discover mtu_discover,
  PSK_options    psk_options
}

type record of Option OptionList;
type record of HostName HostList;

/* The communication ASP is used to send and receive messages in octetstrings.
*/
type record ASP_Send {
  ConnectionId connId,
  ProtoTuple proto optional,
  octetstring msg
}

type record ASP_SendTo {
  ConnectionId connId,
  HostName remName,
  PortNumber remPort,
  ProtoTuple proto optional,
  octetstring msg
}

type record ASP_RecvFrom {
  ConnectionId connId,
  HostName remName,
  PortNumber remPort,
  HostName locName,
  PortNumber locPort,
  ProtoTuple proto,
  UserData userData,
  octetstring msg
}

type PortEvent ASP_Event;


/*
How to release connId:

1. Traditional way: The connid is released as soon as either:
  - The test port processed the incoming close event.
  - or the f_IPL4_close was called.

  Because the connId is released immediately by the test port, the test case
  code can try to use it, which leads faults. Also the test port can reuse the
  connId without the knowledge of the test case code

2. New safe mode: The connId is released only after the confirmation message.
  After the connId is ready for release (triggered by either the incoming close
  or f_IPL4_close) the test port put the ASP_ConnId_ReadyToRelease into the
  incoming queue. When the application processes the ASP_ConnId_ReadyToRelease
  it should call the f_IPL4_ConnId_release function to confirm the release
  of the connId.

  The new safe mode can be activated either via test port parameter
  "connId_release_mode" or f_IPL4_port_settings function

*/
type record ASP_ConnId_ReadyToRelease{
  ConnectionId connId
}

// aliases of PortError values for backward compatibility
const PortError IPL4_ERROR_GENERAL := ERROR_GENERAL;
const PortError IPL4_ERROR_INSUFFICIENT_MEMORY := ERROR_INSUFFICIENT_MEMORY;
const PortError IPL4_ERROR_INVALID_INPUT_PARAMETER := ERROR_INVALID_INPUT_PARAMETER;
const PortError IPL4_ERROR_UNSUPPORTED_TRANSPORT := ERROR_UNSUPPORTED_PROTOCOL;
const PortError IPL4_ERROR_SOCKET := ERROR_SOCKET;
const PortError IPL4_ERROR_HOSTNAME := ERROR_HOSTNAME;
const PortError IPL4_ERROR_INVALID_CONNECTION := ERROR_INVALID_CONNECTION;
const PortError IPL4_ERROR_TEMPORARILY_UNAVAILABLE := ERROR_TEMPORARILY_UNAVAILABLE;
const PortError IPL4_ERROR_AVAILABLE := ERROR_AVAILABLE;
const PortError IPL4_ERROR_LENGTH := ERROR_LENGTH;

/* Type definition for the user defined function to determine the message
length (boundary) in a TCP data stream.
See the description of f_IPL4_setGetMsgLen.
*/
type f_getMsgLen f_IPL4_getMsgLen;

/*
Type definition to query IPL4 parameters.
*/

type enumerated IPL4_Param {
  IPL4_LOCALADDRESS,
  IPL4_REMOTEADDRESS,
  IPL4_PROTO,
  IPL4_USERDATA,
  IPL4_PARENTIDX
}

type union IPL4_ParamResult {
  Socket local,
  Socket remote,
  ProtoTuple proto,
  integer userData,
  ConnectionId parentIdx
}


type enumerated IPL4_IPAddressType
{
  ErrorReadingAddress,
  IPv4,
  IPv6
};

type record IPL4_SrtpKeysAndSalts {
  octetstring localKey,
  octetstring remoteKey,
  octetstring localSalt,
  octetstring remoteSalt
}

// constants for certificate fingerprint calculation methods
type enumerated IPL4_DigestMethods
{
  NULL_method,
  //MD2, MD2 is disabled in OpenSSL
  MD4,
  MD5,
  SHA,
  SHA1,
  DSS,
  DSS1,
  ECDSA,
  SHA224,
  SHA256,
  SHA384,
  SHA512,
  MDC2,
  RIPEMD160,
  WHIRLPOOL
};

type enumerated UDP_ENCAP_Param {
UDP_ENCAP_ESPINUDP_NON_IKE (1),
UDP_ENCAP_ESPINUDP	(2),
UDP_ENCAP_L2TPINUDP	(3)
}

// currently these two seem to be supported in OpenSSL
const charstring c_IPL4_DTLS_SRTP_AES128_CM_SHA1_32_Profile := "SRTP_AES128_CM_SHA1_32";
const charstring c_IPL4_DTLS_SRTP_AES128_CM_SHA1_80_Profile := "SRTP_AES128_CM_SHA1_80";
const charstring c_IPL4_DTLS_SRTP_AES128_F8_SHA1_80_Profile := "SRTP_AES128_F8_SHA1_80";
const charstring c_IPL4_DTLS_SRTP_AES128_F8_SHA1_32_Profile := "SRTP_AES128_F8_SHA1_32";
const charstring c_IPL4_DTLS_SRTP_NULL_SHA1_80_Profile := "SRTP_NULL_SHA1_80";
const charstring c_IPL4_DTLS_SRTP_NULL_SHA1_32_Profile := "SRTP_NULL_SHA1_32";

const charstring c_IPL4_DTLS_SRTP_ALL_KNOWN_Profile :=
c_IPL4_DTLS_SRTP_AES128_CM_SHA1_32_Profile & ":" &
c_IPL4_DTLS_SRTP_AES128_CM_SHA1_80_Profile/* & ":" &
c_IPL4_DTLS_SRTP_AES128_F8_SHA1_80_Profile & ":" &
c_IPL4_DTLS_SRTP_AES128_F8_SHA1_32_Profile*//* & ":" &
c_IPL4_DTLS_SRTP_NULL_SHA1_80_Profile & ":" &
c_IPL4_DTLS_SRTP_NULL_SHA1_32_Profile*/;

} // module IPL4_Types.ttcn

