ROHC compression/decompression library
Data Structures | Defines | Functions
c_generic.h File Reference

ROHC generic compression context for IP-only, UDP and UDP Lite profiles. More...

#include "rohc_comp_internals.h"
#include "rohc_packets.h"
#include "comp_list.h"
#include "ip.h"
#include <stdlib.h>
#include <netinet/ip.h>
Include dependency graph for c_generic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ipv4_header_info
 Store information about an IPv4 header between the different compressions of IP packets. More...
struct  ipv6_header_info
 Store information about an IPv6 header between the different compressions of IP packets. More...
struct  ip_header_info
 Store information about an IP (IPv4 or IPv6) header between the different compressions of IP packets. More...
struct  generic_tmp_vars
 Structure that contains variables that are used during one single compression of packet. More...
struct  c_generic_context
 The generic compression context. More...
struct  list_comp
 The list compressor. More...

Defines

#define IPID_MAX_DELTA   20
 The maximal delta accepted between two consecutive IPv4 ID so that it can be considered as coded in Network Byte Order (NBO)
#define MAX_ITEM   15
 The number of compression list items.
#define L   5

Functions

int c_generic_create (struct c_context *const context, const struct ip_packet *ip)
 Create a new context and initialize it thanks to the given IP packet.
void c_generic_destroy (struct c_context *const context)
 Destroy the context.
void change_mode (struct c_context *const context, const rohc_mode new_mode)
 Change the mode of the context.
void change_state (struct c_context *const context, const rohc_c_state new_state)
 Change the state of the context.
void ip6_c_init_table (struct list_comp *const comp)
 Initialize the tables IPv6 extension in compressor.
int rohc_list_decide_ipv6_compression (struct list_comp *const comp, const struct ip_packet *const ip)
 Decide whether list of IPv6 extension headers shall be sent compressed.
int c_create_current_list (const int index, struct list_comp *const comp, const unsigned char *ext, const int index_table)
 Create the current list.
int rohc_list_decide_type (struct list_comp *const comp)
 Decide the encoding type for compression list.
int rohc_list_encode (struct list_comp *const comp, unsigned char *const dest, int counter, const int ps, const int size)
 Generic encoding of compressed list.
int rohc_list_encode_type_0 (struct list_comp *const comp, unsigned char *const dest, int counter, const int ps)
 Build encoding type 0 for list compression.
int rohc_list_encode_type_1 (struct list_comp *const comp, unsigned char *const dest, int counter, const int ps)
 Build encoding type 1 for list compression.
int rohc_list_encode_type_2 (struct list_comp *const comp, unsigned char *const dest, int counter, const int ps)
 Build encoding type 2 for list compression.
int rohc_list_encode_type_3 (struct list_comp *const comp, unsigned char *const dest, int counter, const int ps)
 Build encoding type 3 for list compression.
int c_generic_encode (struct c_context *const context, const struct ip_packet *ip, const int packet_size, unsigned char *const dest, const int dest_size, rohc_packet_t *const packet_type, int *const payload_offset)
 Encode an IP packet according to a pattern decided by several different factors.
void c_generic_feedback (struct c_context *const context, const struct c_feedback *feedback)
 Update the profile when feedback arrives.
void decide_state (struct c_context *const context)
 Decide the state that should be used for the next packet.

Detailed Description

ROHC generic compression context for IP-only, UDP and UDP Lite profiles.

Author:
Didier Barvaux <didier.barvaux@toulouse.viveris.com>
The hackers from ROHC for Linux

Define Documentation

#define IPID_MAX_DELTA   20

The maximal delta accepted between two consecutive IPv4 ID so that it can be considered as coded in Network Byte Order (NBO)

Referenced by check_ip_identification().

#define L   5

The number of compressed list to send to make the reference list L is the name specified in the RFC

Referenced by rohc_list_decide_ipv6_compression().

#define MAX_ITEM   15

The number of compression list items.

Referenced by rohc_list_decide_ipv6_compression().


Function Documentation

int c_create_current_list ( const int  index,
struct list_comp *const  comp,
const unsigned char *  ext,
const int  index_table 
)

Create the current list.

Parameters:
compThe list compressor which is specific to the extension type
extThe extension
indexThe number of the extension
index_tableThe index of the item in the based table
Returns:
1 if successful, 0 otherwise

References list_comp::based_table, list_comp::compare, c_translation::counter, list_comp::counter, list_comp::create_item, list_comp::curr_list, delete_elt(), elt_index(), get_elt(), list_comp::get_size, list_elt::index_table, insert_elt(), list_elt::item, c_translation::known, rohc_list_item::length, push_back(), rohc_debugf, list_comp::trans_table, and rohc_list_item::type.

Referenced by rohc_list_decide_ipv6_compression().

int c_generic_create ( struct c_context *const  context,
const struct ip_packet ip 
)
void c_generic_destroy ( struct c_context *const  context)
int c_generic_encode ( struct c_context *const  context,
const struct ip_packet ip,
const int  packet_size,
unsigned char *const  dest,
const int  dest_size,
rohc_packet_t *const  packet_type,
int *const  payload_offset 
)

Encode an IP packet according to a pattern decided by several different factors.

1. Check if we have double IP headers.
2. Check if the IP-ID fields are random and if they are in NBO.
3. Decide in which state to go (IR, FO or SO).
4. Decide how many bits are needed to send the IP-ID and SN fields and more important update the sliding windows.
5. Decide which packet type to send.
6. Code the packet.

This function is one of the functions that must exist in one profile for the framework to work.

Parameters:
contextThe compression context
ipThe IP packet to encode
packet_sizeThe length of the IP packet to encode
destThe rohc-packet-under-build buffer
dest_sizeThe length of the rohc-packet-under-build buffer
packet_typeOUT: The type of ROHC packet that is created
payload_offsetThe offset for the payload in the IP packet
Returns:
The length of the created ROHC packet or -1 in case of failure

References c_add_ts(), c_init_header_info(), changed_dynamic_both_hdr(), generic_tmp_vars::changed_fields, changed_fields(), generic_tmp_vars::changed_fields2, changed_static_both_hdr(), check_ip_identification(), code_packet(), c_generic_context::decide_state, c_profile::id, ip_header_info::info, c_generic_context::ip2_flags, c_generic_context::ip_flags, ip_get_hdrlen(), ip_get_inner_packet(), ip_get_next_layer(), ip_get_protocol(), ip_get_total_extension_size(), ip_get_version(), IPV4, ipv4_get_header(), ipv4_get_id(), ipv6_get_header(), c_generic_context::is_ip2_initialized, generic_tmp_vars::max_size, ipv4_header_info::nbo, c_generic_context::next_header_len, c_generic_context::next_header_proto, generic_tmp_vars::nr_ip_id_bits2, generic_tmp_vars::nr_of_ip_hdr, c_context::num_sent_ir, c_context::num_sent_ir_dyn, ipv4_header_info::old_ip, ipv6_header_info::old_ip, ipv4_header_info::old_nbo, ipv4_header_info::old_rnd, PACKET_IR, PACKET_IR_DYN, generic_tmp_vars::packet_type, PACKET_UNKNOWN, c_context::profile, ipv4_header_info::rnd, rohc_debugf, ROHC_OK, ROHC_PROFILE_RTP, generic_tmp_vars::send_dynamic, generic_tmp_vars::send_static, ip_packet::size, rtphdr::sn, c_generic_context::sn, c_context::specific, c_generic_context::specific, rtp_tmp_vars::timestamp, sc_rtp_context::tmp, c_generic_context::tmp, sc_rtp_context::ts_sc, ip_header_info::v4, and ip_header_info::v6.

Referenced by c_rtp_encode(), c_udp_encode(), and c_udp_lite_encode().

void c_generic_feedback ( struct c_context *const  context,
const struct c_feedback feedback 
)
void change_mode ( struct c_context *const  context,
const rohc_mode  new_mode 
)

Change the mode of the context.

Parameters:
contextThe compression context
new_modeThe new mode the context must enter in

References change_state(), IR, c_context::mode, and rohc_debugf.

Referenced by c_generic_feedback().

void change_state ( struct c_context *const  context,
const rohc_c_state  new_state 
)

Change the state of the context.

Parameters:
contextThe compression context
new_stateThe new state the context must enter in

References c_generic_context::fo_count, c_generic_context::ir_count, rohc_debugf, c_generic_context::so_count, c_context::specific, and c_context::state.

Referenced by c_generic_feedback(), change_mode(), decide_state(), periodic_down_transition(), rtp_decide_state(), and udp_decide_state().

void decide_state ( struct c_context *const  context)

Decide the state that should be used for the next packet.

The three states are:

  • Initialization and Refresh (IR),
  • First Order (FO),
  • Second Order (SO).
Parameters:
contextThe compression context

References change_state(), FO, c_generic_context::fo_count, IR, c_generic_context::ir_count, MAX_FO_COUNT, MAX_IR_COUNT, c_context::mode, periodic_down_transition(), generic_tmp_vars::send_dynamic, generic_tmp_vars::send_static, SO, c_context::specific, c_context::state, c_generic_context::tmp, and U_MODE.

Referenced by c_generic_create(), c_udp_lite_create(), rtp_decide_state(), and udp_decide_state().

void ip6_c_init_table ( struct list_comp *const  comp)

Initialize the tables IPv6 extension in compressor.

Parameters:
compThe list compressor

References AH, list_comp::based_table, c_translation::counter, rohc_list_item::data, DEST, HBH, c_translation::item, c_translation::known, rohc_list_item::length, RTHDR, list_comp::trans_table, and rohc_list_item::type.

Referenced by c_init_header_info().

int rohc_list_decide_ipv6_compression ( struct list_comp *const  comp,
const struct ip_packet *const  ip 
)

Decide whether list of IPv6 extension headers shall be sent compressed.

Parameters:
compThe list compressor which is specific to the extension type
ipThe IP packet to compress
Returns:
  • 1 if a compressed list must be sent,
  • 0 if not,
  • -1 if error

References c_create_current_list(), c_translation::counter, list_comp::counter, list_comp::curr_list, delete_elt(), empty_list(), c_list::gen_id, get_elt(), list_comp::get_extension, list_comp::get_index_table, list_elt::index_table, insert_elt(), ip_get_raw_data(), list_comp::islist, list_elt::item, c_translation::known, L, MAX_ITEM, list_comp::ref_list, rohc_debugf, size_list(), list_comp::trans_table, rohc_list_item::type, and list_comp::update_done.

Referenced by code_ipv6_dynamic_part().

int rohc_list_decide_type ( struct list_comp *const  comp)

Decide the encoding type for compression list.

Parameters:
compThe list compressor
Returns:
the encoding type among [0-3]

References list_comp::curr_list, c_list::first_elt, get_elt(), list_elt::index_table, list_comp::islist, list_elt::item, c_translation::known, list_comp::list_compress, list_comp::ref_list, rohc_debugf, size_list(), list_comp::trans_table, and type_is_present().

Referenced by rohc_list_encode().

int rohc_list_encode ( struct list_comp *const  comp,
unsigned char *const  dest,
int  counter,
const int  ps,
const int  size 
)

Generic encoding of compressed list.

Parameters:
compThe list compressor
destThe ROHC packet under build
counterThe current position in the rohc-packet-under-build buffer
psThe size of the index
sizeThe number of element in current list
Returns:
The new position in the rohc-packet-under-build buffer, -1 in case of error

References rohc_debugf, rohc_list_decide_type(), rohc_list_encode_type_0(), rohc_list_encode_type_1(), rohc_list_encode_type_2(), and rohc_list_encode_type_3().

Referenced by code_ipv6_dynamic_part().

int rohc_list_encode_type_0 ( struct list_comp *const  comp,
unsigned char *const  dest,
int  counter,
const int  ps 
)

Build encoding type 0 for list compression.

Todo:
this function is inefficient as it loops many times on the same list (see get_elt especially)

 Encoding type 0 (5.8.6.1):

      0   1   2   3   4   5   6   7
     --- --- --- --- --- --- --- ---
 1  | ET = 0| GP| PS|   CC = m      |
    +---+---+---+---+---+---+---+---+
 2  :            gen_id             : 1 octet, if GP = 1
    +---+---+---+---+---+---+---+---+
    |       XI 1, ..., XI m         | m octets, or m * 4 bits
 3  /               --- --- --- --- /
    |               :    Padding    : if PS = 0 and m is odd
    +---+---+---+---+---+---+---+---+
    |                               |
 4  /      item 1, ..., item n      / variable length
    |                               |
    +---+---+---+---+---+---+---+---+

 ET: Encoding type is zero.

 GP: Indicates presence of gen_id field.

 PS: Indicates size of XI fields:
     PS = 0 indicates 4-bit XI fields;
     PS = 1 indicates 8-bit XI fields.

 CC: CSRC counter from original RTP header.

 gen_id: Identifier for a sequence of identical lists.  It is
     present in U/O-mode when the compressor decides that it may use
     this list as a future reference list.

 XI 1, ..., XI m: m XI items. The format of an XI item is as
     follows:

              +---+---+---+---+
     PS = 0:  | X |   Index   |
              +---+---+---+---+

                0   1   2   3   4   5   6   7
              +---+---+---+---+---+---+---+---+
     PS = 1:  | X |           Index           |
              +---+---+---+---+---+---+---+---+

     X = 1 indicates that the item corresponding to the Index
           is sent in the item 0, ..., item n list.
     X = 0 indicates that the item corresponding to the Index is
               not sent.

     When 4-bit XI items are used and m > 1, the XI items are placed in
     octets in the following manner:

          0   1   2   3   4   5   6   7
        +---+---+---+---+---+---+---+---+
        |     XI k      |    XI k + 1   |
        +---+---+---+---+---+---+---+---+

 Padding: A 4-bit padding field is present when PS = 0 and m is
     odd.  The Padding field is set to zero when sending and ignored
     when receiving.

 Item 1, ..., item n:
     Each item corresponds to an XI with X = 1 in XI 1, ..., XI m.

Parameters:
compThe list compressor
destThe ROHC packet under build
counterThe current position in the rohc-packet-under-build buffer
psThe size of the index
Returns:
The new position in the rohc-packet-under-build buffer

References list_comp::curr_list, rohc_list_item::data, c_list::gen_id, get_elt(), list_elt::index_table, list_elt::item, c_translation::known, rohc_list_item::length, m, rohc_debugf, size_list(), list_comp::trans_table, and rohc_list_item::type.

Referenced by rohc_list_encode().

int rohc_list_encode_type_1 ( struct list_comp *const  comp,
unsigned char *const  dest,
int  counter,
const int  ps 
)

Build encoding type 1 for list compression.

Todo:
this function is inefficient as it loops many times in the current and reference lists (see get_elt and type_is_present especially)

 Encoding type 1 (5.8.6.2):

      0   1   2   3   4   5   6   7
     --- --- --- --- --- --- --- ---
 1  | ET = 1| GP| PS|     XI 1      |
    +---+---+---+---+---+---+---+---+
 2  :            gen_id             : 1 octet, if GP = 1
    +---+---+---+---+---+---+---+---+
 3  |            ref_id             |
    +---+---+---+---+---+---+---+---+
 4  /       insertion bit mask      / 1-2 octets
    +---+---+---+---+---+---+---+---+
    |           XI list             | k octets, or (k - 1) * 4 bits
 5  /               --- --- --- --- /
    |               :    Padding    : if PS = 0 and k is even
    +---+---+---+---+---+---+---+---+
    |                               |
 6  /      item 1, ..., item n      / variable
    |                               |
    +---+---+---+---+---+---+---+---+

 ET: Encoding type is one (1).

 GP: Indicates presence of gen_id field.

 PS: Indicates size of XI fields:
     PS = 0 indicates 4-bit XI fields;
     PS = 1 indicates 8-bit XI fields.

 XI 1: When PS = 0, the first 4-bit XI item is placed here.
       When PS = 1, the field is set to zero when sending, and
       ignored when receiving.

 ref_id: The identifier of the reference CSRC list used when the
       list was compressed.  It is the 8 least significant bits of
       the RTP Sequence Number in R-mode and gen_id (see section
       5.8.2) in U/O-mode.

 insertion bit mask: Bit mask indicating the positions where new
           items are to be inserted.  See Insertion Only scheme in
           section 5.8.3.  The bit mask can have either of the
           following two formats:

      0   1   2   3   4   5   6   7
    +---+---+---+---+---+---+---+---+
    | 0 |        7-bit mask         |  bit 1 is the first bit
    +---+---+---+---+---+---+---+---+

    +---+---+---+---+---+---+---+---+
    | 1 |                           |  bit 1 is the first bit
    +---+      15-bit mask          +
    |                               |  bit 7 is the last bit
    +---+---+---+---+---+---+---+---+

 XI list: XI fields for items to be inserted.  When the insertion
    bit mask has k ones, the total number of XI fields is k.  When
    PS = 1, all XI fields are in the XI list.  When PS = 0, the
    first XI field is in the XI 1 field, and the remaining k - 1
    XI fields are in the XI list.

 Padding: Present when PS = 0 and k is even.

 item 1, ..., item n: One item for each XI field with the X bit set.

Parameters:
compThe list compressor
destThe ROHC packet under build
counterThe current position in the rohc-packet-under-build buffer
psThe size of the index
Returns:
The new position in the rohc-packet-under-build buffer

References list_comp::curr_list, rohc_list_item::data, c_list::gen_id, get_elt(), list_elt::index_table, list_elt::item, c_translation::known, rohc_list_item::length, m, list_comp::ref_list, rohc_debugf, size_list(), list_comp::trans_table, rohc_list_item::type, and type_is_present().

Referenced by rohc_list_encode().

int rohc_list_encode_type_2 ( struct list_comp *const  comp,
unsigned char *const  dest,
int  counter,
const int  ps 
)

Build encoding type 2 for list compression.

Todo:
this function is inefficient as it loops many times in the current and reference lists (see get_elt and type_is_present especially)

 Encoding type 2 (5.8.6.3):

      0   1   2   3   4   5   6   7
    +---+---+---+---+---+---+---+---+
 1  | ET = 2| GP|res|    Count      |
    +---+---+---+---+---+---+---+---+
 2  :            gen_id             : 1 octet, if GP = 1
    +---+---+---+---+---+---+---+---+
 3  |            ref_id             |
    +---+---+---+---+---+---+---+---+
 4  /        removal bit mask       / 1-2 octets
    +---+---+---+---+---+---+---+---+

 ET: Encoding type is 2.

 GP: Indicates presence of gen_id field.

 res: Reserved.  Set to zero when sending, ignored when
      received.

 Count: Number of elements in ref_list.

 removal bit mask: Indicates the elements in ref_list to be
    removed in order to obtain the current list.  See section
    5.8.3.  The bit mask can have either of the following two
    formats:

      0   1   2   3   4   5   6   7
    +---+---+---+---+---+---+---+---+
    | 0 |        7-bit mask         |  bit 1 is the first bit
    +---+---+---+---+---+---+---+---+

    +---+---+---+---+---+---+---+---+
    | 1 |                           |  bit 1 is the first bit
    +---+      15-bit mask          +
    |                               |  bit 7 is the last bit
    +---+---+---+---+---+---+---+---+

Parameters:
compThe list compressor
destThe ROHC packet under build
counterThe current position in the rohc-packet-under-build buffer
psThe size of the index
Returns:
The new position in the rohc-packet-under-build buffer

References list_comp::curr_list, c_list::gen_id, get_elt(), list_elt::item, list_comp::ref_list, rohc_debugf, size_list(), and type_is_present().

Referenced by rohc_list_encode().

int rohc_list_encode_type_3 ( struct list_comp *const  comp,
unsigned char *const  dest,
int  counter,
const int  ps 
)

Build encoding type 3 for list compression.

Todo:
this function is inefficient as it loops many times in the current and reference lists (see get_elt and type_is_present especially)

 Encoding type 3 (5.8.6.4):

      0   1   2   3   4   5   6   7
    +---+---+---+---+---+---+---+---+
 1  | ET=3  |GP |PS |     XI 1      |
    +---+---+---+---+---+---+---+---+
 2  :            gen_id             : 1 octet, if GP = 1
    +---+---+---+---+---+---+---+---+
 3  |            ref_id             |
    +---+---+---+---+---+---+---+---+
 4  /        removal bit mask       / 1-2 octets
    +---+---+---+---+---+---+---+---+
 5  /       insertion bit mask      / 1-2 octets
    +---+---+---+---+---+---+---+---+
    |           XI list             | k octets, or (k - 1) * 4 bits
 6  /               --- --- --- --- /
    |               :    Padding    : if PS = 0 and k is even
    +---+---+---+---+---+---+---+---+
    |                               |
 7  /      item 1, ..., item n      / variable
    |                               |
    +---+---+---+---+---+---+---+---+

 ET: Encoding type is 3.

 GP: Indicates presence of gen_id field.

 PS: Indicates size of XI fields:
     PS = 0 indicates 4-bit XI fields;
     PS = 1 indicates 8-bit XI fields.

 gen_id: Identifier for a sequence of identical lists.  It is
     present in U/O-mode when the compressor decides that it may use
     this list as a future reference list.

 ref_id: The identifier of the reference CSRC list used when the
       list was compressed.  It is the 8 least significant bits of
       the RTP Sequence Number in R-mode and gen_id (see section
       5.8.2) in U/O-mode.

 removal bit mask: Indicates the elements in ref_list to be
    removed in order to obtain the current list.  See section
    5.8.3.  The bit mask can have either of the following two
    formats:

      0   1   2   3   4   5   6   7
    +---+---+---+---+---+---+---+---+
    | 0 |        7-bit mask         |  bit 1 is the first bit
    +---+---+---+---+---+---+---+---+

    +---+---+---+---+---+---+---+---+
    | 1 |                           |  bit 1 is the first bit
    +---+      15-bit mask          +
    |                               |  bit 7 is the last bit
    +---+---+---+---+---+---+---+---+

 insertion bit mask: Bit mask indicating the positions where new
           items are to be inserted.  See Insertion Only scheme in
           section 5.8.3.  The bit mask can have either of the
           following two formats:

      0   1   2   3   4   5   6   7
    +---+---+---+---+---+---+---+---+
    | 0 |        7-bit mask         |  bit 1 is the first bit
    +---+---+---+---+---+---+---+---+

    +---+---+---+---+---+---+---+---+
    | 1 |                           |  bit 1 is the first bit
    +---+      15-bit mask          +
    |                               |  bit 7 is the last bit
    +---+---+---+---+---+---+---+---+

 XI list: XI fields for items to be inserted.  When the insertion
    bit mask has k ones, the total number of XI fields is k.  When
    PS = 1, all XI fields are in the XI list.  When PS = 0, the
    first XI field is in the XI 1 field, and the remaining k - 1
    XI fields are in the XI list.

 Padding: Present when PS = 0 and k is even.

 item 1, ..., item n: One item for each XI field with the X bit set.

Parameters:
compThe list compressor
destThe ROHC packet under build
counterThe current position in the rohc-packet-under-build buffer
psThe size of the index
Returns:
The new position in the rohc-packet-under-build buffer

References list_comp::curr_list, rohc_list_item::data, c_list::gen_id, get_elt(), list_elt::index_table, list_elt::item, c_translation::known, rohc_list_item::length, m, list_comp::ref_list, rohc_debugf, size_list(), list_comp::trans_table, rohc_list_item::type, and type_is_present().

Referenced by rohc_list_encode().