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

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

#include <netinet/ip.h>
#include <string.h>
#include "rohc_comp.h"
#include "comp_list.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.

Classes

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_variables
 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 *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 *context)
 Destroy the context.
void change_mode (struct c_context *context, rohc_mode new_mode)
 Change the mode of the context.
void change_state (struct c_context *context, rohc_c_state new_state)
 Change the state of the context.
void ip6_c_init_table (struct list_comp *comp)
 Initialize the tables IPv6 extension in compressor.
int c_algo_list_compress (struct list_comp *comp, const struct ip_packet ip)
 Algorithm of compression list.
int c_create_current_list (int index, struct list_comp *comp, unsigned char *ext, int index_table)
 Create the current list.
int decide_type (struct list_comp *comp)
 Decide the encoding type for compression list.
int encode_list (struct list_comp *comp, unsigned char *dest, int counter, int ps, int size)
 Generique encoding of compressed list.
int encode_type_0 (struct list_comp *comp, unsigned char *dest, int counter, int ps)
 build Encoding type 0
int encode_type_1 (struct list_comp *comp, unsigned char *dest, int counter, int ps)
 build Encoding type 1
int encode_type_3 (struct list_comp *comp, unsigned char *dest, int counter, int ps)
 build Encoding type 3
int encode_type_2 (struct list_comp *comp, unsigned char *dest, int counter, int ps)
 build Encoding type 2
int c_generic_encode (struct c_context *context, const struct ip_packet ip, int packet_size, unsigned char *dest, int dest_size, int *payload_offset)
 Encode an IP packet according to a pattern decided by several different factors.
void c_generic_feedback (struct c_context *context, struct c_feedback *feedback)
 Update the profile when feedback arrives.
void decide_state (struct c_context *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 c_algo_list_compress(), decode_type_0(), decode_type_1(), decode_type_2(), and decode_type_3().

#define MAX_ITEM   15

The number of compression list items.

Referenced by c_algo_list_compress().


Function Documentation

int c_algo_list_compress ( struct list_comp comp,
const struct ip_packet  ip 
)

Algorithm of compression list.

This function compress a generic extension list

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 and -1 if error

References c_create_current_list(), c_translation::counter, list_comp::counter, list_comp::curr_list, ip_packet::data, 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(), list_comp::islist, list_elt::item, c_translation::known, L, MAX_ITEM, list_comp::ref_list, rohc_debugf, size_list(), list_comp::trans_table, item::type, and list_comp::update_done.

Referenced by code_ipv6_dynamic_part(), and decide_packet().

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

Create the current list.

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

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, item::length, push_back(), rohc_debugf, list_comp::trans_table, and item::type.

Referenced by c_algo_list_compress().

int c_generic_create ( struct c_context context,
const struct ip_packet  ip 
)

Create a new context and initialize it thanks to the given IP 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 given to initialize the new context
Returns:
1 if successful, 0 otherwise

References c_create_wlsb(), c_generic_destroy(), c_init_header_info(), c_init_tmp_variables(), C_WINDOW_WIDTH, c_generic_context::code_dynamic_part, c_generic_context::code_static_part, c_generic_context::code_UO_packet_head, c_generic_context::code_UO_packet_tail, c_generic_context::compute_crc_dynamic, compute_crc_dynamic(), compute_crc_static(), c_generic_context::compute_crc_static, decide_state(), c_generic_context::decide_state, c_generic_context::fo_count, c_generic_context::go_back_fo_count, c_generic_context::go_back_ir_count, c_profile::id, c_generic_context::init_at_IR, c_generic_context::ip_flags, ip_get_inner_packet(), ip_get_protocol(), c_generic_context::ir_count, c_generic_context::ir_dyn_count, c_generic_context::is_ip2_initialized, c_generic_context::next_header_len, c_generic_context::next_header_proto, c_context::profile, rohc_debugf, ROHC_PROFILE_IP, ROHC_PROFILE_RTP, ROHC_PROFILE_UDP, ROHC_PROFILE_UDPLITE, ROHC_PROFILE_UNCOMPRESSED, c_generic_context::sn, c_generic_context::sn_window, c_generic_context::so_count, c_context::specific, c_generic_context::specific, and c_generic_context::tmp_variables.

Referenced by c_rtp_create(), c_udp_create(), and c_udp_lite_create().

void c_generic_destroy ( struct c_context context)
int c_generic_encode ( struct c_context context,
const struct ip_packet  ip,
int  packet_size,
unsigned char *  dest,
int  dest_size,
int *  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
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_variables::changed_fields, changed_fields(), generic_tmp_variables::changed_fields2, changed_static_both_hdr(), check_ip_identification(), code_packet(), decide_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(), ip_is_fragment(), IPV4, ipv4_get_header(), ipv4_get_id(), ipv6_get_header(), c_generic_context::is_ip2_initialized, generic_tmp_variables::max_size, ipv4_header_info::nbo, c_generic_context::next_header_len, c_generic_context::next_header_proto, generic_tmp_variables::nr_ip_id_bits2, generic_tmp_variables::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_variables::packet_type, c_context::profile, ipv4_header_info::rnd, rohc_debugf, ROHC_PROFILE_RTP, generic_tmp_variables::send_dynamic, generic_tmp_variables::send_static, ip_packet::size, rtphdr::sn, c_generic_context::sn, c_context::specific, c_generic_context::specific, rtp_tmp_variables::timestamp, sc_rtp_context::tmp_variables, c_generic_context::tmp_variables, sc_rtp_context::ts_sc, update_variables(), 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 context,
struct c_feedback feedback 
)

Update the profile when feedback arrives.

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

Parameters:
contextThe compression context
feedbackThe feedback information including the whole feedback packet

References c_feedback::acktype, c_ack_sn_wlsb(), change_mode(), change_state(), crc_calculate(), CRC_INIT_8, CRC_TYPE_8, c_feedback::data, FO, ip_header_info::info, c_generic_context::ip_flags, ipv4_header_info::ip_id_window, IPV4, IR, c_generic_context::ir_dyn_count, rohc_debugf, c_feedback::size, sn, c_generic_context::sn_window, SO, c_context::specific, c_feedback::specific_offset, c_feedback::specific_size, c_context::state, c_feedback::type, ip_header_info::v4, and ip_header_info::version.

void change_mode ( struct c_context context,
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 context,
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 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_variables::send_dynamic, generic_tmp_variables::send_static, SO, c_context::specific, c_context::state, c_generic_context::tmp_variables, and U_MODE.

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

int decide_type ( struct list_comp comp)

Decide the encoding type for compression list.

Parameters:
compThe list compressor
Returns:
the encoding type

References list_comp::curr_list, get_elt(), list_elt::index_table, list_elt::item, c_translation::known, list_comp::ref_list, size_list(), list_comp::trans_table, and type_is_present().

Referenced by encode_list().

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

Generique 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

References list_comp::curr_list, decide_type(), encode_type_0(), encode_type_1(), encode_type_2(), encode_type_3(), c_list::first_elt, c_list::gen_id, get_elt(), list_elt::index_table, list_comp::islist, list_comp::list_compress, list_comp::ref_list, and rohc_debugf.

Referenced by code_ipv6_dynamic_part().

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

build Encoding type 0

 
Encoding type 0 (5.8.6.1):

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

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

Referenced by encode_list().

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

build Encoding type 1


Encoding type 1 (5.8.6.2):

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

References list_comp::curr_list, item::data, get_elt(), list_elt::index_table, list_elt::item, c_translation::known, item::length, list_comp::ref_list, size_list(), list_comp::trans_table, and type_is_present().

Referenced by encode_list().

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

build Encoding type 2


Encoding type 2 (5.8.6.3):

	  0   1   2   3   4   5   6   7
	+---+---+---+---+---+---+---+---+
	| ET = 2| GP| PS|    Counter    |
	+---+---+---+---+---+---+---+---+
	|            gen_id             |
	+---+---+---+---+---+---+---+---+
	|            ref_id             |
	+---+---+---+---+---+---+---+---+
	/        removal bit mask       /
	+---+---+---+---+---+---+---+---+
 
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

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

Referenced by encode_list().

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

build Encoding type 3


Encoding type 3 (5.8.6.4):

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

References list_comp::curr_list, item::data, GET_BIT_0_2, GET_BIT_3, get_elt(), GET_REAL, list_elt::index_table, list_elt::item, c_translation::known, item::length, list_comp::ref_list, rohc_debugf, size_list(), list_comp::trans_table, and type_is_present().

Referenced by encode_list().

void ip6_c_init_table ( struct list_comp comp)

Initialize the tables IPv6 extension in compressor.

Parameters:
compThe list compressor

References AH, item::ahhdr, list_comp::based_table, c_translation::counter, item::data, DEST, item::dest, HBH, item::hbh, item::header, c_translation::item, c_translation::known, item::length, RTHDR, item::rthdr, list_comp::trans_table, and item::type.

Referenced by c_init_header_info().