///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Copyright Test Competence Center(TCC) ETH 2003                            //
//                                                                           //
// The copyright to the computer program(s) herein is the property of TCC.   //
// The program(s) may be used and/or copied only with the written permission //
// of TCC or in accordance with the terms and conditions stipulated in the   //
// agreement/contract under which the program(s) has been supplied.          //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
//
// File: ROHC_Types.ttcn
// Description: ROHC
// Rev: R3A01
// Prodnr: CNL 113 426
// Updated: 2006.04.13
// Contact: http://ttcn.ericsson.se
//

/* Based on RFC 3095, July 2001 */

/* TODO: improvements::
- Profile4_Dynamic_Chain_u should not contain the sn field

ethesi */

module ROHC_Types
{
import from General_Types all;

external function f_ROHC_enc(in ROHC_packet_u pdu, in ROHC_config p_config)
return octetstring;
external function f_ROHC_dec(in octetstring data, inout ROHC_config p_config)
return ROHC_packet_u;
external function f_ROHC_CRC(in octetstring data, in integer crclen)
return integer;
external function f_FBCK_enc(in Feedback_data pdu, in ROHC_config p_config)
return octetstring;
external function f_FBCK_dec(in octetstring data, in ROHC_config p_config)
return Feedback_data;

/* Constants for ROHC mode field values including mode cancellation */
const integer cg_ROHC_mode_C := 0;
const integer cg_ROHC_mode_U := 1;
const integer cg_ROHC_mode_O := 2;
const integer cg_ROHC_mode_R := 3;

/* Constants for ROHC feedback type */
const integer cg_ROHC_fbck_type_ACK := 0;
const integer cg_ROHC_fbck_type_NACK := 1;
const integer cg_ROHC_fbck_type_SNACK := 2;
const integer cg_ROHC_fbck_type_reserved := 3;

type bitstring ROHC_BIT7_BO_LAST length (7) with {variant "BYTEORDER(last)"};

type enumerated Packet_type { R_0(0), R_0_CRC(1), UO_0(2), R_1(3), R_1_ID(4),
  R_1_TS(5), UO_1(6), UO_1_ID(7), UO_1_TS(8), UOR_2(9), UOR_2_ID(10),
  UOR_2_TS(11), IR(12), IR_DYN(13), NOPKT(14) };

/* ==================== ROHC configuration and context ==================== */

  type record IP_context {
    /* Version of this IP level. MSB bit may be set (Profile 4 only). */
    integer version,
    /* RND bit of this IP level (RND or RND2) */
    boolean rnd_bit,
    /* Whether AH is present in the IPX index list */
    boolean ah_present,
    /* Whether GRE is present in the IPX index list */
    boolean gre_present,
    /* Whether ESP is present in the IPX index list */
    boolean esp_present,
    /* Length of the compressed AH data field after the base header */
    integer ah_data_len,
    /* Whether GRE header has GRE checksum or not */
    boolean gre_cksum_present
  };
  
  type record UDP_context {
    boolean udp_cksum
  };
  
  type record of IP_context IP_contexts;  
  
  type record ROHC_context {
      integer mode,
      integer profile,
      /* The decoded packet type */
      Packet_type pkt,
      IP_contexts ip_ctx,
      UDP_context udp_ctx
  };

  type record of integer int_array;

  type record of ROHC_context ROHC_context_rof;

  type record ROHC_config {
      boolean large_cid,
      int_array rtp_ports,
      ROHC_context_rof context
  };

  type port ROHC_ASP_SP_PT message
  {
    inout ROHC_packet_u; 
    inout octetstring;
  } with { extension "internal" }

  
  /* ROHC Configuration port */
  type record ROHC_ROHCCFG_REQ_setconfig 
  {
    ROHC_config config
  }

  type enumerated ROHC_ROHCCFG_REQ_operation { rohccfg_getconfig }
  
  type union ROHC_ROHCCFG_REQ 
  {
    ROHC_ROHCCFG_REQ_operation simpleop,
    ROHC_ROHCCFG_REQ_setconfig setconfig
  }
  
  type enumerated ROHC_ROHCCFG_RSP_operation { rohccfg_ok }

  type record ROHC_ROHCCFG_RSP_config 
  {
    ROHC_config config
  }
  
  type union ROHC_ROHCCFG_RSP
  {
    ROHC_ROHCCFG_RSP_operation simpleop,
    ROHC_ROHCCFG_RSP_config config
  }
  
  type port ROHC_PORTCFG_PT message
  {
    inout ROHC_config;
    inout charstring;
    inout ROHC_ROHCCFG_REQ;
    inout ROHC_ROHCCFG_RSP;
  } with { extension "internal" }

  type union ROHC_packet_u
  {
    ROHC_packet rohc,
    Segment_packet segment
  }

  type record ROHC_packet /* p.42 */
  {
    Padding padding optional,
    Feedback feedback optional,
    Header header,
    Payload payload optional
  };

/* TODO CHECK: why this is needed ?
type record Reconstructed_unit
{
 octetstring reconstructed_packet,
 OCT4 CRC
}; */

  type record Segment_packet /* p.50 */
  {
    Padding padding optional,
    Feedback feedback optional,
    INT7b segment_header_id, /* Must be 127 (0x7F) */
    boolean final,
    Payload payload optional,
    integer crc optional
  };

  type octetstring Padding; /* Must be a serie of 0xE0 */
  type octetstring Payload;

  type OCT1n Feedback1; /* p.91 */

  type record Feedback_opts_u /* p.91 */
  {
    INT4b opt_type,
    INT4b opt_len,
    octetstring opt_data optional
  };

  type record of Feedback_opts_u Feedback_opts; /* p.91 */

  type record Feedback2 /* p.91 */
  {
    INT2b acktype,
    INT2b mode,
    INT12b_BO_LAST sn,
    Feedback_opts feedback_opts optional
  };

  type union Feedback_type /* p.46 */
  {
    Feedback1 feedback1,
    Feedback2 feedback2
  };

  type record Feedback_data /* p.46 */
  {
    INT14b_BO_LAST cid,
    Feedback_type feedback_type
  };

  type record Feedback_u /* p.45 */
  {
    BIT5 feedback_type, /* Must be '11110'B */
    INT3b code,
    LIN1 size optional,
    /* TODO: size could be 0, so feedback_data should be optional;
      although it's a weird case, but still possible */
    Feedback_data feedback_data
  };

  type record of Feedback_u Feedback; /* p.42 */

  type union Header /* p.77 */
  {
    Profile0_headers prof0,
    Profile1_headers prof1,
    Profile2_headers prof2,
    Profile4_headers prof4
  };

  //Profile0

  type union Profile0_headers
  {
    Profile0_IR_packet ir,
    Profile0_normal_packet normal
  };

  type record Profile0_IR_packet /* p.127 */
  {
    INT14b_BO_LAST cid,
    BIT7 type_ind, /* Must be '1111110'B */
    BIT1 d, /* Must be 0 */
    LIN1 profile, /* Must be 0 */
    LIN1 crc,
    octetstring orig_packet
  };

  type record Profile0_normal_packet /* p.128 */
  {
    INT14b_BO_LAST cid,
    octetstring orig_packet
  };

  //Profile1

  type record Profile1_headers /* p.77 */
  {
    Profile1_base_header base_header,
    Profile1_Extension ext optional,
    LIN2_BO_LAST ip_id_outer optional,
    octetstring ah_outer optional,
    LIN2_BO_LAST gre_cksum1 optional,
    LIN2_BO_LAST ip_id_inner optional,
    octetstring ah_inner optional,
    LIN2_BO_LAST gre_cksum2 optional,
    LIN2_BO_LAST udp_cksum optional
  };

  type union Profile1_base_header
  {
    Profile1_IR_header ir,
    Profile1_IR_DYN_header ir_dyn,
    Profile1_R_0_header r_0,
    Profile1_R_0_CRC_header r_0_crc,
    Profile1_UO_0_header uo_0,
    Profile1_R_1_header r_1,
    Profile1_R_1_ID_header r_1_id,
    Profile1_R_1_TS_header r_1_ts,
    Profile1_UO_1_header uo_1,
    Profile1_UO_1_ID_header uo_1_id,
    Profile1_UO_1_TS_header uo_1_ts,
    Profile1_UOR_2_header uor_2,
    Profile1_UOR_2_ID_header uor_2_id,
    Profile1_UOR_2_TS_header uor_2_ts
  };

  type union Static_Chain_u /* p.91 */
  {
    IPv4_Static ipv4_stat,
    IPv6_Static ipv6_stat,
    UDP_Static udp_stat,
    RTP_Static rtp_stat,
    ESP_Static esp_stat
  };

  type union Dynamic_Chain_u /* p.91 */
  {
    IPv4_Dynamic ipv4_dyn,
    IPv6_Dynamic ipv6_dyn,
    UDP_Dynamic udp_dyn,
    RTP_Dynamic rtp_dyn,
    ESP_Dynamic esp_dyn
  };

  type record of Static_Chain_u Static_Chain; /* p.91 */

  type record of Dynamic_Chain_u Dynamic_Chain; /* p.91 */

  type record Profile1_IR_header /* p.45 */ /* p.91 */
  {
    INT14b_BO_LAST cid,
    BIT7 type_ind, /* Must be '1111110'B */
    BIT1 d,
    LIN1 profile, /* Must be 1 */
    LIN1 crc,
    Static_Chain stat_chain,
    Dynamic_Chain dyn_chain optional
  };

  type record Profile1_IR_DYN_header /* p.46 */ /* p.92 */
  {
    INT14b_BO_LAST cid,
    BIT8 type_ind, /* Must be '11111000'B */
    LIN1 profile, /* Must be 1 */
    LIN1 crc,
    Dynamic_Chain dyn_chain
  };

  type record Profile1_R_0_header /* p.74 */
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '00'B */
    INT6b sn
  };

  type record Profile1_R_0_CRC_header /* p.74 */
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '01'B */
    INT7b sn,
    INT7b crc
  };

  type record Profile1_UO_0_header /* p.75 */
  {
    INT14b_BO_LAST cid,
    BIT1 type_ind, /* Must be '0'B */
    INT4b sn,
    INT3b crc
  };

  type record Profile1_R_1_header /* p.75 */
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '10'B */
    INT6b sn,
    BIT1 m_bit,
    BIT1 x_bit,
    INT6b ts
  };

  type record Profile1_R_1_ID_header /* p.75 */
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '10'B */
    INT6b sn,
    BIT1 m_bit,
    BIT1 x_bit,
    BIT1 t_bit, /* Must be '0'B */
    INT5b ip_id
  };

  type record Profile1_R_1_TS_header /* p.75 */
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '10'B */
    INT6b sn,
    BIT1 m_bit,
    BIT1 x_bit,
    BIT1 t_bit, /* Must be '1'B */
    INT5b ts
  };

  type record Profile1_UO_1_header /* p.76 */
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '10'B */
    INT6b ts,
    BIT1 m_bit,
    INT4b sn,
    INT3b crc
  };

  type record Profile1_UO_1_ID_header /* p.76 */
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '10'B */
    BIT1 t_bit, /* Must be '0'B */
    INT5b ip_id,
    BIT1 x_bit,
    INT4b sn,
    INT3b crc
  };

  type record Profile1_UO_1_TS_header /* p.76 */
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '10'B */
    BIT1 t_bit, /* Must be '1'B */
    INT5b ts,
    BIT1 m_bit,
    INT4b sn,
    INT3b crc
  };

  type record Profile1_UOR_2_header /* p.77 */
  {
    INT14b_BO_LAST cid,
    BIT3 type_ind, /* Must be '110'B */
    INT6b ts,
    BIT1 m_bit,
    INT6b sn,
    BIT1 x_bit,
    INT7b crc
  };

  type record Profile1_UOR_2_ID_header /* p.77 */
  {
    INT14b_BO_LAST cid,
    BIT3 type_ind, /* Must be '110'B */
    INT5b ip_id,
    BIT1 t_bit, /* Must be '0'B */
    BIT1 m_bit,
    INT6b sn,
    BIT1 x_bit,
    INT7b crc
  };

  type record Profile1_UOR_2_TS_header /* p.77 */
  {
    INT14b_BO_LAST cid,
    BIT3 type_ind, /* Must be '110'B */
    INT5b ts,
    BIT1 t_bit, /* Must be '1'B */
    BIT1 m_bit,
    INT6b sn,
    BIT1 x_bit,
    INT7b crc
  };

  type record Short_Seqnum /* p.120 */
  {
    BIT1 ind, /* Must be '0'B */
    INT7b lsb_of_seqnum
  };

  type record Long_Seqnum /* p.120 */
  {
    BIT1 ind, /* Must be '1'B */
    INT31b_BO_LAST lsb_of_seqnum
  };

  type union AEGSeqnum /* p.112 */
  {
    Short_Seqnum short_form,
    Long_Seqnum long_form
  };

  type record XI_Item4_r /* p.121 */
  {
    BIT1 x_ind,
    INT3b index
  };

  type record XI_Item8_r /* p.121 */
  {
    BIT1 x_ind,
    INT7b index
  };

  type record of XI_Item4_r XI_Item4;

  type record of XI_Item8_r XI_Item8;

  type union XI_list /* p.113 */
  {
    XI_Item4 xi_item4,
    XI_Item8 xi_item8
  };

  type record IPv6_ext_item
  {
    LIN1 nexthead,
    LIN1 hdr_ext_len,
    octetstring data
  }

  type record MINE_item {
    LIN1 protocol,
    BIT1 s_bit,
    ROHC_BIT7_BO_LAST reserved,
    LIN2_BO_LAST cksum,
    OCT4 dstaddr,
    OCT4 srcaddr optional
  } with { 
    variant "FIELDORDER(msb)"; 
    variant (srcaddr)  "PRESENCE(s_bit = '1'B)";
  }

/* TODO: check why better use INTn intead of OCTn */
  type record AH_item /* RFC 2402, p.3 */
  {
    LIN1 nexthead, /* Must be 51 */
    LIN1 payload_len,
    LIN2_BO_LAST reserved, /* Must be 0 */
    LIN4_BO_LAST spi,
    LIN4_BO_LAST sn,
    octetstring auth_data optional
  }

  type record ESP_item
  {
    LIN1 nexthead, /* Must be 50 */
    LIN4_BO_LAST spi,
    LIN4_BO_LAST sn
  }

  type record GRE_item
  {
    LIN1 nexthead, /* Must be 47 */
    BIT1 C_bit,
    BIT1 reserved_1, /* Must be '0'B */
    BIT1 K_bit,
    BIT1 S_bit,
    BIT1 reserved_2, /* Must be '0'B */
    BIT3 version,
    LIN2_BO_LAST cksum optional,
    LIN4_BO_LAST key optional,
    LIN4_BO_LAST sn optional
  }

  type union Item
  {
    IPv6_ext_item ipv6_ext_item,
    AH_item ah_item,
    ESP_item esp_item,
    GRE_item gre_item,
    MINE_item mine_item
/* TODO CHECK: could we use it ?
    octetstring any_item */
  }

  type record of Item IP_Item_list;

  type record of OCT4n CSRC_Item_list;
  
  /* TODO: temporary solution for profile4 tests */
  type record of octetstring RAW_data;

  type union Item_list
  {
    CSRC_Item_list csrc_item_list,
    IP_Item_list ip_item_list,
    /* TODO: temporary solution for profile4 tests */
    RAW_data raw_data
  }

  type record Enc_Type_0 /* p.112 */
  {
    BIT2 et, /* Must be '00'B */
    BIT1 gp_bit,
    BIT1 ps_bit,
    INT4b cc,
    LIN1 gen_id optional,
    XI_list xi_list optional,
    BIT4 padding optional, /* Must be '0000'B */
    Item_list item_list optional
  };

  type record Enc_Type_1 /* p.114 */
  {
    BIT2 et, /* Must be '01'B */
    BIT1 gp_bit,
    BIT1 ps_bit,
    INT4b xi1,
    LIN1 gen_id optional,
    LIN1 ref_id,
    octetstring insbitmask,
    XI_list xi_list optional,
    BIT4 padding optional, /* Must be '0000'B */
    Item_list item_list optional
  };

  type record Enc_Type_2 /* p.115 */
  {
    BIT2 et, /* Must be '10'B */
    BIT1 gp_bit,
    BIT1 res,
    INT4b count,
    LIN1 gen_id optional,
    LIN1 ref_id,
    octetstring rembitmask
  };

  type record Enc_Type_3 /* p.115 */
  {
    BIT2 et, /* Must be '11'B */
    BIT1 gp_bit,
    BIT1 ps_bit,
    INT4b xi1,
    LIN1 gen_id optional,
    LIN1 ref_id,
    octetstring rembitmask,
    octetstring insbitmask,
    XI_list xi_list optional,
    BIT4 padding optional, /* Must be '0000'B */
    Item_list item_list optional
  };

  type record IPv4_Static /* p.94 */
  {
    INT4b version, /* Must be '0100'B */
    INT4b reserved, /* Must be '0000'B */
    LIN1 proto,
    OCT4 srcaddr,
    OCT4 dstaddr
  };

  type record IPv4_Dynamic /* p.94 */
  {
    LIN1 tos,
    LIN1 ttl,
    LIN2_BO_LAST identification,
    BIT1 df_bit,
    BIT1 rnd_bit,
    BIT1 nbo_bit,
    BIT5 reserved, /* Must be '00000'B */
    Enc_Type_0 genextheadlist
  };
  
  type record IPv6_Static /* p.93 */
  {
    INT4b version, /* Must be '0110'B */
    INT20b_BO_LAST flowlabel,
    LIN1 nexthead,
    OCT16 srcaddr,
    OCT16 dstaddr
  };

  type record IPv6_Dynamic /* p.93 */
  {
    LIN1 trafficclass,
    LIN1 hoplimit,
    Enc_Type_0 genextheadlist
  };

  type record UDP_Static /* p.95 */
  {
    LIN2_BO_LAST srcport,
    LIN2_BO_LAST dstport
  };

  type record UDP_Dynamic /* p.95 */
  {
    LIN2_BO_LAST cksum
  };

  type record RTP_Static /* p.96 */
  {
    OCT4 ssrc
  };

  type record Rx_Field /* p.96 */
  {
    BIT3 reserved, /* Must be '000'B */
    BIT1 xbit,
    INT2b mode,
    BIT1 tisbit,
    BIT1 tssbit
  };

  type record RTP_Dynamic /* p.96 */
  {
    INT2b vfield, /* Must be '10'B */
    BIT1 pbit,
    BIT1 rxbit,
    INT4b ccfield,
    BIT1 mbit,
    INT7b ptfield,
    LIN2_BO_LAST rtpseqnum,
    LIN4_BO_LAST rtpts,
    Enc_Type_0 gencsrclist,
    Rx_Field rx_field optional,
    integer ts_stride optional,
    integer time_stride optional
  };

  type record ESP_Static /* p.97 */
  {
    LIN4_BO_LAST spi
  };

  type record ESP_Dynamic /* p.97 */
  {
    LIN4_BO_LAST seqnum
  };

  type union Compr_head_list /* p.112 */
  {
    Enc_Type_0 enctype0,
    Enc_Type_1 enctype1,
    Enc_Type_2 enctype2,
    Enc_Type_3 enctype3
  };
  
  type record IP_Ext_heads /* p.111 */
  {
    BIT1 cl,
    BIT1 aseq,
    BIT1 eseq,
    BIT1 gseq,
    BIT4 res,
    AEGSeqnum ah_seq optional,
    AEGSeqnum esp_seq optional,
    AEGSeqnum gre_seq optional,
    Compr_head_list compr_head_list optional
  };

  type record Outer_IP_fields /* p.82 */
  {
    LIN1 tos optional,
    LIN1 ttl optional,
    LIN1 proto optional,
    IP_Ext_heads ext_heads optional,
    LIN2_BO_LAST ip_id optional
  };

  type record Outer_IP_flags /* p.81 */
  {
    BIT1 tos2,
    BIT1 ttl2,
    BIT1 df2,
    BIT1 pr2,
    BIT1 ipx2,
    BIT1 nbo2,
    BIT1 rnd2,
    BIT1 i2_bit
  };

  type record Inner_IP_fields /* p.81 */
  {
    LIN1 tos optional,
    LIN1 ttl optional,
    LIN1 proto optional,
    IP_Ext_heads ext_heads optional
  };

  type record Inner_IP_flags /* p.80 */
  {
    BIT1 tos,
    BIT1 ttl,
    BIT1 df,
    BIT1 pr,
    BIT1 ipx,
    BIT1 nbo,
    BIT1 rnd_bit,
    BIT1 ip2_bit
  };

  type record RTP_flags
  {
    BIT1 r_p,
    INT7b rtp_pt
  }

  type record RTP_flags_fields /* p.82 */
  {
    INT2b mode,
    BIT1 r_pt,
    BIT1 m_bit,
    BIT1 r_x,
    BIT1 csrc,
    BIT1 tss,
    BIT1 tis,
    RTP_flags flags optional,
    Compr_head_list csrc_list optional,
    integer ts_stride optional,
    integer time_stride optional
  }

  type record Extension0 /* p.79 */
  {
    BIT2 ext_type, /* Must be '00'B */
    INT3b sn,
    INT3b plust
  }

  type record Extension1 /* p.79 */
  {
    BIT2 ext_type, /* Must be '01'B */
    INT3b sn,
    INT3b plust,
    LIN1 minust
  };

  type record Extension2 /* p.79 */
  {
    BIT2 ext_type, /* Must be '10'B */
    INT3b sn,
    INT11b_BO_LAST plust,
    LIN1 minust
  };

  type record Extension3 /* p.79 */
  {
    BIT2 ext_type, /* Must be '11'B */
    BIT1 s_bit,
    BIT1 r_ts_bit,
    BIT1 tsc_bit,
    BIT1 i_bit,
    BIT1 ip_bit,
    BIT1 rtp_bit,
    Inner_IP_flags inner_ip_flags optional,
    Outer_IP_flags outer_ip_flags optional,
    LIN1 sn optional,
    integer ts optional,
    /* This field contains the length of the SDVL encoded TS value counted in
      octets. */
    integer ts_length optional,
    Inner_IP_fields inner_ip_hdr optional,
    LIN2_BO_LAST ip_id optional,
    Outer_IP_fields outer_ip_hdr optional,
    RTP_flags_fields rtp_fl_fi optional
  };

  type union Profile1_Extension /* p.79 */
  {
    Extension0 ext0,
    Extension1 ext1,
    Extension2 ext2,
    Extension3 ext3
  };

  //Profile2

  type record Profile2_headers /* p.77 */
  {
    Profile2_base_header base_header,
    Profile2_Extension ext optional,
    LIN2_BO_LAST ip_id_outer optional,
    octetstring ah_outer optional,
    LIN2_BO_LAST gre_cksum1 optional,
    LIN2_BO_LAST ip_id_inner optional,
    octetstring ah_inner optional,
    LIN2_BO_LAST gre_cksum2 optional,
    LIN2_BO_LAST udp_cksum optional
  };

  type union Profile2_base_header
  {
    Profile2_IR_header ir,
    Profile2_IR_DYN_header ir_dyn,
    Profile1_R_0_header r_0,
    Profile1_R_0_CRC_header r_0_crc,
    Profile1_UO_0_header uo_0,
    Profile2_R_1_header r_1,
    Profile2_UO_1_header uo_1,
    Profile2_UOR_2_header uor_2
  };

  type union Profile2_Static_Chain_u
  {
    IPv4_Static ipv4_stat,
    IPv6_Static ipv6_stat,
    UDP_Static udp_stat
  };

  type record Profile2_UDP_Dynamic
  {
    LIN2_BO_LAST cksum,
    LIN2_BO_LAST udp_sn
  };

  type union Profile2_Dynamic_Chain_u
  {
    IPv4_Dynamic ipv4_dyn,
    IPv6_Dynamic ipv6_dyn,
    Profile2_UDP_Dynamic udp_dyn
  };

  type record of Profile2_Static_Chain_u Profile2_Static_Chain;

  type record of Profile2_Dynamic_Chain_u Profile2_Dynamic_Chain;

  type record Profile2_IR_header
  {
    INT14b_BO_LAST cid,
    BIT7 type_ind, /* Must be '1111110'B */
    BIT1 d,
    LIN1 profile, /* Must be 2 */
    LIN1 crc,
    Profile2_Static_Chain stat_chain,
    Profile2_Dynamic_Chain dyn_chain optional
  };

  type record Profile2_IR_DYN_header /* p.46 */ /* p.92 */
  {
    INT14b_BO_LAST cid,
    BIT8 type_ind, /* Must be '11111000'B */
    LIN1 profile, /* Must be 2 */
    LIN1 crc,
    Profile2_Dynamic_Chain dyn_chain
  };

  type record Profile2_R_1_header
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '10'B */
    INT6b sn,
    BIT1 x_bit,
    INT7b ip_id
  };

  type record Profile2_UO_1_header
  {
    INT14b_BO_LAST cid,
    BIT2 type_ind, /* Must be '10'B */
    INT6b ip_id,
    INT5b sn,
    INT3b crc
  };

  type record Profile2_UOR_2_header
  {
    INT14b_BO_LAST cid,
    BIT3 type_ind, /* Must be '110'B */
    INT5b sn,
    BIT1 x_bit,
    INT7b crc
  };

  type record Profile2_Inner_IP_flags
  {
    BIT1 tos,
    BIT1 ttl,
    BIT1 df,
    BIT1 pr,
    BIT1 ipx,
    BIT1 nbo,
    BIT1 rnd_bit,
    BIT1 reserved /* Must be '0'B */
  };

  type union Profile2_Extension
  {
    Profile2_Extension0 ext0,
    Profile2_Extension1 ext1,
    Profile2_Extension2 ext2,
    Profile2_Extension3 ext3
  };

  type record Profile2_Extension0
  {
    BIT2 ext_type, /* Must be '00'B */
    INT3b sn,
    INT3b ip_id
  }

  type record Profile2_Extension1
  {
    BIT2 ext_type, /* Must be '01'B */
    INT3b sn,
    INT11b_BO_LAST ip_id
  };

  type record Profile2_Extension2
  {
    BIT2 ext_type, /* Must be '10'B */
    INT3b sn,
    INT11b_BO_LAST ip_id2,
    LIN1 ip_id
  };

  type record Profile2_Extension3
  {
    BIT2 ext_type, /* Must be '11'B */
    BIT1 s_bit,
    INT2b mode,
    BIT1 i_bit,
    BIT1 ip_bit,
    BIT1 ip2_bit,
    Profile2_Inner_IP_flags inner_ip_flags optional,
    Outer_IP_flags outer_ip_flags optional,
    LIN1 sn optional,
    Inner_IP_fields inner_ip_hdr optional,
    LIN2_BO_LAST ip_id optional,
    Outer_IP_fields outer_ip_hdr optional
  };

  //Profile4

  type record Profile4_headers
  {
    Profile4_base_header base_header,
    Profile2_Extension ext optional,
    LIN2_BO_LAST ip_id_outer optional,
    octetstring ah_outer optional,
    LIN2_BO_LAST gre_cksum1 optional,
    LIN2_BO_LAST ip_id_inner optional,
    octetstring ah_inner optional,
    LIN2_BO_LAST gre_cksum2 optional,
    Profile4_Dynamic_Chain additional_IP optional
  };

  type union Profile4_base_header
  {
    Profile4_IR_header ir,
    Profile4_IR_DYN_header ir_dyn,
    Profile1_R_0_header r_0,
    Profile1_R_0_CRC_header r_0_crc,
    Profile1_UO_0_header uo_0,
    Profile2_R_1_header r_1,
    Profile2_UO_1_header uo_1,
    Profile2_UOR_2_header uor_2
  };

  type union Profile4_Static_Chain_u
  {
    IPv4_Static ipv4_stat,
    IPv6_Static ipv6_stat
  };
  
  type record Profile4_IPv4_Dynamic
  {
    LIN1 tos,
    LIN1 ttl,
    LIN2_BO_LAST identification,
    BIT1 df_bit,
    BIT1 rnd_bit,
    BIT1 nbo_bit,
    BIT1 sid_bit,
    BIT4 reserved, /* Must be '0000'B */
    Enc_Type_0 genextheadlist
  };

  type union Profile4_Dynamic_Chain_u
  {
    Profile4_IPv4_Dynamic ipv4_dyn,
    IPv6_Dynamic ipv6_dyn,
    LIN2_BO_LAST sn
  };

  type record of Profile4_Static_Chain_u Profile4_Static_Chain;

  type record of Profile4_Dynamic_Chain_u Profile4_Dynamic_Chain;

  type record Profile4_IR_header
  {
    INT14b_BO_LAST cid,
    BIT7 type_ind, /* Must be '1111110'B */
    BIT1 d,
    LIN1 profile, /* Must be 4 */
    LIN1 crc,
    Profile4_Static_Chain stat_chain,
    Profile4_Dynamic_Chain dyn_chain optional
  };

  type record Profile4_IR_DYN_header
  {
    INT14b_BO_LAST cid,
    BIT8 type_ind, /* Must be '11111000'B */
    LIN1 profile, /* Must be 4 */
    LIN1 crc,
    Profile4_Dynamic_Chain dyn_chain
  };

} with { encode "RAW" }

