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 <string.h>
#include <stdarg.h>
#include <assert.h>
Include dependency graph for rohc_decomp.c:

Data Structures

struct  rohc_decomp_stream
 The stream informations about a decompressed packet. 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. More...
 
static const 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. More...
 
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. More...
 
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. More...
 
static void context_free (struct rohc_decomp_ctxt *const context)
 Destroy one decompression context and the profile specific data associated with it. More...
 
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 rohc_decomp_stream *const stream)
 Decompress the compressed headers. More...
 
static bool rohc_decomp_decode_cid (struct rohc_decomp *decomp, const uint8_t *packet, unsigned int len, rohc_cid_t *const cid, size_t *const add_cid_len, size_t *const large_cid_len)
 Decode the CID of a packet. More...
 
static void rohc_decomp_parse_padding (const struct rohc_decomp *const decomp, struct rohc_buf *const packet)
 Parse padding bits if some are present. More...
 
static rohc_status_t rohc_decomp_find_context (struct rohc_decomp *const decomp, const uint8_t *const packet, const size_t packet_len, const rohc_cid_type_t cid, const size_t large_cid_len, const struct rohc_ts arrival_time, rohc_profile_t *const profile_id, struct rohc_decomp_ctxt **const context, bool *const context_created)
 Find the context for the given ROHC packet. More...
 
static rohc_status_t rohc_decomp_decode_pkt (struct rohc_decomp *const decomp, struct rohc_decomp_ctxt *const context, const struct rohc_buf rohc_packet, const size_t add_cid_len, const size_t large_cid_len, struct rohc_buf *const uncomp_packet, rohc_packet_t *const packet_type, bool *const do_change_mode)
 Decode one ROHC packet. More...
 
static bool rohc_decomp_check_ir_crc (const struct rohc_decomp *const decomp, const struct rohc_decomp_ctxt *const context, const uint8_t *const rohc_hdr, const size_t rohc_hdr_len, const size_t add_cid_len, const size_t large_cid_len, const uint8_t crc_packet)
 Check whether the CRC on IR or IR-DYN header is correct or not. More...
 
static void rohc_decomp_stats_add_success (struct rohc_decomp_ctxt *const context, const size_t comp_hdr_len, const size_t uncomp_hdr_len)
 Update statistics upon successful decompression. More...
 
static void rohc_decomp_update_context (struct rohc_decomp_ctxt *const context, const void *const decoded, const size_t payload_len, const struct rohc_ts pkt_arrival_time, bool *const do_change_mode)
 Update context with decoded values. More...
 
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. More...
 
static bool rohc_decomp_parse_feedback (struct rohc_decomp *const decomp, struct rohc_buf *const rohc_data, struct rohc_buf *const feedback, size_t *const feedback_len)
 Parse a feedback item from the given ROHC data. More...
 
static bool rohc_decomp_feedback_ack (struct rohc_decomp *const decomp, const struct rohc_decomp_stream *const infos, struct rohc_buf *const feedback)
 Build a positive ACK feedback. More...
 
static bool rohc_decomp_feedback_nack (struct rohc_decomp *const decomp, const struct rohc_decomp_stream *const infos, struct rohc_buf *const feedback)
 Build a negative ACK feedback. More...
 
static void rohc_decomp_reset_stats (struct rohc_decomp *const decomp)
 Reset all the statistics of the given ROHC decompressor. More...
 
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. More...
 
void rohc_decomp_free (struct rohc_decomp *const decomp)
 Destroy the given ROHC decompressor. More...
 
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. More...
 
const char * rohc_decomp_get_state_descr (const rohc_decomp_state_t state)
 Give a description for the given ROHC decompression context state. More...
 
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. More...
 
bool rohc_decomp_get_context_info (const struct rohc_decomp *const decomp, const rohc_cid_t cid, rohc_decomp_context_info_t *const info)
 Get some information about the given decompression context. More...
 
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. More...
 
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. More...
 
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. More...
 
bool rohc_decomp_set_mrru (struct rohc_decomp *const decomp, const size_t mrru)
 Set the Maximum Reconstructed Reception Unit (MRRU). More...
 
bool rohc_decomp_get_mrru (const struct rohc_decomp *const decomp, size_t *const mrru)
 Get the Maximum Reconstructed Reception Unit (MRRU). More...
 
bool rohc_decomp_set_prtt (struct rohc_decomp *const decomp, const size_t prtt)
 Set the number of packets sent during one Round-Trip Time (RTT). More...
 
bool rohc_decomp_get_prtt (const struct rohc_decomp *const decomp, size_t *const prtt)
 Get the number of packets sent during one Round-Trip Time (RTT). More...
 
bool rohc_decomp_set_rate_limits (struct rohc_decomp *const decomp, const size_t k, const size_t n, const size_t k_1, const size_t n_1, const size_t k_2, const size_t n_2)
 Set the rate limits for feedbacks. More...
 
bool rohc_decomp_get_rate_limits (const struct rohc_decomp *const decomp, size_t *const k, size_t *const n, size_t *const k_1, size_t *const n_1, size_t *const k_2, size_t *const n_2)
 Get the rate limits for feedbacks currently configured. More...
 
bool rohc_decomp_set_features (struct rohc_decomp *const decomp, const rohc_decomp_features_t features)
 Enable/disable features for ROHC decompressor. More...
 
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? More...
 
bool rohc_decomp_enable_profile (struct rohc_decomp *const decomp, const rohc_profile_t profile)
 Enable a decompression profile for a decompressor. More...
 
bool rohc_decomp_disable_profile (struct rohc_decomp *const decomp, const rohc_profile_t profile)
 Disable a decompression profile for a decompressor. More...
 
bool rohc_decomp_enable_profiles (struct rohc_decomp *const decomp,...)
 Enable several decompression profiles for a decompressor. More...
 
bool rohc_decomp_disable_profiles (struct rohc_decomp *const decomp,...)
 Disable several decompression profiles for a decompressor. More...
 
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. More...
 

Variables

const struct rohc_decomp_profile d_uncomp_profile
 Define the decompression part of the Uncompressed profile as described in the RFC 3095. More...
 
const struct rohc_decomp_profile d_udp_profile
 Define the decompression part of the UDP profile as described in the RFC 3095. More...
 
const struct rohc_decomp_profile d_ip_profile
 Define the decompression part of the IP-only profile as described in the RFC 3843. More...
 
const struct rohc_decomp_profile d_udplite_profile
 Define the decompression part of the UDP-Lite profile as described in the RFC 4019. More...
 
const struct rohc_decomp_profile d_esp_profile
 Define the decompression part of the ESP profile as described in the RFC 3095. More...
 
const struct rohc_decomp_profile d_rtp_profile
 Define the decompression part of the RTP profile as described in the RFC 3095. More...
 
const struct rohc_decomp_profile d_tcp_profile
 Define the decompression part of the TCP profile as described in the RFC 3095. More...
 
static const struct rohc_decomp_profile *const rohc_decomp_profiles [D_NUM_PROFILES]
 The decompression parts of the ROHC profiles. More...
 

Detailed Description

ROHC decompression routines.

Author
Didier Barvaux didie.nosp@m.r.ba.nosp@m.rvaux.nosp@m.@tou.nosp@m.louse.nosp@m..viv.nosp@m.eris..nosp@m.com
Didier Barvaux didie.nosp@m.r@ba.nosp@m.rvaux.nosp@m..org
David Moreau from TAS

Function Documentation

◆ context_create()

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

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

◆ context_free()

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

◆ d_decode_header()

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 rohc_decomp_stream *const  stream 
)
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]streamThe informations about the decompressed stream, required for sending feedback to compressor
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 (or failed to do so),
  • ROHC_STATUS_MALFORMED if packet is malformed,
  • ROHC_STATUS_BAD_CRC if a CRC error occurs,
  • ROHC_STATUS_ERROR if another error occurs

◆ find_context()

static struct rohc_decomp_ctxt * find_context ( const struct rohc_decomp *const  decomp,
const rohc_cid_t  cid 
)
static

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

◆ find_profile()

static const struct rohc_decomp_profile * find_profile ( const struct rohc_decomp *const  decomp,
const rohc_profile_t  profile_id 
)
static

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

◆ rohc_decomp_check_ir_crc()

static bool rohc_decomp_check_ir_crc ( const struct rohc_decomp *const  decomp,
const struct rohc_decomp_ctxt *const  context,
const uint8_t *const  rohc_hdr,
const size_t  rohc_hdr_len,
const size_t  add_cid_len,
const size_t  large_cid_len,
const uint8_t  crc_packet 
)
static

Check whether the CRC on IR or IR-DYN header is correct or not.

The CRC for IR/IR-DYN headers is always CRC-8. It is computed on the whole compressed header (payload excluded, but any CID bits included).

Parameters
decompThe ROHC decompressor
contextThe decompression context
rohc_hdrThe compressed IR or IR-DYN header
rohc_hdr_lenThe length (in bytes) of the compressed header
add_cid_lenThe length of the optional Add-CID field
large_cid_lenThe length of the optional large CID field
crc_packetThe CRC extracted from the ROHC header
Returns
true if the CRC is correct, false otherwise

◆ rohc_decomp_create_contexts()

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
Returns
true if the contexts were created, false otherwise

◆ rohc_decomp_decode_cid()

static bool rohc_decomp_decode_cid ( struct rohc_decomp decomp,
const uint8_t *  packet,
unsigned int  len,
rohc_cid_t *const  cid,
size_t *const  add_cid_len,
size_t *const  large_cid_len 
)
static

Decode the CID of a packet.

Parameters
decompThe ROHC decompressor
packetThe ROHC packet to extract CID from
lenThe size of the ROHC packet
[out]cidThe Context ID (CID) extracted from the ROHC packet
[out]add_cid_lenThe length of add-CID in ROHC packet
[out]large_cid_lenThe length of large CID in ROHC packet
Returns
true in case of success, false in case of failure

◆ rohc_decomp_decode_pkt()

static rohc_status_t rohc_decomp_decode_pkt ( struct rohc_decomp *const  decomp,
struct rohc_decomp_ctxt *const  context,
const struct rohc_buf  rohc_packet,
const size_t  add_cid_len,
const size_t  large_cid_len,
struct rohc_buf *const  uncomp_packet,
rohc_packet_t *const  packet_type,
bool *const  do_change_mode 
)
static

Decode one ROHC packet.

Steps:

  • A. Parse the ROHC header
  • B. For IR and IR-DYN packet, check for correct compressed header (CRC)
  • C. Decode extracted bits
  • D. Build uncompressed headers (and check for correct decompression for UO* packets)
  • E. Copy the payload (if any)
  • F. Update the compression context

Steps C and D may be repeated if packet or context repair is attempted upon CRC failure.

Parameters
decompThe ROHC decompressor
contextThe decompression context
rohc_packetThe ROHC packet to decode
add_cid_lenThe length of the optional Add-CID field
large_cid_lenThe length of the optional large CID field
[out]uncomp_packetThe uncompressed packet
[in,out]packet_typeIN: The type of the ROHC packet to parse OUT: The type of the parsed ROHC packet
[out]do_change_modeWhether the profile context wants to change its operational mode or not
Returns
ROHC_STATUS_OK if packet is successfully decoded, ROHC_STATUS_MALFORMED if packet is malformed, ROHC_STATUS_BAD_CRC if a CRC error occurs, ROHC_STATUS_ERROR if an error occurs

◆ rohc_decomp_feedback_ack()

static bool rohc_decomp_feedback_ack ( struct rohc_decomp *const  decomp,
const struct rohc_decomp_stream *const  infos,
struct rohc_buf *const  feedback 
)
static

Build a positive ACK feedback.

Parameters
decompThe ROHC decompressor
infosThe information collected on the successfully decompressed packet
[out]feedbackThe feedback to be transmitted to the remote compressor through the feedback channel
Returns
true if the ACK feedback was successfully built (may be 0 byte), false if a problem occurred

◆ rohc_decomp_feedback_nack()

static bool rohc_decomp_feedback_nack ( struct rohc_decomp *const  decomp,
const struct rohc_decomp_stream *const  infos,
struct rohc_buf *const  feedback 
)
static

Build a negative ACK feedback.

There are two types of negative feedback: NACK and STATIC-NACK.

Parameters
decompThe ROHC decompressor
infosThe information collected on the failed decompressed packet
[out]feedbackThe feedback to be transmitted to the remote compressor through the feedback channel (may be NULL)
Returns
true if the ACK feedback was successfully built (may be 0 byte), false if a problem occurred

◆ rohc_decomp_find_context()

static rohc_status_t rohc_decomp_find_context ( struct rohc_decomp *const  decomp,
const uint8_t *const  packet,
const size_t  packet_len,
const rohc_cid_type_t  cid,
const size_t  large_cid_len,
const struct rohc_ts  arrival_time,
rohc_profile_t *const  profile_id,
struct rohc_decomp_ctxt **const  context,
bool *const  context_created 
)
static

Find the context for the given ROHC packet.

If packet is an IR(-DYN) packet, parse it for the profile ID. Searche for the context with the given CID. Create a new context if needed.

Parameters
decompThe ROHC decompressor
packetThe ROHC packet to parse
packet_lenThe length (in bytes) of the ROHC packet
cidThe CID that was parsed from ROHC packet
large_cid_lenThe length (in bytes) of the Large CID that was parsed from ROHC packet
arrival_timeThe time at which the ROHC packet was received
[out]profile_idThe profile ID parsed from the ROHC packet
[out]contextThe decompression context for the given ROHC packet
[out]context_createdWhether the packet has just been created or not
Returns
Possible return values:
  • ROHC_STATUS_OK if context was found,
  • ROHC_STATUS_NO_CONTEXT if no matching context was found and packet cannot create a new context (or failed to do so),
  • ROHC_STATUS_MALFORMED if packet is malformed

◆ rohc_decomp_parse_feedback()

static bool rohc_decomp_parse_feedback ( struct rohc_decomp *const  decomp,
struct rohc_buf *const  rohc_data,
struct rohc_buf *const  feedback,
size_t *const  feedback_len 
)
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
[out]feedback_lenThe length of the parsed feedback (maybe be different from feedback->len if feedback was NULL or full)
Returns
true if feedback parsing was successful, false if feedback is malformed

◆ rohc_decomp_parse_feedbacks()

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

◆ rohc_decomp_parse_padding()

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

◆ rohc_decomp_reset_stats()

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

◆ rohc_decomp_stats_add_success()

static void rohc_decomp_stats_add_success ( struct rohc_decomp_ctxt *const  context,
const size_t  comp_hdr_len,
const size_t  uncomp_hdr_len 
)
static

Update statistics upon successful decompression.

Parameters
contextThe decompression context
comp_hdr_lenThe length (in bytes) of the compressed header
uncomp_hdr_lenThe length (in bytes) of the uncompressed header

◆ rohc_decomp_update_context()

static void rohc_decomp_update_context ( struct rohc_decomp_ctxt *const  context,
const void *const  decoded,
const size_t  payload_len,
const struct rohc_ts  pkt_arrival_time,
bool *const  do_change_mode 
)
static

Update context with decoded values.

Parameters
contextThe decompression context
decodedThe decoded values to update in the context
payload_lenThe length of the packet payload
pkt_arrival_timeThe arrival time of the decoded ROHC packet
[out]do_change_modeWhether the context wants to change its operational mode or not

Variable Documentation

◆ d_esp_profile

const struct rohc_decomp_profile d_esp_profile

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

◆ d_ip_profile

const struct rohc_decomp_profile d_ip_profile

Define the decompression part of the IP-only profile as described in the RFC 3843.

◆ d_rtp_profile

const struct rohc_decomp_profile d_rtp_profile

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

◆ d_tcp_profile

const struct rohc_decomp_profile d_tcp_profile

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

◆ d_udp_profile

const struct rohc_decomp_profile d_udp_profile

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

◆ d_udplite_profile

const struct rohc_decomp_profile d_udplite_profile

Define the decompression part of the UDP-Lite profile as described in the RFC 4019.

◆ d_uncomp_profile

const struct rohc_decomp_profile d_uncomp_profile

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

◆ rohc_decomp_profiles

const struct rohc_decomp_profile* const rohc_decomp_profiles[D_NUM_PROFILES]
static
Initial value:
=
{
}
const struct rohc_decomp_profile d_tcp_profile
Define the decompression part of the TCP profile as described in the RFC 3095.
Definition: d_tcp.c:4614
const struct rohc_decomp_profile d_ip_profile
Define the decompression part of the IP-only profile as described in the RFC 3843.
Definition: d_ip.c:777
const struct rohc_decomp_profile d_udplite_profile
Define the decompression part of the UDP-Lite profile as described in the RFC 4019.
Definition: d_udp_lite.c:779
const struct rohc_decomp_profile d_uncomp_profile
Define the decompression part of the Uncompressed profile as described in the RFC 3095...
Definition: d_uncompressed.c:551
const struct rohc_decomp_profile d_udp_profile
Define the decompression part of the UDP profile as described in the RFC 3095.
Definition: d_udp.c:588
const struct rohc_decomp_profile d_rtp_profile
Define the decompression part of the RTP profile as described in the RFC 3095.
Definition: d_rtp.c:1936
const struct rohc_decomp_profile d_esp_profile
Define the decompression part of the ESP profile as described in the RFC 3095.
Definition: d_esp.c:424

The decompression parts of the ROHC profiles.