ROHC compression/decompression library
Functions | Variables
rohc_comp.c File Reference

ROHC compression routines. More...

#include "rohc_comp.h"
#include "rohc_comp_internals.h"
#include "rohc_packets.h"
#include "rohc_traces.h"
#include "rohc_traces_internal.h"
#include "rohc_time_internal.h"
#include "rohc_debug.h"
#include "rohc_utils.h"
#include "sdvl.h"
#include "rohc_add_cid.h"
#include "ip.h"
#include "crc.h"
#include "protocols/udp.h"
#include "protocols/ip_numbers.h"
#include "feedback_parse.h"
#include "config.h"
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
Include dependency graph for rohc_comp.c:

Functions

static struct rohc_comp_profilerohc_get_profile_from_id (const struct rohc_comp *comp, const rohc_profile_t profile_id)
 Find out a ROHC profile given a profile ID.
static struct rohc_comp_profilec_get_profile_from_packet (const struct rohc_comp *const comp, const struct net_pkt *const packet)
 Find out a ROHC profile given an IP protocol ID.
static bool c_create_contexts (struct rohc_comp *const comp)
 Create the array of compression contexts.
static void c_destroy_contexts (struct rohc_comp *const comp)
 Destroy all the compression contexts in the context array.
static struct rohc_comp_ctxtc_create_context (struct rohc_comp *const comp, const struct rohc_comp_profile *const profile, const struct net_pkt *const packet, const struct rohc_ts arrival_time)
 Create a compression context.
static struct rohc_comp_ctxtrohc_comp_find_ctxt (struct rohc_comp *const comp, const struct net_pkt *const packet, const int profile_id_hint, const struct rohc_ts arrival_time)
 Find a compression context given an IP packet.
static struct rohc_comp_ctxtc_get_context (struct rohc_comp *const comp, const rohc_cid_t cid)
 Find out a context given its CID.
static bool __rohc_feedback_remove_locked (struct rohc_comp *const comp)
 Remove all feedbacks locked during the packet build.
static bool __rohc_feedback_unlock (struct rohc_comp *const comp)
 Unlock all feedbacks locked during the packet build.
static void rohc_feedback_destroy (struct rohc_comp *const comp)
 Destroy memory allocated for the feedback packets.
static int rohc_feedback_get (struct rohc_comp *const comp, unsigned char *const buffer, const unsigned int max)
 Retrieve one feedback packet and store it in the given buffer.
static void rohc_comp_print_trace_default (void *const priv_ctxt, const rohc_trace_level_t level, const rohc_trace_entity_t entity, const int profile, const char *const format,...)
 The default callback for traces.
static void __rohc_c_set_max_cid (struct rohc_comp *comp, int value)
 Set the maximal CID value the compressor should use.
static bool rohc_comp_default_rtp_cb (const unsigned char *const ip, const unsigned char *const udp, const unsigned char *const payload, const unsigned int payload_size, void *const rtp_private)
 The default RTP detection callback to keep compatibility.
static int rohc_comp_get_random_default (const struct rohc_comp *const comp, void *const user_context)
 The default callback for random numbers.
static int __rohc_c_context (struct rohc_comp *comp, int cid, unsigned int indent, char *buffer)
 Get information about a compression context.
struct rohc_comprohc_alloc_compressor (int max_cid, int jam_use, int adapt_size, int encap_size)
 Create one ROHC compressor.
void rohc_free_compressor (struct rohc_comp *comp)
 Destroy one ROHC compressor.
struct rohc_comprohc_comp_new (const rohc_cid_type_t cid_type, const rohc_cid_t max_cid)
 Create a new ROHC compressor.
struct rohc_comprohc_comp_new2 (const rohc_cid_type_t cid_type, const rohc_cid_t max_cid, const rohc_comp_random_cb_t rand_cb, void *const rand_priv)
 Create a new ROHC compressor.
void rohc_comp_free (struct rohc_comp *const comp)
 Destroy the given ROHC compressor.
bool rohc_comp_set_traces_cb (struct rohc_comp *const comp, rohc_trace_callback_t callback)
 Set the callback function used to manage traces in compressor.
bool rohc_comp_set_traces_cb2 (struct rohc_comp *const comp, rohc_trace_callback2_t callback, void *const priv_ctxt)
 Set the callback function used to manage traces in compressor.
bool rohc_comp_set_random_cb (struct rohc_comp *const comp, rohc_comp_random_cb_t callback, void *const user_context)
 Set the user-defined callback for random numbers.
int rohc_compress (struct rohc_comp *comp, unsigned char *ibuf, int isize, unsigned char *obuf, int osize)
 Compress the given uncompressed packet into a ROHC packet.
int rohc_compress2 (struct rohc_comp *const comp, const unsigned char *const uncomp_packet, const size_t uncomp_packet_len, unsigned char *const rohc_packet, const size_t rohc_packet_max_len, size_t *const rohc_packet_len)
 Compress the given uncompressed packet into a ROHC packet.
int rohc_compress3 (struct rohc_comp *const comp, const struct rohc_ts arrival_time, const unsigned char *const uncomp_packet, const size_t uncomp_packet_len, unsigned char *const rohc_packet, const size_t rohc_packet_max_len, size_t *const rohc_packet_len)
 Compress the given uncompressed packet into a ROHC packet.
rohc_status_t rohc_compress4 (struct rohc_comp *const comp, const struct rohc_buf uncomp_packet, struct rohc_buf *const rohc_packet)
 Compress the given uncompressed packet into a ROHC packet.
int rohc_comp_get_segment (struct rohc_comp *const comp, unsigned char *const segment, const size_t max_len, size_t *const len)
 Get the next ROHC segment if any.
rohc_status_t rohc_comp_get_segment2 (struct rohc_comp *const comp, struct rohc_buf *const segment)
 Get the next ROHC segment if any.
bool rohc_comp_force_contexts_reinit (struct rohc_comp *const comp)
 Force the compressor to re-initialize all its contexts.
bool rohc_comp_set_wlsb_window_width (struct rohc_comp *const comp, const size_t width)
 Set the window width for the W-LSB encoding scheme.
bool rohc_comp_set_periodic_refreshes (struct rohc_comp *const comp, const size_t ir_timeout, const size_t fo_timeout)
 Set the timeout values for IR and FO periodic refreshes.
bool rohc_comp_set_list_trans_nr (struct rohc_comp *const comp, const size_t list_trans_nr)
 Set the number of uncompressed transmissions for list compression.
bool rohc_comp_set_rtp_detection_cb (struct rohc_comp *const comp, rohc_rtp_detection_callback_t callback, void *const rtp_private)
 Set the RTP detection callback function.
bool rohc_comp_profile_enabled (const struct rohc_comp *const comp, const rohc_profile_t profile)
 Is the given compression profile enabled for a compressor?
void rohc_activate_profile (struct rohc_comp *comp, int profile)
 Activate a profile for a compressor.
bool rohc_comp_enable_profile (struct rohc_comp *const comp, const rohc_profile_t profile)
 Enable a compression profile for a compressor.
bool rohc_comp_disable_profile (struct rohc_comp *const comp, const rohc_profile_t profile)
 Disable a compression profile for a compressor.
bool rohc_comp_enable_profiles (struct rohc_comp *const comp,...)
 Enable several compression profiles for a compressor.
bool rohc_comp_disable_profiles (struct rohc_comp *const comp,...)
 Disable several compression profiles for a compressor.
int rohc_c_using_small_cid (struct rohc_comp *comp)
 Whether the compressor uses small CID or not.
void rohc_c_set_header (struct rohc_comp *comp, int header)
 Set the maximal header size. The maximal header size is ignored for the moment.
void rohc_c_set_mrru (struct rohc_comp *comp, int value)
 Set the Maximum Reconstructed Reception Unit (MRRU).
bool rohc_comp_set_mrru (struct rohc_comp *const comp, const size_t mrru)
 Set the Maximum Reconstructed Reception Unit (MRRU).
bool rohc_comp_get_mrru (const struct rohc_comp *const comp, size_t *const mrru)
 Get the Maximum Reconstructed Reception Unit (MRRU).
void rohc_c_set_max_cid (struct rohc_comp *comp, int value)
 Set the maximal CID value the compressor should use.
bool rohc_comp_get_max_cid (const struct rohc_comp *const comp, size_t *const max_cid)
 Get the maximal CID value the compressor uses.
void rohc_c_set_large_cid (struct rohc_comp *comp, int large_cid)
 Tell the compressor to use large CIDs.
bool rohc_comp_get_cid_type (const struct rohc_comp *const comp, rohc_cid_type_t *const cid_type)
 Get the CID type that the compressor uses.
bool rohc_comp_add_rtp_port (struct rohc_comp *const comp, const unsigned int port)
 Add a port to the list of UDP ports dedicated for RTP traffic.
bool rohc_comp_remove_rtp_port (struct rohc_comp *const comp, const unsigned int port)
 Remove a port from the list of UDP ports dedicated to RTP traffic.
bool rohc_comp_reset_rtp_ports (struct rohc_comp *const comp)
 Reset the list of dedicated RTP ports.
bool rohc_comp_set_features (struct rohc_comp *const comp, const rohc_comp_features_t features)
 Enable/disable features for ROHC compressor.
void rohc_c_set_enable (struct rohc_comp *comp, int enable)
 Enable the ROHC compressor.
int rohc_c_is_enabled (struct rohc_comp *comp)
 Whether the ROHC compressor is enabled or not.
int rohc_c_info (char *buffer)
 Get information about available compression profiles.
int rohc_c_statistics (struct rohc_comp *comp, unsigned int indent, char *buffer)
 Get information about a ROHC compressor.
int rohc_c_context (struct rohc_comp *comp, int cid, unsigned int indent, char *buffer)
 Get information about a compression context.
void c_piggyback_feedback (struct rohc_comp *comp, unsigned char *feedback, int size)
 Add a feedback packet to the next outgoing ROHC packet (piggybacking)
bool __rohc_comp_piggyback_feedback (struct rohc_comp *const comp, const unsigned char *const feedback, const size_t size)
 Add a feedback packet to the next outgoing ROHC packet (piggybacking)
bool rohc_comp_piggyback_feedback (struct rohc_comp *const comp, const unsigned char *const feedback, const size_t size)
 Add a feedback packet to the next outgoing ROHC packet (piggybacking)
void c_deliver_feedback (struct rohc_comp *comp, unsigned char *packet, int size)
 Callback called by a decompressor to deliver a feedback packet to the compressor.
bool __rohc_comp_deliver_feedback (struct rohc_comp *const comp, const uint8_t *const packet, const size_t size)
 Deliver a feedback packet to the compressor.
bool rohc_comp_deliver_feedback (struct rohc_comp *const comp, const uint8_t *const packet, const size_t size)
 Deliver a feedback packet to the compressor.
bool rohc_comp_deliver_feedback2 (struct rohc_comp *const comp, const struct rohc_buf feedback)
 Deliver a feedback packet to the compressor.
int rohc_feedback_flush (struct rohc_comp *comp, unsigned char *obuf, int osize)
 Send as much feedback data as possible.
size_t rohc_feedback_avail_bytes (const struct rohc_comp *const comp)
 How many bytes of unsent feedback data are available at compressor?
int rohc_comp_get_last_packet_info (const struct rohc_comp *const comp, rohc_comp_last_packet_info_t *const info)
 Get some information about the last compressed packet.
bool rohc_comp_get_last_packet_info2 (const struct rohc_comp *const comp, rohc_comp_last_packet_info2_t *const info)
 Get some information about the last compressed packet.
bool rohc_comp_get_general_info (const struct rohc_comp *const comp, rohc_comp_general_info_t *const info)
 Get some general information about the compressor.
const char * rohc_comp_get_state_descr (const rohc_comp_state_t state)
 Give a description for the given ROHC compression context state.
bool rohc_feedback_remove_locked (struct rohc_comp *const comp)
 Remove all feedbacks locked during the packet build.
bool rohc_feedback_unlock (struct rohc_comp *const comp)
 Unlock all feedbacks locked during the packet build.

Variables

struct rohc_comp_profile
c_rtp_profile c_udp_profile
c_udp_lite_profile
c_esp_profile c_tcp_profile
c_ip_profile 
c_uncompressed_profile
 Define the compression part of the Uncompressed profile as described in the RFC 3095.
static struct
rohc_comp_profile *const 
rohc_comp_profiles [C_NUM_PROFILES]
 The compression parts of the ROHC profiles.

Detailed Description

ROHC compression routines.

Author:
Didier Barvaux <didier.barvaux@toulouse.viveris.com>
Didier Barvaux <didier@barvaux.org>
David Moreau from TAS

Function Documentation

static int __rohc_c_context ( struct rohc_comp comp,
int  cid,
unsigned int  indent,
char *  buffer 
) [static]

Get information about a compression context.

This function outputs XML.

Internal implementation of rohc_c_context() for compatibility reasons.

Parameters:
compThe ROHC compressor
cidThe CID of the compressor context to output information about
indentThe indent level to beautify the XML output
bufferThe buffer where to store the information
Returns:
The length of the data stored in the buffer if successful, -2 if the given CID is too large, -1 if the given CID is unused or an error occurs
static void __rohc_c_set_max_cid ( struct rohc_comp comp,
int  value 
) [static]

Set the maximal CID value the compressor should use.

Parameters:
compThe ROHC compressor
valueThe new maximal CID value
bool __rohc_comp_deliver_feedback ( struct rohc_comp *const  comp,
const uint8_t *const  packet,
const size_t  size 
)

Deliver a feedback packet to the compressor.

When feedback is received by the decompressor, this function is called and delivers the feedback to the right profile/context of the compressor.

Parameters:
compThe ROHC compressor
packetThe feedback data
sizeThe length of the feedback packet
Returns:
true if the feedback was successfully taken into account, false if the feedback could not be taken into account
bool __rohc_comp_piggyback_feedback ( struct rohc_comp *const  comp,
const unsigned char *const  feedback,
const size_t  size 
)

Add a feedback packet to the next outgoing ROHC packet (piggybacking)

Parameters:
compThe ROHC compressor
feedbackThe feedback data
sizeThe length of the feedback packet
Returns:
true in case of success, false otherwise
static bool __rohc_feedback_remove_locked ( struct rohc_comp *const  comp) [static]

Remove all feedbacks locked during the packet build.

Remove all feedbacks locked during the packet build from the compressor's context. A call to function rohc_feedback_remove_locked closes the transaction started by the function rohc_feedback_flush. It frees the compressor's internal memory related to feedback data once the feedback data was sent for sure.

If the feedback data failed to be sent correctly (eg. temporary network problem), then the feedback data shall not be removed but only unlocked with the rohc_feedback_unlock function. This way, feedback data could be sent again later.

Parameters:
compThe ROHC compressor
Returns:
true if action succeeded, false in case of error
See also:
rohc_feedback_unlock
rohc_feedback_flush
static bool __rohc_feedback_unlock ( struct rohc_comp *const  comp) [static]

Unlock all feedbacks locked during the packet build.

Unlock all feedbacks locked during the packet build, but do not remove them from the compressor's context. A call to function rohc_feedback_unlock closes the transaction started by the function rohc_feedback_flush. It allows the compressor to send the unlocked feedback bytes again after the the program failed to send them correctly (eg. temporary network problem).

If the feedback data was sent successfully, then the feedback data shall not be unlocked, but removed with the rohc_feedback_remove_locked function. This way, feedback data will not be sent again later.

Parameters:
compThe ROHC compressor
Returns:
true if action succeeded, false in case of error
See also:
rohc_feedback_remove_locked
rohc_feedback_flush
static struct rohc_comp_ctxt * c_create_context ( struct rohc_comp *const  comp,
const struct rohc_comp_profile *const  profile,
const struct net_pkt *const  packet,
const struct rohc_ts  arrival_time 
) [static, read]

Create a compression context.

Parameters:
compThe ROHC compressor
profileThe profile to associate the context with
packetThe packet to create a compression context for
arrival_timeThe time at which packet was received (0 if unknown, or to disable time-related features in ROHC protocol)
Returns:
The compression context if successful, NULL otherwise
static bool c_create_contexts ( struct rohc_comp *const  comp) [static]

Create the array of compression contexts.

Parameters:
compThe ROHC compressor
Returns:
true if the creation is successful, false otherwise
static void c_destroy_contexts ( struct rohc_comp *const  comp) [static]

Destroy all the compression contexts in the context array.

The profile-specific contexts are also destroyed.

Parameters:
compThe ROHC compressor
static struct rohc_comp_ctxt * c_get_context ( struct rohc_comp *const  comp,
const rohc_cid_t  cid 
) [static, read]

Find out a context given its CID.

Parameters:
compThe ROHC compressor
cidThe CID of the context to find
Returns:
The context with the given CID if found, NULL otherwise
static struct rohc_comp_profile * c_get_profile_from_packet ( const struct rohc_comp *const  comp,
const struct net_pkt *const  packet 
) [static, read]

Find out a ROHC profile given an IP protocol ID.

Parameters:
compThe ROHC compressor
packetThe packet to find a compression profile for
Returns:
The ROHC profile if found, NULL otherwise
int rohc_c_context ( struct rohc_comp comp,
int  cid,
unsigned int  indent,
char *  buffer 
)

Get information about a compression context.

This function outputs XML.

Deprecated:
do not use this function anymore, use rohc_comp_get_general_info() instead
Parameters:
compThe ROHC compressor
cidThe CID of the compressor context to output information about
indentThe indent level to beautify the XML output
bufferThe buffer where to store the information
Returns:
The length of the data stored in the buffer if successful, -2 if the given CID is too large, -1 if the given CID is unused or an error occurs
static bool rohc_comp_default_rtp_cb ( const unsigned char *const  ip,
const unsigned char *const  udp,
const unsigned char *const  payload,
const unsigned int  payload_size,
void *const  rtp_private 
) [static]

The default RTP detection callback to keep compatibility.

Parameters:
ipThe innermost IP packet
udpThe UDP header of the packet
payloadThe UDP payload of the packet
payload_sizeThe size of the UDP payload (in bytes)
rtp_privateAn optional private context
Returns:
true if the packet is an RTP packet, false otherwise
static struct rohc_comp_ctxt * rohc_comp_find_ctxt ( struct rohc_comp *const  comp,
const struct net_pkt *const  packet,
const int  profile_id_hint,
const struct rohc_ts  arrival_time 
) [static, read]

Find a compression context given an IP packet.

Parameters:
compThe ROHC compressor
packetThe packet to find a compression context for
profile_id_hintIf positive, indicate the profile to use
arrival_timeThe time at which packet was received (0 if unknown, or to disable time-related features in the ROHC protocol)
Returns:
The context if found or successfully created, NULL if not found
static int rohc_comp_get_random_default ( const struct rohc_comp *const  comp,
void *const  user_context 
) [static]

The default callback for random numbers.

The default callback for random numbers always returns 0 to keep compatibility with previous releases. That could be changed for the 2.0.0 release.

Parameters:
compThe ROHC compressor
user_contextShould always be NULL
Returns:
Always 0
static void rohc_comp_print_trace_default ( void *const  priv_ctxt,
const rohc_trace_level_t  level,
const rohc_trace_entity_t  entity,
const int  profile,
const char *const  format,
  ... 
) [static]

The default callback for traces.

The default callback for traces always prints traces on stdout for compatibility with previous releases. That could be changed for the 2.0.0 release.

Parameters:
priv_ctxtThe private context is not used, shall be NULL
levelThe level of the message
entityThe entity concerned by the traces
profileThe number of the profile concerned by the message
formatThe format string for the trace message
...The arguments related to the format string
static void rohc_feedback_destroy ( struct rohc_comp *const  comp) [static]

Destroy memory allocated for the feedback packets.

Parameters:
compThe ROHC compressor
static int rohc_feedback_get ( struct rohc_comp *const  comp,
unsigned char *const  buffer,
const unsigned int  max 
) [static]

Retrieve one feedback packet and store it in the given buffer.

The feedback packet is not removed from the context, it is locked. It will be removed only in case of success when rohc_feedback_remove_locked is called. It will be unlocked but not removed in case of failure when rohc_feedback_unlock is called. Doing these actions in two times is required not to lose feedback data if compression fails.

Parameters:
compThe ROHC compressor
bufferThe buffer to store the feedback packet
maxThe size of the buffer
Returns:
The length of the feedback packet if any, 0 if no feedback is available, -1 if the feedback is too large for the given buffer
static struct rohc_comp_profile * rohc_get_profile_from_id ( const struct rohc_comp comp,
const rohc_profile_t  profile_id 
) [static, read]

Find out a ROHC profile given a profile ID.

Parameters:
compThe ROHC compressor
profile_idThe ID of the ROHC profile to find out
Returns:
The ROHC profile if found, NULL otherwise

Variable Documentation

Define the compression part of the Uncompressed profile as described in the RFC 3095.

Initial value:

The compression parts of the ROHC profiles.

The order of profiles declaration is important: they are evaluated in that order. The RTP profile shall be declared before the UDP one for example.