///////////////////////////////////////////////////////////////////////////////
//
// 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:               SDP_Types.ttcn
//  Rev:                R14C
//  Prodnr:             CNL 113 353
//  Contact:            http://ttcn.ericsson.se
//  Reference:          ITU-T SDP

module SDP_Types
{
external function f_SDP_enc_Message (in SDP_Message input) return charstring;
external function f_SDP_enc_Message_RFC822Name (in SDP_Message input) return charstring;
external function f_SDP_dec_Message (in charstring input) return SDP_Message;
external function f_SDP_decodeMessage (in charstring input, out SDP_Message msg) return integer;


external function f_SDP_enc_SRTP_Crypto(in SRTP_Crypto input) return charstring
 with { extension "prototype(convert) encode(TEXT)" };
external function f_SDP_dec_SRTP_Crypto(in charstring input) return SRTP_Crypto
// with { extension "prototype(convert) decode(TEXT)" };
  group Types
  {
    group SubTypes
    {
        group AttributeTypes
        {
            type record SDP_attribute_cat {
                charstring attr_value
            } with { variant "BEGIN('cat:')"}
            
            type record SDP_attribute_keywds {
                charstring attr_value
            } with { variant "BEGIN('keywds:')"}
            
            type record SDP_attribute_tool {
                charstring attr_value
            } with { variant "BEGIN('tool:')"}
            
            type record SDP_attribute_ptime {
                charstring attr_value
            } with { variant "BEGIN('ptime:')"}
            
            type record SDP_attribute_recvonly {
            } with { variant "BEGIN('recvonly')"}
            
            type record SDP_attribute_sendrecv {
            } with { variant "BEGIN('sendrecv')"}
            
            type record SDP_attribute_sendonly {
            } with { variant "BEGIN('sendonly')"}
            
            type record SDP_attribute_orient {
                charstring attr_value
            } with { variant "BEGIN('orient:')"}
        
            type record SDP_attribute_type {
                charstring attr_value
            } with { variant "BEGIN('type:')"}
            
            type record SDP_attribute_charset {
                charstring attr_value
            } with { variant "BEGIN('charset:')"}
            
            type record SDP_attribute_sdplang {
                charstring attr_value
            } with { variant "BEGIN('sdplang:')"}
            
            type record SDP_attribute_lang {
                charstring attr_value
            } with { variant "BEGIN('lang:')"}
            
            type record SDP_attribute_framerate {
                charstring attr_value
            } with { variant "BEGIN('framerate:')"}
            
            type record SDP_attribute_quality {
                charstring attr_value
            } with { variant "BEGIN('quality:')"}
            
            type record SDP_attribute_fmtp {
                charstring attr_value
            } with { variant "BEGIN('fmtp:')"}
            
            type record SDP_attribute_curr {
                charstring attr_value
            } with { variant "BEGIN('curr:')"}
            
            type record SDP_attribute_des {
                charstring attr_value
            } with { variant "BEGIN('des:')"}
            
            type record SDP_attribute_conf {
                charstring attr_value
            } with { variant "BEGIN('conf:')"}
            
            type record SDP_attribute_rtpmap {
                charstring attr_value
            } with { variant "BEGIN('rtpmap:')"}
            
            type record SDP_attribute_rtcp {
                charstring attr_value
            } with { variant "BEGIN('rtcp:')"}
            
            type record SDP_attribute_rtcp_mux {
            } with { variant "BEGIN('rtcp-mux')"}
            
            type record SDP_attribute_max_size{
                integer max_size
            } with { variant "BEGIN('max-size:')"}
            
            type record of charstring SDP_url_list
              with { variant "SEPARATOR(' ')"}

            type record SDP_attribute_path {
                SDP_url_list path_list
            } with { variant "BEGIN('path:')"}
            
            type record of charstring SDP_media_type_list
              with { variant "SEPARATOR(' ')"}

            type record SDP_attribute_accept_types {
                SDP_media_type_list attr_value
            } with { variant "BEGIN('accept-types:')"}

            type record SDP_attribute_accept_wd_types {
                SDP_media_type_list attr_value
            } with { variant "BEGIN('accept-wrapped-types:')"}

            type record SDP_attribute_maxprate{
                integer prate_integer_part,
                integer prate_fraction_part optional
            } with { variant "BEGIN('maxprate:')";
                     variant "SEPARATOR('.')";}

            type record SDP_attribute_mid {
                charstring id_tag
            } with { variant "BEGIN('mid:')"}

            type record of charstring SDP_id_tag_list
              with { variant "SEPARATOR(' ')"}

            type record SDP_attribute_group {
                charstring semantics,
                SDP_id_tag_list id_tag optional
            } with { variant "BEGIN('group:')";
                     variant "SEPARATOR(' ')";}

            type record SDP_attribute_unknown {
                charstring name,
                charstring attr_value optional
            } with { variant "SEPARATOR(':')";
                     variant (attr_value) "TEXT_CODING(,,'[^\n]#(,)')"}
            
            type record SDP_attribute_file_selector {
                charstring attr_value
            } with { variant "BEGIN('file-selector:')"}

			type record SDP_attribute_file_transfer_id {
                 charstring attr_value
            } with { variant "BEGIN('file-transfer-id:')"}

			type record SDP_attribute_inactive {
                          } with { variant "BEGIN('inactive')"}
                          
            type record SDP_attribute_setup {
                charstring attr_value
            } with { variant "BEGIN('setup:')"}

            type record SDP_attribute_connection {
                charstring attr_value
            } with { variant "BEGIN('connection:')"}

            type record SDP_attribute_crypto {
                charstring attr_value
            } with { variant "BEGIN('crypto:')"}

      type record SDP_attribute_content {
        charstring attr_value
      } with { variant "BEGIN('content:')"}

      type record SDP_attribute_label {
        charstring attr_value
      } with { variant "BEGIN('label:')"}

      type record SDP_attribute_floorctrl {
        charstring attr_value
      } with { variant "BEGIN('floorctrl:')"}

      type record SDP_attribute_confid {
        charstring attr_value
      } with { variant "BEGIN('confid:')"}

      type record SDP_attribute_userid {
        charstring attr_value
      } with { variant "BEGIN('userid:')"}

      type record SDP_attribute_floorid {
        charstring attr_value
      } with { variant "BEGIN('floorid:')"}

      type record SDP_attribute_fingerprint {
        charstring attr_value
      } with { variant "BEGIN('fingerprint:')"}
        
      type record SDP_attribute_ice_ufrag {
        charstring attr_value
      } with { variant "BEGIN('ice-ufrag:')"}
      
     type record SDP_attribute_ice_pwd {
       charstring attr_value
     } with { variant "BEGIN('ice-pwd:')"}
     
     type record SDP_attribute_candidate {
       charstring      foundation,
       integer         component_id,
       charstring      transport,
       integer         priority,
       charstring      connection_address, 
       integer         connection_port,  
       charstring      candidate_type,
       charstring      rel_address optional,
       charstring      rel_port optional,
       SDP_extension_list  extensions optional          
     } with { variant "BEGIN('candidate:')";  
              variant "SEPARATOR(' ')";  
	      variant (candidate_type) "BEGIN('typ ')";
	      variant (rel_address) "BEGIN('raddr ')";
	      variant (rel_port) "BEGIN('rport ')";
	    } 
	       	          
      type set of SDP_extension SDP_extension_list with { variant "SEPARATOR(' ')"};
      
      type record SDP_extension 
      {
        charstring extension_attr_name,
        charstring extension_attr_value
      } with { variant "SEPARATOR(' ')"}     
	       	      	      
     type record SDP_attribute_ice_lite {       
     } with { variant "BEGIN('ice-lite')"}
     
     type record SDP_attribute_ice_mismatch {
      } with { variant "BEGIN('ice-mismatch')"}
  
     type record SDP_Remote_candidate
     {
       charstring     component_Id,
       charstring     connection_address,
       integer        portValue     
     } with { variant "SEPARATOR(' ')"} 
   
     type set of SDP_Remote_candidate SDP_Remote_candidate_list with { variant "SEPARATOR(' ')"};
      
     type record SDP_attribute_remote_candidate {
        SDP_Remote_candidate_list    attr_value    
     } with { variant "BEGIN('remote-candidates:')"}  
           
     type record of charstring SDP_ice_options_list
              with { variant "SEPARATOR(' ')"}
	      	      	      	      	      
     type record SDP_attribute_ice_options {
                SDP_ice_options_list attr_value
            } with { variant "BEGIN('ice-options:')"}

     type record SDP_attribute_rtcp_fb {
                charstring attr_value
            } with { variant "BEGIN('rtcp-fb:')"}
	    
     type record SDP_attribute_maxptime {	    
                charstring attr_value
            } with { variant "BEGIN('maxptime:')"}

     //ITU-T T.38: Procedures for real-time Group 3 fascimile communication over IP networks

     type record SDP_attribute_T38FaxVersion {	    
                integer attr_value
     } with { variant "BEGIN('T38FaxVersion:')"}
     
     type record SDP_attribute_T38MaxBitRate {	    
                integer attr_value
     } with { variant "BEGIN('T38MaxBitRate:')"} 
     
     type record SDP_attribute_T38FaxFillBitRemoval {	    
                integer attr_value
     } with { variant "BEGIN('T38FaxFillBitRemoval:')"} 
     
     type record SDP_attribute_T38FaxTranscodingMMR {	    
                integer attr_value
     } with { variant "BEGIN('T38FaxTranscodingMMR:')"} 
     
     type record SDP_attribute_T38FaxTranscodingJBIG {	    
                integer attr_value
     } with { variant "BEGIN('T38FaxTranscodingJBIG:')"}
     
     type record SDP_attribute_T38FaxRateManagement {	    
                charstring attr_value
     } with { variant "BEGIN('T38FaxRateManagement:')"}
     
     type record SDP_attribute_T38FaxMaxBuffer {	    
                integer attr_value
     } with { variant "BEGIN('T38FaxMaxBuffer:')"}
     
     type record SDP_attribute_T38FaxMaxDatagram   {	    
                integer attr_value
     } with { variant "BEGIN('T38FaxMaxDatagram:')"} 
     
     type record SDP_attribute_T38FaxMaxIFP {	    
                integer attr_value
     } with { variant "BEGIN('T38FaxMaxIFP:')"}
     
     type record SDP_attribute_T38FaxUdpEC  {	    
                charstring attr_value
     } with { variant "BEGIN('T38FaxUdpEC:')"} 
     
     type record SDP_attribute_T38FaxUdpECDepth  {
                integer minred,
                integer maxred optional
     } with { variant "BEGIN('T38FaxUdpECDepth:')"
              variant "SEPARATOR(' ')"
     }
     
     type record SDP_attribute_T38FaxUdpFECMaxSpam  {	    
                integer attr_value
     } with { variant "BEGIN('T38FaxUdpFECMaxSpan:')"} 
     
     type record SDP_attribute_T38VendorInfo {	    
                integer t35country_code,
                integer t35extension,
                integer manufacturer_code
     } with { variant "BEGIN('T38VendorInfo:')"
              variant "SEPARATOR(' ')"
     }
     
     type record SDP_attribute_T38ModemType  {	    
                charstring attr_value
            } with { variant "BEGIN('T38ModemType:')"}     
     

// RFC5547

     type record SDP_attribute_file_disposition  {	    
                charstring attr_value
     } with { variant "BEGIN('file-disposition:')"}     

     type record SDP_attribute_file_date  {	    
                charstring attr_value
     } with { variant "BEGIN('file-date:')"}     

     type record SDP_attribute_file_icon  {	    
                charstring attr_value
     } with { variant "BEGIN('file-icon:')"}     	    				               	                    	      	      	                                        
     type record SDP_attribute_file_range  {	    
                charstring attr_value
     } with { variant "BEGIN('file-range:')"}     

     type record SDP_attribute_sctpmap  {	    
                charstring attr_value
     } with { variant "BEGIN('sctpmap:')"}     
     
     type record SDP_attribute_sctp_port   {	    
                integer attr_value
     } with { variant "BEGIN('sctp_port:')"} 

     type record SDP_attribute_max_message_size   {	    
                integer attr_value
     } with { variant "BEGIN('max-message-size:')"} 

            type union SDP_attribute {
              SDP_attribute_cat               cat,
              SDP_attribute_keywds            keywds,
              SDP_attribute_tool              tool,
              SDP_attribute_ptime             ptime,
              SDP_attribute_recvonly          recvonly,
              SDP_attribute_sendrecv          sendrecv,
              SDP_attribute_sendonly          sendonly,
              SDP_attribute_orient            orient,
              SDP_attribute_type              sdp_type,
              SDP_attribute_charset           charset,
              SDP_attribute_sdplang           sdplang,
              SDP_attribute_lang              lang,
              SDP_attribute_framerate         framerate,
              SDP_attribute_quality           quality,
              SDP_attribute_fmtp              fmtp,
              SDP_attribute_curr              curr,
              SDP_attribute_des               des,
              SDP_attribute_conf              conf,
              SDP_attribute_rtpmap            rtpmap,
              SDP_attribute_rtcp              rtcp,
              SDP_attribute_max_size          max_size,
              SDP_attribute_path              path,
              SDP_attribute_accept_types      accept_types,
              SDP_attribute_accept_wd_types   accept_wrapped_types,
              SDP_attribute_maxprate          maxprate,
              SDP_attribute_mid               mid,
              SDP_attribute_group             group_attr,
              SDP_attribute_file_selector     file_selector,
              SDP_attribute_file_transfer_id  file_transfer_id,
              SDP_attribute_inactive          inactive,
              SDP_attribute_setup             setup,
              SDP_attribute_connection        connection,
              SDP_attribute_crypto            crypto,
              SDP_attribute_content           content,
              SDP_attribute_label             attr_label,
              SDP_attribute_floorctrl         floorctrl,
              SDP_attribute_confid            confid,
              SDP_attribute_userid            userid,
              SDP_attribute_floorid           floorid,
              SDP_attribute_fingerprint       fingerprint,
              SDP_attribute_ice_ufrag         ice_ufrag,
              SDP_attribute_ice_pwd           ice_pwd,
	      SDP_attribute_candidate         candidate,
	      SDP_attribute_ice_lite          ice_lite, 
	      SDP_attribute_ice_mismatch      ice_mismatch,
	      SDP_attribute_remote_candidate  remote_candidate,
	      SDP_attribute_ice_options       ice_options,
	      SDP_attribute_rtcp_fb           rtcp_fb, 
              SDP_attribute_maxptime          maxptime,

              SDP_attribute_T38FaxVersion         t38_version,
              SDP_attribute_T38MaxBitRate         t38_bit_rate,
              SDP_attribute_T38FaxFillBitRemoval  t38_fill_bit_removal,
              SDP_attribute_T38FaxTranscodingMMR  t38_transcoding_mmr,
              SDP_attribute_T38FaxTranscodingJBIG t38_transcoding_jbig,
              SDP_attribute_T38FaxRateManagement  t38_rate_management,
              SDP_attribute_T38FaxMaxBuffer       t38_max_buffer,
              SDP_attribute_T38FaxMaxDatagram     t38_max_datagram,
              SDP_attribute_T38FaxMaxIFP          t38_max_ifp,
              SDP_attribute_T38FaxUdpEC           t38_udp_ec,
              SDP_attribute_T38FaxUdpECDepth      t38_udp_ec_depth,
              SDP_attribute_T38FaxUdpFECMaxSpam   t38_udp_fec_max_spam,
              SDP_attribute_T38VendorInfo         t38_vendor_info,
              SDP_attribute_T38ModemType          t38_modem_type,
              
              SDP_attribute_file_disposition  file_disposition,
              SDP_attribute_file_date         file_date,
              SDP_attribute_file_icon         file_icon,
              SDP_attribute_file_range        file_range,
              
              SDP_attribute_sctpmap           sctpmap,
              SDP_attribute_sctp_port         sctp_port,
              SDP_attribute_max_message_size  max_message_size,
              SDP_attribute_rtcp_mux          rtcp_mux,  
                // unknown has to be the last else encoding/decoding won't work!
                SDP_attribute_unknown unknown
            } with {variant "BEGIN('a='), END('\r\n','(\r\n)|[\n]')"}
        } // group AttributeTypes
            
      type set of SDP_attribute SDP_attribute_list;

      type set of SDP_bandwidth SDP_bandwidth_list;

      type record SDP_bandwidth {
        charstring          modifier,
        integer             bandwidth
      } with { variant "BEGIN('b='), END('\r\n','(\r\n)|[\n]'), SEPARATOR(':')";}
      
      type record SDP_connection{
        charstring          net_type,
        charstring          addr_type,
		SDP_conn_addr		conn_addr
      } with { variant "BEGIN('c='), END('\r\n','(\r\n)|[\n]'), SEPARATOR(' ')";}

      type record SDP_conn_addr {
	  	charstring addr,
		integer ttl optional,
		integer num_of_addr optional
	  } with { variant "SEPARATOR('/')"}

      type set of SDP_connection SDP_connection_list;

      type record SDP_contact {
        charstring          addr_or_phone,
        charstring          disp_name optional
      } with {variant "END('\r\n','(\r\n)|[\n]')"}

      type SDP_contact SDP_contact_tel with {variant "BEGIN('p=')"}

      type SDP_contact SDP_contact_email with {variant "BEGIN('e=')"}
      
      type set of SDP_contact_email SDP_email_list;

      type record of charstring SDP_fmt_list with { variant "SEPARATOR(' ')"};

      type record SDP_key {
        charstring          method,
        charstring          key optional
      } with { variant "BEGIN('k='), END('\r\n','(\r\n)|[\n]'), SEPARATOR(':')";
               variant (key) "TEXT_CODING(,,'[^\n]#(,)')"}

      type record SDP_media_desc {
        SDP_media_field     media_field,
        charstring          information optional,
        SDP_connection_list connections optional,
        SDP_bandwidth_list  bandwidth optional,
        SDP_key             key optional,
        SDP_attribute_list  attributes optional
      } with { variant (information) "BEGIN('i='), END('\r\n','(\r\n)|[\n]')";}

      type set of SDP_media_desc SDP_media_desc_list;

      type record SDP_media_port {
        integer             port_number,
        integer             num_of_ports optional
      } with {variant "SEPARATOR('/')"}

      type record SDP_media_field{
        charstring          media,
        SDP_media_port      ports,
        charstring          transport,
        SDP_fmt_list        fmts
      } with { variant "BEGIN('m='), END('\r\n','(\r\n)|[\n]'), SEPARATOR(' ')"}

      type record SDP_time{
        SDP_time_field      time_field,
        SDP_repeat_list     time_repeat optional		
      }

      type record SDP_time_field{
      // due to the limitation of integer value a charstring shall be used
      // to represent 32 bit long unsigned int
        charstring   start_time,
        charstring   stop_time
      } with { variant "BEGIN('t='), END('\r\n','(\r\n)|[\n]'), SEPARATOR(' ')";}

      type record SDP_repeat{
        SDP_typed_time      repeat_interval,
        SDP_typed_time      active,
        SDP_typed_time_list offsets
      } with { variant "BEGIN('r='), END('\r\n','(\r\n)|[\n]'), SEPARATOR(' ')";}

      type set of SDP_repeat SDP_repeat_list with { variant "SEPARATOR(' ')"};

      type record SDP_typed_time{
        integer        time,
        charstring     unit optional
      } with { variant (time) "TEXT_CODING(,,'[\-]#(,1)[\d]#(1,)')"}
      
      type set of SDP_typed_time SDP_typed_time_list;

      type set of SDP_time SDP_time_list;

      type record SDP_timezone{
        charstring          adjustment_time,
        SDP_typed_time      offset
      } with { variant "SEPARATOR(' ')"}

      type set of SDP_timezone SDP_timezone_list 
        with { variant "BEGIN('z='), END('\r\n','(\r\n)|[\n]'), SEPARATOR(' ')";};

      type record SDP_Origin{
        charstring          user_name,
// the following 2 fields are numeric strings that may not fit into 32-bit signed int
        charstring          session_id,
        charstring          session_version,
        charstring          net_type,
        charstring          addr_type,
        charstring          addr
      } with { variant "BEGIN('o='), END('\r\n','(\r\n)|[\n]'), SEPARATOR(' ')";}
      type set of SDP_contact_tel SDP_phone_list;
    } // group SubTypes
    
    group MessageTypes
    {
      type record SDP_Message{
        integer             protocol_version,
        SDP_Origin          origin,
        charstring          session_name,
        charstring          information optional,
        charstring          uri optional,
        SDP_email_list      emails optional,
        SDP_phone_list      phone_numbers optional,
        SDP_connection      connection optional,
        SDP_bandwidth_list  bandwidth optional,
        SDP_time_list       times,
        SDP_timezone_list   timezone_adjustments optional,
        SDP_key             key optional,
        SDP_attribute_list  attributes optional,
        SDP_media_desc_list media_list optional
      } with { variant "TEXT_CODING()";
               variant (protocol_version) "BEGIN('v='), END('\r\n','(\r\n)|[\n]')";
               variant (session_name) "BEGIN('s='), END('\r\n','(\r\n)|[\n]')";
               variant (information) "BEGIN('i='), END('\r\n','(\r\n)|[\n]')";
               variant (uri) "BEGIN('u='), END('\r\n','(\r\n)|[\n]')";}
    } // group MessageTypes
  } // group Types


  // crypto attribute according to the RFC4568
  type record SRTP_Crypto{
    charstring            tag,
    charstring            crypto_suite,
    Crypto_Key_Params     key_params,
    Crypto_Session_Params session_params optional
  } with {
    variant "SEPARATOR(' ')"
  }
  
  type record of Crypto_Key_Param Crypto_Key_Params 
  with {
    variant "SEPARATOR(';')"
  }
  
  type record Crypto_Key_Param{
    charstring           key_method,
    charstring           key_salt,
    charstring           lifetime optional,
    charstring           mki_value optional,
    charstring           mki_length optional
  } with {
    variant (key_method) "END(':')";
    variant (key_salt) "TEXT_CODING(,,'[a-zA-Z0-9+/=]#(1,)')";
    variant (lifetime) "BEGIN('|'), TEXT_CODING(,,'2^[0-9]#(1,)')";
    variant (mki_value) "BEGIN('|'), END(':')"
  }

  type record of Crypto_Session_Param Crypto_Session_Params
  with {
    variant "SEPARATOR(' ')"
  }

  type record Crypto_Session_Param{
    charstring           param_name,
    charstring           param_value optional
  } with {
    variant "SEPARATOR('=')"
  }


} with {encode "TEXT"}

