ROHC compression/decompression library
|
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>
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. |
ROHC generic compression context for IP-only, UDP and UDP Lite profiles.
#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().
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.
comp | The list compressor which is specific to the extension type |
ext | The extension |
index | The number of the extension |
index_table | The index of the item in the based table |
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 | ||
) |
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.
context | The compression context |
ip | The IP packet given to initialize the new context |
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, c_generic_context::decide_state, 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.
Referenced by c_rtp_create(), c_udp_create(), and c_udp_lite_create().
void c_generic_destroy | ( | struct c_context *const | context | ) |
Destroy the context.
This function is one of the functions that must exist in one profile for the framework to work.
context | The compression context |
References c_destroy_wlsb(), list_comp::curr_list, destroy_list(), ipv6_header_info::ext_comp, ip_header_info::info, c_generic_context::ip2_flags, c_generic_context::ip_flags, ipv4_header_info::ip_id_window, IPV4, IPV6, c_generic_context::is_ip2_initialized, list_comp::ref_list, c_generic_context::sn_window, c_context::specific, c_generic_context::specific, ip_header_info::v4, ip_header_info::v6, ip_header_info::version, and zfree.
Referenced by c_generic_create(), c_rtp_create(), c_rtp_destroy(), c_udp_create(), and c_udp_lite_create().
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.
context | The compression context |
ip | The IP packet to encode |
packet_size | The length of the IP packet to encode |
dest | The rohc-packet-under-build buffer |
dest_size | The length of the rohc-packet-under-build buffer |
packet_type | OUT: The type of ROHC packet that is created |
payload_offset | The offset for the payload in the IP packet |
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 | ||
) |
Update the profile when feedback arrives.
This function is one of the functions that must exist in one profile for the framework to work.
context | The compression context |
feedback | The feedback information including the whole feedback packet |
References c_feedback::acktype, c_ack_sn_wlsb(), change_mode(), change_state(), c_context::compressor, crc_calculate(), CRC_INIT_8, rohc_comp::crc_table_8, CRC_TYPE_8, c_feedback::data, FO, ip_header_info::info, c_generic_context::ip2_flags, c_generic_context::ip_flags, ipv4_header_info::ip_id_window, IPV4, IR, c_generic_context::ir_dyn_count, c_generic_context::is_ip2_initialized, 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 *const | context, |
const rohc_mode | new_mode | ||
) |
Change the mode of the context.
context | The compression context |
new_mode | The 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.
context | The compression context |
new_state | The 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:
context | The 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.
comp | The 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.
comp | The list compressor which is specific to the extension type |
ip | The IP packet to compress |
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.
comp | The list compressor |
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.
comp | The list compressor |
dest | The ROHC packet under build |
counter | The current position in the rohc-packet-under-build buffer |
ps | The size of the index |
size | The number of element in current list |
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.
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.
comp | The list compressor |
dest | The ROHC packet under build |
counter | The current position in the rohc-packet-under-build buffer |
ps | The size of the index |
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.
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.
comp | The list compressor |
dest | The ROHC packet under build |
counter | The current position in the rohc-packet-under-build buffer |
ps | The size of the index |
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.
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 +---+---+---+---+---+---+---+---+
comp | The list compressor |
dest | The ROHC packet under build |
counter | The current position in the rohc-packet-under-build buffer |
ps | The size of the index |
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.
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.
comp | The list compressor |
dest | The ROHC packet under build |
counter | The current position in the rohc-packet-under-build buffer |
ps | The size of the index |
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().