Files
2026-07-30 11:19:44 +05:30

231 lines
7.3 KiB
C

/* iprohc_coding_util.h - ROHC coding/decoding routines */
/*
* Copyright (c) 2008 Wind River Systems, Inc.
*
* The right to copy, distribute or otherwise make use of this software
* may be licensed only pursuant to the terms of an applicable Wind River
* license agreement. No license to Wind River intellectual property rights
* is granted herein. All rights not licensed by Wind River are reserved
* by Wind River.
*/
/*
modification history
--------------------
01h,01oct11,ggz Added capability to simulate various ipid change pattern
01g,01dec09,ggz Add LSB encoding
01f,01dec09,ggz Include LSB routines regardless to the option IPROHC_WLSB_LSB
01e,01dec09,ggz Added k parameter to some WLSB/LSB APIs
01d,01dec09,ggz Added p = 0 support
01c,01dec09,ggz Added 32 bit WLSB value support and a test case
01b,02mar09,tlu Fix Linux build warning
01a,05apr08,ggz Created
*/
#ifndef IPROHC_CODING_UTIL_H
#define IPROHC_CODING_UTIL_H
/*
****************************************************************************
* INCLUDE FILES
****************************************************************************
*/
#define IPCOM_USE_CLIB_PROTO
#include <ipcom_type.h>
#include <ipcom_os.h>
#include <ipcom_list.h>
#include <ipcom_err.h>
#include <ipcom_syslog.h>
#include <ipcom_time.h>
#include <ipcom_clib.h>
#include "iprohc.h"
/*
****************************************************************************
* DEFINES
****************************************************************************
*/
#undef ROHC_DEBUG_TEST_WLSB
#undef ROHC_DEBUG_ENABLE_LOG
/*
* For field values that are expected always to increase, p can be
* set to -1. The interpretation interval becomes
* v_ref + 1, v_ref + 2^k].
*/
#ifdef ROHC_DEBUG_TEST_WLSB
#define P_FOR_INCR -1
/* For field values that stay the same or increase, p can be set to
0. The interpretation interval becomes [v_ref, v_ref + 2^k - 1].*/
#define P_FOR_STAT_INCR 0
#endif
/*
****************************************************************************
* Public TYPES
****************************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
****************************************************************************
* LOCAL TYPES
****************************************************************************
*/
/*#ifdef IPROHC_WLSB_LSB*/
typedef struct cmp_wlsb_wnd{
Ip_u32 val;
Ip_u32 index;
} cmp_wlsb_wnd;
/*
This is a prototype for passsing WLSB stucts of variouse types to generic functions.
We could use dynamic allocation but this is much faster.
Warning: cmp_wnd rngBuf[1] - must always be the last in the structure.
In case of modification of this structure the structure in
iprohc_create_cmp_wlsb_struct macro should be updated as well.
*/
typedef struct cmp_wslb_cast{
int rngBuf_marker;
int rngBuf_curr;
int num_of_vals;
int sizeOfWnd;
int numOfBits;
int p;
cmp_wlsb_wnd rngBuf[1]; /* This arrays must always be the last in the structure */
} cmp_wslb_cast;
/*#endif*/ /*IPROHC_WLSB_LSB*/
typedef struct cmp_lsb{
Ip_u32 ref;
Ip_u32 prev_ref;
int p;
int numOfBits;
int num_of_vals;
}cmp_lsb;
typedef struct cmp_lsb_intrvl{
Ip_u32 left_margin;
Ip_u32 right_margin;
} cmp_lsb_intrvl;
typedef struct dmp_lsb{
Ip_u32 ref;
Ip_u32 prev_ref;
int p;
Ip_u32 bit_mask;
/*int numOfBits;*/
int num_of_vals;
}dmp_lsb;
typedef struct dmp_lsb_intrvl{
Ip_u32 left_margin;
Ip_u32 right_margin;
}dmp_lsb_intrvl;
/*
****************************************************************************
* Application APIs
****************************************************************************
*/
/*
****************************************************************************
* GLOBAL FUNCTIONS
****************************************************************************
*/
/*#ifdef IPROHC_WLSB_LSB*/
/*
Add here WLSB structes with variouse lengt if needed. The name should be unique
Warning cmp_wnd rngBuf[sizeOfWnd] - must always be the last on the structure
*/
#define iprohc_create_cmp_wlsb_struct(name, szOfWnd) \
struct { \
int rngBuf_marker; \
int rngBuf_curr; \
int num_of_vals; \
int sizeOfWnd; \
int numOfBits; \
int p; \
cmp_wlsb_wnd rngBuf[szOfWnd]; \
} name
#define iprohc_create_cmp_lsb_struct(name) \
cmp_lsb name
IP_PUBLIC void iprohc_init_cmp_wlsb_struct(cmp_wslb_cast* wlsb, int sizeOfWnd,
int numOfBits, int p);
IP_PUBLIC Ip_bool iprohc_cmp_wlsb_add_val(cmp_wslb_cast* wlsb, Ip_u32 val, Ip_u32 index);
IP_PUBLIC Ip_bool iprohc_cmp_wlsb_encode_val(cmp_wslb_cast *wlsb, Ip_u32 val, Ip_u32
*enc_val, Ip_u8* enc_val_ln);
/*#endif*/ /*IPROHC_WLSB_LSB*/
#define iprohc_create_cmp_lsb_struct(name) \
cmp_lsb name
#define iprohc_create_dmp_lsb_struct(name) \
dmp_lsb name
IP_PUBLIC void iprohc_init_cmp_lsb_struct(cmp_lsb* lsb, int numOfBits, int p);
IP_PUBLIC void iprohc_cmp_lsb_add_val(cmp_lsb* lsb, Ip_u32 val);
IP_PUBLIC Ip_bool iprohc_cmp_lsb_encode_val(cmp_lsb *lsb, Ip_u32 val, Ip_u32 *enc_val, Ip_u8* enc_val_ln);
/* Don't initialize the WLSB ring buffer */
IP_PUBLIC void iprohc_init_dmp_lsb_struct(dmp_lsb *lsb, int p, Ip_u32 bit_mask);
IP_PUBLIC void iprohc_dmp_lsb_save_last_valid_ref(dmp_lsb* lsb, Ip_u32 rev);
IP_PUBLIC Ip_bool iprohc_lsb_decode_and_save_ip_sn_ref(Ip_u32* dec_val, dmp_lsb *lsb, Ip_u32 val, Ip_u8 k);
IP_PUBLIC Ip_bool iprohc_lsb_decode_and_save_ref(Ip_u32* dec_val, dmp_lsb *lsb, Ip_u32 val, Ip_u8 k);
IP_PUBLIC Ip_bool iprohc_lsb_encode_32(Ip_u32 ref_val, Ip_u32 val, Ip_u8 k, int p);
IP_PUBLIC Ip_bool iprohc_lsb_decode_32(Ip_u32* dec_val, Ip_u32 ref_val,
Ip_u32 val, Ip_u8 k, int p);
#ifdef IPROHC_USE_TEST
#ifdef IPROHC_TCP_IP_SIMULATED_IPID
IP_PUBLIC void iprohc_ipid_sim(Ipcom_pkt *pkt, Ip_u16 ipid_gen);
#endif
#endif
/*
****************************************************************************
* LOCAL FUNCTIONS
****************************************************************************
*/
/*#ifdef IPROHC_WLSB_LSB*/
#ifdef ROHC_DEBUG_TEST_WLSB
IP_PUBLIC void test_wlsb_ip_id(void);
IP_PUBLIC void test_wlsb_32bit(void);
IP_PUBLIC void test_lsb_16bit(void);
IP_PUBLIC void test_lsb_32bit(void);
IP_PUBLIC void test_lsb_32(void);
#endif
/*#endif*/ /* IPROHC_WLSB_LSB */
#ifdef __cplusplus
}
#endif
#endif
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/