Files
m241Neelima/components/ip_net2-6.9/iprohc/include/iprohc.h
T
2026-07-30 11:19:44 +05:30

481 lines
14 KiB
C

/* iprohc.h - ROHC head file */
/*
* 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
--------------------
01i,20oct11,ggz Defect WIND00351290. Use ipcom_mutex_lock for unix port
01h,20oct11,ggz Fix for defect WIND00312450
01g,01oct11,ggz Added capability to simulate various ipid change pattern
01f,22feb10,ggz Add TCP/IP profiles
01e,03dec09,ggz Add iprohc_d_choose_profile() for decompressor. Add ESP,UDP
profiles
01d,24feb09,tlu Replace ipcom_tmo by ipnet timer untilities to port to LKM
01c,25jun08,tlu Add reference list structure definition
01b,23apr08,tlu Add external declaration for iprohc
01a,20feb08,tlu Created.
*/
#ifndef IPROHC_H
#define IPROHC_H
/*
****************************************************************************
* INCLUDE FILES
****************************************************************************
*/
#include <ipcom_tags.h>
#include <ipcom_type.h>
#include <ipcom_sock.h>
#include <ipcom_sock6.h>
#include <ipcom_list.h>
#include <ipcom_netif.h>
#include <ipcom_pkt.h>
#include <ipcom_inet.h>
#ifdef IPNET
#include <ipnet_timeout.h>
#endif
#include "iprohc_config.h"
#include "iprohc_constant.h"
#include "iprohc_comp.h"
#include "iprohc_decomp.h"
#include "iprohc_parser.h"
/*
****************************************************************************
* DEFINES
****************************************************************************
*/
#define IPROHC_ENABLE_REENTRANT
#ifdef IPROHC_ENABLE_REENTRANT
#if defined(IP_PORT_VXWORKS) || defined(IP_PORT_UNIX)
#define IPROHC_LOCK() ipcom_mutex_lock(iprohc.code_mutex)
#define IPROHC_UNLOCK() ipcom_mutex_unlock(iprohc.code_mutex)
#define IPROHC_IF_LOCK(interface) ipcom_mutex_lock((interface)->code_mutex)
#define IPROHC_IF_UNLOCK(interface) ipcom_mutex_unlock((interface)->code_mutex)
#else /* !IP_PORT_VXWORKS, Linux recursive semaphore */
#define IPROHC_LOCK() iprohc_lck()
#define IPROHC_UNLOCK() iprohc_unlck()
#define IPROHC_IF_LOCK(interface) iprohc_if_lck(interface)
#define IPROHC_IF_UNLOCK(interface) iprohc_if_unlck(interface)
#endif /* IP_PORT_VXWORKS */
#else
#define IPROHC_LOCK() IP_NOOP
#define IPROHC_UNLOCK() IP_NOOP
#define IPROHC_IF_LOCK(interface) IP_NOOP
#define IPROHC_IF_UNLOCK(interface) IP_NOOP
#endif
/* Syslog priority and facility. */
#undef IPCOM_SYSLOG_PRIORITY
#if defined(_WRS_CONFIG_IPROHC_SYSLOG_PRIORITY)
#define IPCOM_SYSLOG_PRIORITY _WRS_CONFIG_IPROHC_SYSLOG_PRIORITY
#else
#define IPCOM_SYSLOG_PRIORITY IPCOM_SYSLOG_PRIO_DEFAULT
#endif
#undef IPCOM_SYSLOG_FACILITY
#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPROHC
#define IPROHC_LEAVE(xerrval) do { retval = xerrval; goto leave; } while(0)
#define IPROHC_ERROUT(xerrval) do { retval = xerrval; goto errout; } while(0)
#define IPROHC_VALID_PROFILE_ID(id) ((id == ROHC_PROFILE_UNCOMPRESSED) || \
(id == ROHC_PROFILE_UDP_IP) || \
(id == ROHC_PROFILE_ESP_IP) || \
(id == ROHC_PROFILE_IP) || \
(id == ROHC_PROFILE_TCP_IP))
/*
****************************************************************************
* Public TYPES
****************************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
*===========================================================================
* Iprohc_ref_list
*===========================================================================
* This is the ROHC reference list structure
*/
typedef struct Iprohc_ref_list_struct
{
Ipcom_list ref_list;
Ip_u8 index;
Ip_u8 type;
Ip_u8 length;
Ip_u8 *data;
}
Iprohc_ref_list;
/*
****************************************************************************
* LOCAL TYPES
****************************************************************************
*/
/*
*===========================================================================
* Iprohc_feedback
*===========================================================================
* This is the ROHC feedback structure
*/
typedef struct Iprohc_feedback_struct
{
Ipcom_list feedback_list;
/* Whether the packet is to be transmitted or not */
Ip_bool to_be_transmitted;
/* an IPv4 or IPv6 packet */
Ip_u8 packet_type;
/* The destination address to send the feedback to */
Iprohc_addr dst;
/* The source address the feedback is for */
Iprohc_addr src;
/* Buffer contaions an already formatted feedback packet */
Ip_u16 size;
Ip_u8 data[IPROHC_MAX_FEEDBCK_BUF];
}
Iprohc_feedback;
/*
*===========================================================================
* Iprohc_interface
*===========================================================================
* This is the ROHC monitoring interface structure
*/
typedef struct Iprohc_interface_struct
{
Ipcom_list interface_list;
/* interface name, such as "fei", or "motfcc" */
char name[IPROHC_IF_NAME_MAX];
/* wheter have interface unit number */
Ip_bool have_unitNum;
/* interface unit number, such as 1, 2 */
Ip_u8 unitNum;
/* Record Ipcom_netif interface structure */
Ipcom_netif *netif;
/* Profile list, value 1 means configured, 0 means not configured */
/* The index profile ID is defined by RFC 3095, RFC 3843 */
Ip_u16 profile_num; /* number of supported profiles */
Ip_bool profiles[IPROHC_MAX_PROFILE_IDS];
/* Feedback buffer */
Ip_u16 feedback_num[IPROHC_MAX_PROFILE_IDS]; /* number of feedbacks */
Ipcom_list feedback_head[IPROHC_MAX_PROFILE_IDS];
/* Compressor structure list */
Iprohc_compressor *compressor;
/* De-compressor structure ist */
Iprohc_decompressor *decompressor;
#ifdef IPROHC_ENABLE_REENTRANT
Ipcom_mutex code_mutex; /* Mutex to protect IPROHC interface data. */
#endif
#ifndef IP_PORT_VXWORKS /* for Linux recursive semaphore */
/* the process that currently holds the semaphore and taken counter */
Ip_pid_t pid;
Ip_u8 s_counter;
#endif /* !IP_PORT_VXWORKS */
}
Iprohc_interface;
/*
*===========================================================================
* Iprohc_profile
*===========================================================================
* This is the ROHC profile structure
*/
struct Iprohc_profile;
typedef struct Iprohc_profile_struct
{
/* Configured, value 1 means configured, 0 means not configured */
Ip_bool configured;
/* Profile specific functions */
/* De-register profile specific functions, and free any contents */
Ip_err (*p_deregister) (void);
/* Profile compression functions */
/* Find a compression context associated with the packet */
Ip_err (*c_find_context) (Iprohc_compressor *comp,
Ipcom_pkt *pkt,
Iprohc_c_context **c_context);
/* Create a compression context associated with the packet */
Iprohc_c_context * (*c_create_context) (Iprohc_compressor *comp,
Ipcom_pkt *pkt);
/* Free a compression context */
Ip_err (*c_del_context) (Iprohc_c_context *context);
/* Process a feedback element */
Ip_err (*c_process_feedback) (Iprohc_c_context *context,
Ip_u8 *feedback,
Ip_u8 size);
/* Compress a packet */
Ip_err (*c_compress) (Iprohc_c_context *context,
Ipcom_pkt *pkt);
/* Debug: print a compression context */
void (*c_print_context) (Iprohc_c_context *context);
/* Profile de-compression functions */
/* Find a de-compression context associated with the packet */
Iprohc_d_context * (*d_find_context) (Iprohc_decompressor *decomp,
Ipcom_pkt *pkt);
/* Create a de-compression context associated with the packet */
Iprohc_d_context * (*d_create_context) (Iprohc_decompressor *decomp,
Ipcom_pkt *pkt);
/* Free a de-compression context */
Ip_err (*d_del_context) (Iprohc_d_context *context);
/* De-compress a packet */
Ip_err (*d_decompress) (Iprohc_d_context *context,
Ipcom_pkt *pkt);
/* Debug: print a de-compression context */
void (*d_print_context) (Iprohc_d_context *context);
}
Iprohc_profile;
/*
*===========================================================================
* IPROHC data
*===========================================================================
*/
typedef struct Iprohc_data_struct
{
Ip_bool opened;
#ifdef IPROHC_ENABLE_REENTRANT
Ipcom_mutex code_mutex; /* Mutex to protect IPROHC global data. */
#endif
/* ROHC monitoring interfaces */
Ip_u16 if_num; /* number of monitoring IFs. */
Ipcom_list if_head;
/* Profile list, indexed by a profile id */
/* The profile ID is defined by RFC 3095, RFC 3843 */
Ip_u16 profile_num; /* number of supported profiles */
Iprohc_profile profiles[IPROHC_MAX_PROFILE_IDS];
/* Maximum Context Identifier */
Ip_u16 max_cid;
/* Used Context Identifier Representation */
Ip_bool large_cid;
/* FEEDBACK_FOR Parameter Defined */
Ip_bool feedback_for_defined;
/* FEEDBACK_FOR Parameter */
Ip_u32 feedback_for;
/* F_MAX_PERIOD parameter */
Ip_u16 f_max_period;
/* F_MAX_TIME parameter */
Ip_u8 f_max_time;
#ifndef IP_PORT_VXWORKS /* for Linux recursive semaphore */
/* the process that currently holds the semaphore and taken counter */
Ip_pid_t pid;
Ip_u8 s_counter;
#endif /* !IP_PORT_VXWORKS */
/* Syslog output memory. */
char buf[48];
#ifdef IPROHC_USE_TEST
#ifdef IPROHC_TCP_IP_SIMULATED_IPID
Ip_u8 ipid_sim;
#endif
#endif
}
Iprohc_data;
IP_EXTERN IP_GLOBAL Iprohc_data iprohc;
/*
****************************************************************************
* Application APIs
****************************************************************************
*/
IP_PUBLIC Ip_err iprohc_input_hook(Ipcom_netif *netif, Ipcom_pkt *pkt);
IP_PUBLIC Ip_err iprohc_output_hook(Ipcom_netif *netif, Ipcom_pkt *pkt);
IP_PUBLIC Ip_err iprohc_ioctl(unsigned long request, struct Ip_rohcreq *rohcmsg);
/*
****************************************************************************
* GLOBAL FUNCTIONS
****************************************************************************
*/
IP_PUBLIC Ip_err iprohc_create(void);
IP_PUBLIC Ip_err iprohc_start(void);
IP_PUBLIC Ip_err iprohc_close(void);
IP_PUBLIC Ip_err iprohc_exit(void);
IP_PUBLIC void iprohc_show_config(void);
IP_PUBLIC const char * iprohc_version(void);
IP_PUBLIC Iprohc_interface * iprohc_find_interface(char *ifname);
IP_PUBLIC Ip_err iprohc_add_interface(char *name, Ip_bool have_num, Ip_u8 num);
IP_PUBLIC Ip_err iprohc_del_interface(char *name, Ip_bool have_num, Ip_u8 num);
IP_PUBLIC Ip_err iprohc_remove_interfaces(void);
IP_PUBLIC Ip_err
iprohc_if_find_profile(Iprohc_interface *interface, Ip_u8 profileid);
IP_PUBLIC Ip_err
iprohc_if_add_profile(Iprohc_interface *interface, Ip_u8 profileid);
IP_PUBLIC Ip_err
iprohc_if_del_profile(Iprohc_interface *interface, Ip_u8 profileid);
IP_PUBLIC Ip_s8
iprohc_choose_profile(Iprohc_interface *interface, Ipcom_pkt *pkt);
IP_PUBLIC Ip_s8
iprohc_d_choose_profile(Iprohc_interface *interface, Ipcom_pkt *pkt);
/* Feedback functions */
IP_PUBLIC Iprohc_feedback *
iprohc_create_feedback_1(Iprohc_d_context *d_context,
Ip_u16 sn);
IP_PUBLIC Iprohc_feedback *
iprohc_create_feedback_2(Iprohc_d_context *d_context,
Iprohc_feedback_acktype acktype,
Ip_u16 sn);
IP_PUBLIC Ip_err
iprohc_feedback_add_option(Iprohc_feedback *feedback,
Iprohc_feedback_opt opt_type,
Ip_u8 opt_len,
Ip_u8 opt_data);
IP_PUBLIC Ip_err
iprohc_preappend_feedback(Iprohc_interface *interface,
Ip_u8 profileid, Iprohc_c_context *c_context,
Ipcom_pkt *pkt);
IP_PUBLIC Ip_err iprohc_find_profile(Ip_u8 profileid);
IP_PUBLIC Ip_err iprohc_add_profile(Ip_u8 profileid);
IP_PUBLIC Ip_err iprohc_del_profile(Ip_u8 profileid);
IP_PUBLIC void iprohc_update_rnd_nbo(Ip_u16 old_ipid, Ip_u16 ipid,
Ip_bool *rnd, Ip_bool *nbo, Ip_bool *sid);
/* CRC calculation */
IP_PUBLIC Ip_u8 iprohc_crc3(Ip_u8 *data, int len);
IP_PUBLIC Ip_u8 iprohc_crc7(Ip_u8 *data, int len);
IP_PUBLIC Ip_u8 iprohc_crc8(Ip_u8 *data, int len);
/* Debug utilities */
IP_PUBLIC char * iprohc_profile(Ip_u8 profile_id);
IP_PUBLIC void iprohc_print_pkt(Ipcom_pkt *pkt);
IP_PUBLIC char * iprohc_pkt_type(Ip_u8 pkt_type);
IP_PUBLIC char * iprohc_context_mode(Iprohc_mode mode);
IP_PUBLIC char * iprohc_ext_type(Iprohc_extension extension);
IP_PUBLIC void iprohc_print_feedback(Iprohc_feedback *feedback);
#ifndef IP_PORT_VXWORKS /* for Linux recursive semaphore */
IP_PUBLIC void iprohc_lck(void);
IP_PUBLIC void iprohc_unlck(void);
IP_PUBLIC void iprohc_if_lck(Iprohc_interface *interface);
IP_PUBLIC void iprohc_if_unlck(Iprohc_interface *interface);
#endif /* !IP_PORT_VXWORKS */
#ifdef __cplusplus
}
#endif
#endif /* #ifndef IPROHC_H */
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/