ROHC compression/decompression library
Data Structures | Functions | Variables
rohc_decomp.c File Reference

ROHC decompression routines. More...

#include "rohc_decomp.h"
#include "rohc_decomp_internals.h"
#include "rohc_traces_internal.h"
#include "rohc_time_internal.h"
#include "rohc_utils.h"
#include "rohc_bit_ops.h"
#include "rohc_debug.h"
#include "feedback_create.h"
#include "feedback_parse.h"
#include "sdvl.h"
#include "rohc_add_cid.h"
#include "rohc_decomp_detect_packet.h"
#include "crc.h"
#include "config.h"
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
Include dependency graph for rohc_decomp.c:

Data Structures

struct  d_decode_data
 Decompression-related data. More...

Functions

static bool rohc_decomp_create_contexts (struct rohc_decomp *const decomp, const rohc_cid_t max_cid)
 Create the array of decompression contexts.
static rohc_status_t d_decode_header (struct rohc_decomp *decomp, const struct rohc_buf rohc_packet, struct rohc_buf *const uncomp_packet, struct rohc_buf *const rcvd_feedback, struct d_decode_data *ddata, rohc_packet_t *const packet_type)
 Decompress the compressed headers.
static struct rohc_decomp_profilefind_profile (const struct rohc_decomp *const decomp, const rohc_profile_t profile_id)
 Find the ROHC profile with the given profile ID.
static struct rohc_decomp_ctxtcontext_create (struct rohc_decomp *decomp, const rohc_cid_t cid, const struct rohc_decomp_profile *const profile, const struct rohc_ts arrival_time)
 Create one new decompression context with profile specific data.
static struct rohc_decomp_ctxtfind_context (const struct rohc_decomp *const decomp, const rohc_cid_t cid)
 Find one decompression context thanks to its CID.
static void context_free (struct rohc_decomp_ctxt *const context)
 Destroy one decompression context and the profile specific data associated with it.
static bool rohc_decomp_decode_cid (struct rohc_decomp *decomp, const unsigned char *packet, unsigned int len, struct d_decode_data *ddata)
 Decode the CID of a packet.
static void rohc_decomp_print_trace_default (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 bool __rohc_decomp_set_cid_type (struct rohc_decomp *const decomp, const rohc_cid_type_t cid_type)
 Set the type of CID to use for the given decompressor.
static bool __rohc_decomp_set_max_cid (struct rohc_decomp *const decomp, const size_t max_cid)
 Set the MAX_CID allowed for the given decompressor.
static void rohc_decomp_parse_padding (const struct rohc_decomp *const decomp, struct rohc_buf *const packet)
 Parse padding bits if some are present.
static bool rohc_decomp_parse_feedbacks (struct rohc_decomp *const decomp, struct rohc_buf *const rohc_data, struct rohc_buf *const feedbacks)
 Parse zero or more feedback items from the given ROHC data.
static bool rohc_decomp_parse_feedback (struct rohc_decomp *const decomp, struct rohc_buf *const rohc_data, struct rohc_buf *const feedback)
 Parse a feedback item from the given ROHC data.
static void d_operation_mode_feedback (struct rohc_decomp *decomp, const rohc_status_t rohc_status, const uint16_t cid, const rohc_cid_type_t cid_type, int mode, struct rohc_decomp_ctxt *context, struct rohc_buf *const feedback_send)
 Send feedback depending on the mode: Unidirectional, Optimistic or Reliable.
static void d_optimistic_feedback (struct rohc_decomp *decomp, const rohc_status_t rohc_status, const rohc_cid_t cid, const rohc_cid_type_t cid_type, struct rohc_decomp_ctxt *context, struct rohc_buf *const feedback_send)
 Send feedback in Optimistic Mode.
static void rohc_decomp_reset_stats (struct rohc_decomp *const decomp)
 Reset all the statistics of the given ROHC decompressor.
static int rohc_d_context (struct rohc_decomp *decomp, const size_t pos, unsigned int indent, char *buffer)
 Output the statistics of one decompression context to a buffer.
struct rohc_decomprohc_alloc_decompressor (struct rohc_comp *compressor)
 Create one ROHC decompressor.
void rohc_free_decompressor (struct rohc_decomp *decomp)
 Destroy one ROHC decompressor.
struct rohc_decomprohc_decomp_new (const rohc_cid_type_t cid_type, const rohc_cid_t max_cid, const rohc_mode_t mode, struct rohc_comp *const comp)
 Create a new ROHC decompressor.
struct rohc_decomprohc_decomp_new2 (const rohc_cid_type_t cid_type, const rohc_cid_t max_cid, const rohc_mode_t mode)
 Create a new ROHC decompressor.
void rohc_decomp_free (struct rohc_decomp *const decomp)
 Destroy the given ROHC decompressor.
int rohc_decompress (struct rohc_decomp *decomp, unsigned char *ibuf, int isize, unsigned char *obuf, int osize)
 Decompress the given ROHC packet into one uncompressed packet.
int rohc_decompress2 (struct rohc_decomp *const decomp, const struct rohc_ts arrival_time, const unsigned char *const rohc_packet, const size_t rohc_packet_len, unsigned char *const uncomp_packet, const size_t uncomp_packet_max_len, size_t *const uncomp_packet_len)
 Decompress the given ROHC packet into one uncompressed packet.
rohc_status_t rohc_decompress3 (struct rohc_decomp *const decomp, const struct rohc_buf rohc_packet, struct rohc_buf *const uncomp_packet, struct rohc_buf *const rcvd_feedback, struct rohc_buf *const feedback_send)
 Decompress the given ROHC packet into one uncompressed packet.
int rohc_decompress_both (struct rohc_decomp *decomp, unsigned char *ibuf, int isize, unsigned char *obuf, int osize, int large)
 Decompress both large and small CID packets.
void clear_statistics (struct rohc_decomp *decomp)
 Clear all the statistics.
int rohc_d_statistics (struct rohc_decomp *decomp, unsigned int indent, char *buffer)
 Output the decompression statistics of one decompressor to a buffer. The buffer must be large enough to store all the statistics.
const char * rohc_decomp_get_state_descr (const rohc_decomp_state_t state)
 Give a description for the given ROHC decompression context state.
bool rohc_decomp_get_last_packet_info (const struct rohc_decomp *const decomp, rohc_decomp_last_packet_info_t *const info)
 Get some information about the last decompressed packet.
bool rohc_decomp_get_general_info (const struct rohc_decomp *const decomp, rohc_decomp_general_info_t *const info)
 Get some general information about the decompressor.
void user_interactions (struct rohc_decomp *decomp, int feedback_maxval)
 Update feedback interval by the user.
bool rohc_decomp_set_cid_type (struct rohc_decomp *const decomp, const rohc_cid_type_t cid_type)
 Set the type of CID to use for the given decompressor.
bool rohc_decomp_get_cid_type (const struct rohc_decomp *const decomp, rohc_cid_type_t *const cid_type)
 Get the CID type that the decompressor uses.
bool rohc_decomp_set_max_cid (struct rohc_decomp *const decomp, const size_t max_cid)
 Set the MAX_CID allowed for the given decompressor.
bool rohc_decomp_get_max_cid (const struct rohc_decomp *const decomp, size_t *const max_cid)
 Get the maximal CID value the decompressor uses.
bool rohc_decomp_set_mrru (struct rohc_decomp *const decomp, const size_t mrru)
 Set the Maximum Reconstructed Reception Unit (MRRU).
bool rohc_decomp_get_mrru (const struct rohc_decomp *const decomp, size_t *const mrru)
 Get the Maximum Reconstructed Reception Unit (MRRU).
bool rohc_decomp_set_features (struct rohc_decomp *const decomp, const rohc_decomp_features_t features)
 Enable/disable features for ROHC decompressor.
bool rohc_decomp_profile_enabled (const struct rohc_decomp *const decomp, const rohc_profile_t profile)
 Is the given decompression profile enabled for a decompressor?
bool rohc_decomp_enable_profile (struct rohc_decomp *const decomp, const rohc_profile_t profile)
 Enable a decompression profile for a decompressor.
bool rohc_decomp_disable_profile (struct rohc_decomp *const decomp, const rohc_profile_t profile)
 Disable a decompression profile for a decompressor.
bool rohc_decomp_enable_profiles (struct rohc_decomp *const decomp,...)
 Enable several decompression profiles for a decompressor.
bool rohc_decomp_disable_profiles (struct rohc_decomp *const decomp,...)
 Disable several decompression profiles for a decompressor.
bool rohc_decomp_set_traces_cb (struct rohc_decomp *decomp, rohc_trace_callback_t callback)
 Set the callback function used to manage traces in decompressor.
bool rohc_decomp_set_traces_cb2 (struct rohc_decomp *decomp, rohc_trace_callback2_t callback, void *const priv_ctxt)
 Set the callback function used to manage traces in decompressor.

Variables

struct rohc_decomp_profile
d_uncomp_profile d_udp_profile
d_ip_profile d_udplite_profile
d_esp_profile d_rtp_profile 
d_tcp_profile
 Define the decompression part of the TCP profile as described in the RFC 3095.
static struct
rohc_decomp_profile *const 
rohc_decomp_profiles [D_NUM_PROFILES]
 The decompression parts of the ROHC profiles.

Detailed Description

ROHC decompression routines.

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

Function Documentation

static bool __rohc_decomp_set_cid_type ( struct rohc_decomp *const  decomp,
const rohc_cid_type_t  cid_type 
) [static]

Set the type of CID to use for the given decompressor.

Set the type of CID to use for the given decompressor.

Warning:
Changing the CID type while library is used may lead to destruction of decompression contexts
Parameters:
decompThe decompressor for which to set CID type
cid_typeThe new CID type among ROHC_SMALL_CID or ROHC_LARGE_CID
Returns:
true if the CID type was successfully set, false otherwise
static bool __rohc_decomp_set_max_cid ( struct rohc_decomp *const  decomp,
const size_t  max_cid 
) [static]

Set the MAX_CID allowed for the given decompressor.

Set the MAX_CID allowed for the given decompressor.

Warning:
Changing the MAX_CID value while library is used may lead to destruction of decompression contexts
Parameters:
decompThe decompressor for which to set MAX_CID
max_cidThe new MAX_CID value:
Returns:
true if the MAX_CID was successfully set, false otherwise
static struct rohc_decomp_ctxt * context_create ( struct rohc_decomp decomp,
const rohc_cid_t  cid,
const struct rohc_decomp_profile *const  profile,
const struct rohc_ts  arrival_time 
) [static, read]

Create one new decompression context with profile specific data.

Parameters:
decompThe ROHC decompressor
cidThe CID of the new context
profileThe profile to be assigned with the new context
arrival_timeThe time at which packet was received (0 if unknown, or to disable time-related features in ROHC protocol)
Returns:
The new context if successful, NULL otherwise
static void context_free ( struct rohc_decomp_ctxt *const  context) [static]

Destroy one decompression context and the profile specific data associated with it.

Parameters:
contextThe context to destroy
static rohc_status_t d_decode_header ( struct rohc_decomp decomp,
const struct rohc_buf  rohc_packet,
struct rohc_buf *const  uncomp_packet,
struct rohc_buf *const  rcvd_feedback,
struct d_decode_data ddata,
rohc_packet_t *const  packet_type 
) [static]

Decompress the compressed headers.

Parameters:
decompThe ROHC decompressor
rohc_packetThe ROHC packet to decode
[out]uncomp_packetThe uncompressed packet
[out]rcvd_feedbackThe feedback received from the remote peer for the same-side associated ROHC compressor through the feedback channel:
  • If NULL, ignore the received feedback data
  • If not NULL, store the received feedback in at the given address
[out]ddataDecompression-related data (e.g. the context)
[out]packet_typeThe type of the decompressed ROHC packet
Returns:
Possible return values:
  • ROHC_STATUS_OK if packet is successfully decoded,
  • ROHC_STATUS_NO_CONTEXT if no matching context was found and packet cannot create a new context,
  • ROHC_STATUS_MALFORMED if packet is malformed,
  • ROHC_STATUS_BAD_CRC if a CRC error occurs,
  • ROHC_STATUS_ERROR if another error occurs
static void d_operation_mode_feedback ( struct rohc_decomp decomp,
const rohc_status_t  rohc_status,
const uint16_t  cid,
const rohc_cid_type_t  cid_type,
int  mode,
struct rohc_decomp_ctxt context,
struct rohc_buf *const  feedback_send 
) [static]

Send feedback depending on the mode: Unidirectional, Optimistic or Reliable.

Parameters:
decompThe ROHC decompressor
rohc_statusThe type of feedback to send:
  • ROHC_STATUS_OK = OK (ack),
  • ROHC_STATUS_NO_CONTEXT = ContextInvalid (S-nack),
  • ROHC_STATUS_MALFORMED = PackageFailed (Nack)
cidThe Context ID (CID) to which the feedback is related
cid_typeThe type of CID used for the feedback
modeThe mode in which the ROHC decompressor operates: ROHC_U_MODE, ROHC_O_MODE or ROHC_R_MODE
contextThe context to which the feedback is related
[out]feedback_sendThe feedback to be transmitted to the remote compressor through the feedback channel:
  • If NULL, the decompression won't generate feedback information for its compressor
  • If not NULL, may store the generated feedback at the given address
static void d_optimistic_feedback ( struct rohc_decomp decomp,
const rohc_status_t  rohc_status,
const rohc_cid_t  cid,
const rohc_cid_type_t  cid_type,
struct rohc_decomp_ctxt context,
struct rohc_buf *const  feedback_send 
) [static]

Send feedback in Optimistic Mode.

Parameters:
decompThe ROHC decompressor
rohc_statusThe type of feedback to send:
  • ROHC_STATUS_OK = OK (ack),
  • ROHC_STATUS_NO_CONTEXT = ContextInvalid (S-nack),
  • ROHC_STATUS_MALFORMED = PackageFailed (Nack)
cidThe Context ID (CID) to which the feedback is related
cid_typeThe type of CID used for the feedback
contextThe context to which the feedback is related
[out]feedback_sendThe feedback to be transmitted to the remote compressor through the feedback channel:
  • If NULL, the decompression won't generate feedback information for its compressor
  • If not NULL, may store the generated feedback at the given address
static struct rohc_decomp_ctxt * find_context ( const struct rohc_decomp *const  decomp,
const rohc_cid_t  cid 
) [static, read]

Find one decompression context thanks to its CID.

Parameters:
decompThe ROHC decompressor
cidThe CID of the context to find out
Returns:
The context if found, NULL otherwise
static struct rohc_decomp_profile * find_profile ( const struct rohc_decomp *const  decomp,
const rohc_profile_t  profile_id 
) [static, read]

Find the ROHC profile with the given profile ID.

Parameters:
decompThe ROHC decompressor
profile_idThe profile ID to search for
Returns:
The matching ROHC profile if found and enabled, NULL if not found or disabled
static int rohc_d_context ( struct rohc_decomp decomp,
const size_t  pos,
unsigned int  indent,
char *  buffer 
) [static]

Output the statistics of one decompression context to a buffer.

The buffer must be large enough to store the statistics of one context.

Parameters:
decompThe ROHC decompressor
posThe pos of the decompression context in the contexts array
indentThe level of indentation to add during output
bufferThe buffer where to outputs the statistics
Returns:
The length of data written to the buffer
static bool rohc_decomp_create_contexts ( struct rohc_decomp *const  decomp,
const rohc_cid_t  max_cid 
) [static]

Create the array of decompression contexts.

The maximum size of the array is ROHC_LARGE_CID_MAX + 1.

Parameters:
decompThe ROHC decompressor
max_cidThe MAX_CID value to used (may be different from the one in decompressor if the MAX_CID value is being changed)
Returns:
true if the contexts were created, false otherwise
static bool rohc_decomp_decode_cid ( struct rohc_decomp decomp,
const unsigned char *  packet,
unsigned int  len,
struct d_decode_data ddata 
) [static]

Decode the CID of a packet.

Parameters:
decompThe ROHC decompressor
packetThe ROHC packet to extract CID from
lenThe size of the ROHC packet
ddataIN/OUT: decompression-related data (e.g. the context)
Returns:
true in case of success, false in case of failure
static bool rohc_decomp_parse_feedback ( struct rohc_decomp *const  decomp,
struct rohc_buf *const  rohc_data,
struct rohc_buf *const  feedback 
) [static]

Parse a feedback item from the given ROHC data.

Parameters:
decompThe ROHC decompressor
rohc_dataThe ROHC data to parse for one feedback item
[out]feedbackThe retrieved feedback (header and data included), may be NULL if one don't want to retrieve the feedback item
Returns:
true if feedback parsing was successful, false if feedback is malformed
static bool rohc_decomp_parse_feedbacks ( struct rohc_decomp *const  decomp,
struct rohc_buf *const  rohc_data,
struct rohc_buf *const  feedbacks 
) [static]

Parse zero or more feedback items from the given ROHC data.

Parameters:
decompThe ROHC decompressor
rohc_dataThe ROHC data to parse for feedback items
[out]feedbacksThe parsed feedback items, may be NULL if one don't want to retrieve the feedback items
Returns:
true if parsing of feedback items is successful, false if at least one feedback is malformed
static void rohc_decomp_parse_padding ( const struct rohc_decomp *const  decomp,
struct rohc_buf *const  packet 
) [static]

Parse padding bits if some are present.

Parameters:
decompThe ROHC decompressor
packetThe ROHC packet to parse
static void rohc_decomp_print_trace_default ( 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:
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_decomp_reset_stats ( struct rohc_decomp *const  decomp) [static]

Reset all the statistics of the given ROHC decompressor.

Parameters:
decompThe ROHC decompressor

Variable Documentation

Define the decompression part of the TCP profile as described in the RFC 3095.

Initial value:

The decompression parts of the ROHC profiles.