original files of m241
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/* 00folder_ipnet_rohc.cdf - ROHC configuration 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
|
||||
--------------------
|
||||
01e,22feb10,ggz Add TCP/IP profile components
|
||||
01d,18dec09,ggz Add ESP/IP, UDP/IP profile components
|
||||
01c,12aug08,tlu Move ROHC to network protocol folder
|
||||
01b,27feb08,tlu Add profile folder
|
||||
01a,21feb08,tlu Created.
|
||||
*/
|
||||
|
||||
#ifdef _WRS_CONFIG_COMPONENT_IPROHC
|
||||
|
||||
Folder FOLDER_ROHC {
|
||||
NAME ROHC Components
|
||||
SYNOPSIS Robust Header Compression Components
|
||||
CHILDREN INCLUDE_IPROHC \
|
||||
FOLDER_ROHC_PROFILES \
|
||||
INCLUDE_IPROHC_CMD
|
||||
_CHILDREN FOLDER_NET_L3_NETWORK
|
||||
}
|
||||
|
||||
Folder FOLDER_ROHC_PROFILES {
|
||||
NAME ROHC Profile Components
|
||||
SYNOPSIS Folder for Robust Header Compression Profile Components
|
||||
CHILDREN INCLUDE_IPROHC_PROFILE_UNCOMPRESSED \
|
||||
INCLUDE_IPROHC_PROFILE_IP \
|
||||
INCLUDE_IPROHC_PROFILE_ESP_IP \
|
||||
INCLUDE_IPROHC_PROFILE_UDP_IP \
|
||||
INCLUDE_IPROHC_PROFILE_TCP_IP
|
||||
_CHILDREN FOLDER_ROHC
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,161 @@
|
||||
/* 02comp_ipnet_rohc.cdf - ROHC configuration 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
|
||||
--------------------
|
||||
01e,22feb10,ggz Add TCP/IP profile components
|
||||
01d,18dec09,ggz Add ESP/IP, UDP/IP profile components
|
||||
01c,16apr08,tlu Add F_MAX_PERIOD and F_MAX_TIME configuration parameters
|
||||
01b,27feb08,tlu Add profile components
|
||||
01a,21feb08,tlu Created.
|
||||
*/
|
||||
|
||||
#ifdef _WRS_CONFIG_COMPONENT_IPROHC
|
||||
|
||||
Component INCLUDE_IPROHC {
|
||||
NAME ROHC
|
||||
SYNOPSIS Robust Header Compression
|
||||
MODULES iprohc.o
|
||||
CONFIGLETTES iprohc_config.c
|
||||
CFG_PARAMS ROHC_INTERFACES \
|
||||
ROHC_INTERFACE_PROFILES \
|
||||
ROHC_MAX_CID \
|
||||
ROHC_LARGE_CID \
|
||||
ROHC_FEEDBACK_FOR_DEFINED \
|
||||
ROHC_FEEDBACK_FOR \
|
||||
ROHC_F_MAX_PERIOD \
|
||||
ROHC_F_MAX_TIME
|
||||
}
|
||||
|
||||
Component INCLUDE_IPROHC_CMD {
|
||||
NAME ROHC commands
|
||||
SYNOPSIS IPCOM shell commands for robust header compression
|
||||
MODULES iprohc_cmd_rohc.o
|
||||
REQUIRES INCLUDE_IPCOM_SHELL_CMD INCLUDE_IPROHC
|
||||
}
|
||||
|
||||
Component INCLUDE_IPROHC_PROFILE_IP {
|
||||
NAME ROHC IP Compression Profile
|
||||
SYNOPSIS ROHC IP Compression Profile component
|
||||
MODULES iprohc_ip.o
|
||||
REQUIRES INCLUDE_IPROHC
|
||||
}
|
||||
|
||||
Component INCLUDE_IPROHC_PROFILE_UNCOMPRESSED {
|
||||
NAME ROHC Uncompressed Profile
|
||||
SYNOPSIS ROHC Uncompressed Profile component
|
||||
MODULES iprohc_uncompressed.o
|
||||
REQUIRES INCLUDE_IPROHC
|
||||
}
|
||||
|
||||
Component INCLUDE_IPROHC_PROFILE_ESP_IP {
|
||||
NAME ROHC ESP/IP Profile
|
||||
SYNOPSIS ROHC ESP/IP Profile component
|
||||
MODULES iprohc_esp_ip.o
|
||||
REQUIRES INCLUDE_IPROHC
|
||||
}
|
||||
|
||||
Component INCLUDE_IPROHC_PROFILE_UDP_IP {
|
||||
NAME ROHC UDP/IP Profile
|
||||
SYNOPSIS ROHC UDP/IP Profile component
|
||||
MODULES iprohc_udp_ip.o
|
||||
REQUIRES INCLUDE_IPROHC
|
||||
}
|
||||
|
||||
Component INCLUDE_IPROHC_PROFILE_TCP_IP {
|
||||
NAME ROHC TCP/IP Profile
|
||||
SYNOPSIS ROHC TCP/IP Profile component
|
||||
MODULES iprohc_tcp_ip.o
|
||||
REQUIRES INCLUDE_IPROHC
|
||||
}
|
||||
|
||||
/******************** Configuration Parameters *****************************/
|
||||
|
||||
Parameter ROHC_INTERFACES {
|
||||
NAME Interface List
|
||||
SYNOPSIS List of interfaces on which the ROHC compresses and \
|
||||
decompresses the packets. e.g., "fei,1,fei,2"
|
||||
TYPE char *
|
||||
DEFAULT ""
|
||||
}
|
||||
|
||||
Parameter ROHC_INTERFACE_PROFILES {
|
||||
NAME Interface Profile List
|
||||
SYNOPSIS List of supported interface-profiles on which ROHC compresses \
|
||||
and decompresses the packets. The format is a \
|
||||
semicolon-separated list of interface-profile list, e.g., \
|
||||
"fei1,0;fei2,4", where means the interface fei1 supports \
|
||||
the profile 0 (uncompressed profile), and the interface fei2 \
|
||||
supports the profile 4 (IP profile).
|
||||
TYPE char *
|
||||
DEFAULT ""
|
||||
}
|
||||
|
||||
Parameter ROHC_MAX_CID {
|
||||
NAME Maximum Context Identifier
|
||||
SYNOPSIS A nonnegative integer, the highest context identifier \
|
||||
number to be used by the compressor. Refer to RFC 3095, \
|
||||
section 5.1.1.
|
||||
TYPE char *
|
||||
DEFAULT "15"
|
||||
}
|
||||
|
||||
Parameter ROHC_LARGE_CID {
|
||||
NAME Used Context Identifier Representation
|
||||
SYNOPSIS Specifies what CID representation is used. If set to "0", \
|
||||
the short CID representation (0 byte or 1 prefix byte, \
|
||||
covering CID 0 to 15) is used; if set to "1", the embedded \
|
||||
CID representation (1 or 2 embedded CID bytes, covering \
|
||||
CID 0 to 16383) is used. Refer to RFC 3095, section 5.1.1.
|
||||
TYPE char *
|
||||
DEFAULT "0"
|
||||
}
|
||||
|
||||
Parameter ROHC_FEEDBACK_FOR_DEFINED {
|
||||
NAME FEEDBACK_FOR Parameter Defined
|
||||
SYNOPSIS Control whetherFEEDBACK_FOR parameter is defined. If set \
|
||||
to "1", the FEEDBACK_FOR parameter is defined. If set \
|
||||
to "0", the FEEDBACK_FOR parameter is not defined.
|
||||
TYPE char *
|
||||
DEFAULT "0"
|
||||
}
|
||||
|
||||
Parameter ROHC_FEEDBACK_FOR {
|
||||
NAME Feedback Channel
|
||||
SYNOPSIS Specifies which channel any feedback refers to. \
|
||||
Refer to RFC 3095, section 5.1.1.
|
||||
TYPE char *
|
||||
DEFAULT "5"
|
||||
}
|
||||
|
||||
Parameter ROHC_F_MAX_PERIOD {
|
||||
NAME Maximum number of consecutive compressed headers
|
||||
SYNOPSIS Specifies the largest number of compressed headers that \
|
||||
may be sent without sending a full header. The valid range \
|
||||
is [1, 65535]. The default value is 256. \
|
||||
Refer to RFC 2507, section 14.
|
||||
TYPE char *
|
||||
DEFAULT "256"
|
||||
}
|
||||
|
||||
Parameter ROHC_F_MAX_TIME {
|
||||
NAME Maximum time period of consecutive compressed headers
|
||||
SYNOPSIS Specifies the maximum time period in seconds that compressed \
|
||||
headers may be sent without sending a full header. The valid \
|
||||
range is [1, 255]. The default value is 60. \
|
||||
Refer to RFC 2507, section 14.
|
||||
TYPE char *
|
||||
DEFAULT "60"
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
# Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: common.vxconfig,v $ $Revision: 1.5 $
|
||||
# $Source: /home/interpeak/CVSRoot/iprohc/config/common.vxconfig,v $
|
||||
# $Author: myakan $
|
||||
# $State: Exp $ $Locker: $
|
||||
#
|
||||
# INTERPEAK_COPYRIGHT_STRING
|
||||
|
||||
#hidden option that enables IPROHC
|
||||
config SUPPORTS_ROHC
|
||||
bool
|
||||
default y
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
/* iprohc_config.c - ROHC Component configellete 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
|
||||
--------------------
|
||||
01d,22feb10,ggz Add TCP/IP profile components
|
||||
01c,18dec09,ggz Add ESP/UDP profiles
|
||||
01b,20feb09,tlu Ported to LKM
|
||||
01a,20feb08,tlu created.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
#if 0
|
||||
#include "iprohc_config.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "ipcom_cstyle.h"
|
||||
#include "ipcom_err.h"
|
||||
#include "ipcom_sysvar.h"
|
||||
#include "ipcom_shell.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ROHC_INTERFACES
|
||||
#define ROHC_INTERFACES ""
|
||||
#endif
|
||||
|
||||
#ifndef ROHC_INTERFACE_PROFILES
|
||||
#define ROHC_INTERFACE_PROFILES ""
|
||||
#endif
|
||||
|
||||
#ifndef ROHC_MAX_CID
|
||||
#define ROHC_MAX_CID "15"
|
||||
#endif
|
||||
|
||||
#ifndef ROHC_LARGE_CID
|
||||
#define ROHC_LARGE_CID "0"
|
||||
#endif
|
||||
|
||||
#ifndef ROHC_FEEDBACK_FOR_DEFINED
|
||||
#define ROHC_FEEDBACK_FOR_DEFINED "0"
|
||||
#endif
|
||||
|
||||
#ifndef ROHC_FEEDBACK_FOR
|
||||
#define ROHC_FEEDBACK_FOR "5"
|
||||
#endif
|
||||
|
||||
#ifndef ROHC_F_MAX_PERIOD
|
||||
#define ROHC_F_MAX_PERIOD "256"
|
||||
#endif
|
||||
|
||||
#ifndef ROHC_F_MAX_TIME
|
||||
#define ROHC_F_MAX_TIME "60"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(WRS_IPNET) && !defined(PRJ_BUILD)
|
||||
#define INCLUDE_IPROHC_CMD
|
||||
#define INCLUDE_IPROHC_PROFILE_IP
|
||||
#define INCLUDE_IPROHC_PROFILE_UNCOMPRESSED
|
||||
#define INCLUDE_IPROHC_PROFILE_ESP_IP
|
||||
#define INCLUDE_IPROHC_PROFILE_UDP_IP
|
||||
#define INCLUDE_IPROHC_PROFILE_TCP_IP
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef INCLUDE_IPROHC_CMD
|
||||
IP_PUBLIC int iprohc_cmd_rohc(int argc, char **argv);
|
||||
#endif /* INCLUDE_IPROHC_CMD */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_IP
|
||||
IP_PUBLIC Ip_err iprohc_profile_ip_register(void);
|
||||
#endif /* INCLUDE_IPROHC_PROFILE_IP */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_UNCOMPRESSED
|
||||
IP_PUBLIC Ip_err iprohc_profile_uncompressed_register(void);
|
||||
#endif /* INCLUDE_IPROHC_PROFILE_UNCOMPRESSED */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_ESP_IP
|
||||
IP_PUBLIC Ip_err iprohc_profile_esp_ip_register(void);
|
||||
#endif /* INCLUDE_IPROHC_PROFILE_ESP_IP */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_UDP_IP
|
||||
IP_PUBLIC Ip_err iprohc_profile_udp_ip_register(void);
|
||||
#endif /* INCLUDE_IPROHC_PROFILE_UDP_IP */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_TCP_IP
|
||||
IP_PUBLIC Ip_err iprohc_profile_tcp_ip_register(void);
|
||||
#endif /* INCLUDE_IPROHC_PROFILE_TCP_IP */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC Ip_err iprohc_configure(void);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* SYSVAR CONFIGURATION
|
||||
*===========================================================================
|
||||
* Refer to CDF file for detailed explanation.
|
||||
*/
|
||||
|
||||
IP_STATIC IP_CONST Ipcom_sysvar iprohc_conf_sysvar[] =
|
||||
{
|
||||
/* ROHC compression/decompression interface list. e.g. "fei,1" */
|
||||
{ "iprohc.interface_list", ROHC_INTERFACES },
|
||||
|
||||
/* ROHC compression/decompression interface-profile list. */
|
||||
/* e.g. "fei1,0;fei2,4" */
|
||||
{ "iprohc.interface_profile_list", ROHC_INTERFACE_PROFILES },
|
||||
|
||||
/* A nonnegative integer, highest context ID number, default 15 */
|
||||
{ "iprohc.max_cid", ROHC_MAX_CID },
|
||||
|
||||
/* Used CID representation, e.g. "0" */
|
||||
{ "iprohc.large_cid", ROHC_LARGE_CID },
|
||||
|
||||
/* Define whether feedback for parameter is defined, default 0 */
|
||||
{ "iprohc.feedback_for_defined", ROHC_FEEDBACK_FOR_DEFINED },
|
||||
|
||||
/* The channel feedback for, refer to RFC 3095, section 5.1.1, e.g. 5 */
|
||||
{ "iprohc.feedback_for", ROHC_FEEDBACK_FOR },
|
||||
|
||||
/* Maximum number of consecutive compressed headers, */
|
||||
/* refer to RFC 2507, section 14 */
|
||||
{ "iprohc.f_max_period", ROHC_F_MAX_PERIOD },
|
||||
|
||||
/* Maximum time period in seconds of consecutive compressed headers, */
|
||||
/* refer to RFC 2507, section 14 */
|
||||
{ "iprohc.f_max_time", ROHC_F_MAX_TIME },
|
||||
|
||||
{ IP_NULL, IP_NULL }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_configure
|
||||
*===========================================================================
|
||||
* Description: ROHC configuration function
|
||||
* Parameters: none
|
||||
* Returns: IPCOM_SUCCESS
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_configure(void)
|
||||
{
|
||||
/* Initialize IPROHC system variables. */
|
||||
(void)ipcom_sysvar_setv(iprohc_conf_sysvar, 0);
|
||||
|
||||
#ifdef INCLUDE_IPROHC_CMD
|
||||
/* Add the ROHC command */
|
||||
(void)ipcom_shell_add_cmd("rohc", "rohc [command] <modifier...>",
|
||||
"ROHC", iprohc_cmd_rohc,
|
||||
IPCOM_SHELL_PRIO_SAME, IPCOM_PROC_STACK_DEFAULT);
|
||||
#endif /* INCLUDE_IPROHC_CMD */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_IP
|
||||
/* Register IP compression profile */
|
||||
iprohc_profile_ip_register();
|
||||
#endif /* INCLUDE_IPROHC_IP */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_UNCOMPRESSED
|
||||
/* Add uncompressed profile, id = 0 */
|
||||
iprohc_profile_uncompressed_register();
|
||||
#endif /* INCLUDE_IPROHC_UNCOMPRESSED */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_ESP_IP
|
||||
/* Register ESP_IP compression profile */
|
||||
iprohc_profile_esp_ip_register();
|
||||
#endif /* INCLUDE_IPROHC_ESP_IP */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_UDP_IP
|
||||
/* Register UDP_IP compression profile */
|
||||
iprohc_profile_udp_ip_register();
|
||||
#endif /* INCLUDE_IPROHC_UDP_IP */
|
||||
|
||||
#ifdef INCLUDE_IPROHC_PROFILE_TCP_IP
|
||||
/* Register TCP_IP compression profile */
|
||||
iprohc_profile_tcp_ip_register();
|
||||
#endif /* INCLUDE_IPROHC_TCP_IP */
|
||||
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2008 Wind River Systems, Inc.
|
||||
*
|
||||
* The right to copy, distribute, modify or otherwise make use
|
||||
* of this software may be licensed only pursuant to the terms
|
||||
* of an applicable Wind River license agreement.
|
||||
*/
|
||||
|
||||
/*
|
||||
modification history
|
||||
--------------------
|
||||
01c,11aug08,tlu Add ROHC address type definition
|
||||
01b,26may08,tlu Add compile flag for WLSB/LSB encoding/decoding
|
||||
01a,20feb08,tlu Initial creation
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_CONFIG_H
|
||||
#define IPROHC_CONFIG_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_inet.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Syslog priority */
|
||||
#ifdef IP_DEBUG
|
||||
#define IPROHC_SYSTEM_PRIORITY IPCOM_LOG_DEBUG
|
||||
#else
|
||||
#define IPROHC_SYSTEM_PRIORITY IPCOM_LOG_WARNING
|
||||
#endif
|
||||
|
||||
/* compile flag for WLSB/LSB encoding/decoding */
|
||||
#undef IPROHC_WLSB_LSB
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
typedef union Iprohc_addr_union
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
Ipa_union addr4;
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
struct Ip_in6_addr addr6;
|
||||
#endif
|
||||
}
|
||||
Iprohc_addr;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
@@ -0,0 +1,10 @@
|
||||
IPTARGETS := lib
|
||||
ifneq ($(IPMAKEFILE),)
|
||||
include $(IPMAKEFILE)
|
||||
else
|
||||
include $(IPCOM_ROOT)/Makefile
|
||||
endif
|
||||
include iprohc.mk
|
||||
include $(IPCOM_ROOT)/gmake/ipcom_make.mk
|
||||
|
||||
lib: dirs $(IPLIBFILE)
|
||||
@@ -0,0 +1,117 @@
|
||||
# /*
|
||||
# * Copyright 2008 Wind River Systems, Inc.
|
||||
# *
|
||||
# * The right to copy, distribute, modify or otherwise make use
|
||||
# * of this software may be licensed only pursuant to the terms
|
||||
# * of an applicable Wind River license agreement.
|
||||
# */
|
||||
|
||||
# /*
|
||||
# modification history
|
||||
# --------------------
|
||||
# 01d,20may10,ggz Add TCP/IP profile files
|
||||
# 01c,16dec09,ggz Add ESP/UDP profile files
|
||||
# 01b,28mar08,tlu Add more files
|
||||
# 01a,20feb08,tlu Initial creation
|
||||
# */
|
||||
|
||||
|
||||
#############################################################################
|
||||
# PRODUCT
|
||||
###########################################################################
|
||||
|
||||
IPPROD ?= iprohc
|
||||
|
||||
|
||||
#############################################################################
|
||||
# DEFINE
|
||||
###########################################################################
|
||||
|
||||
IPDEFINE += -DIPROHC
|
||||
|
||||
|
||||
#############################################################################
|
||||
# INCLUDE
|
||||
###########################################################################
|
||||
|
||||
IPINCLUDE += -I$(IPROHC_ROOT)/config
|
||||
IPINCLUDE += -I$(IPROHC_ROOT)/include
|
||||
IPINCLUDE += -I$(IPROHC_ROOT)/src
|
||||
|
||||
|
||||
#############################################################################
|
||||
# OBJECTS
|
||||
###########################################################################
|
||||
|
||||
# Configuration
|
||||
IPLIBOBJECTS_C += iprohc_config.o
|
||||
|
||||
# Main
|
||||
IPLIBOBJECTS += iprohc.o
|
||||
IPLIBOBJECTS += iprohc_comp.o
|
||||
IPLIBOBJECTS += iprohc_decomp.o
|
||||
IPLIBOBJECTS += iprohc_util.o
|
||||
IPLIBOBJECTS += iprohc_parser.o
|
||||
IPLIBOBJECTS += iprohc_format.o
|
||||
IPLIBOBJECTS += iprohc_feedback.o
|
||||
IPLIBOBJECTS += iprohc_ip.o
|
||||
IPLIBOBJECTS += iprohc_esp_ip.o
|
||||
IPLIBOBJECTS += iprohc_udp_ip.o
|
||||
IPLIBOBJECTS += iprohc_tcp_ip.o
|
||||
IPLIBOBJECTS += iprohc_uncompressed.o
|
||||
IPLIBOBJECTS += iprohc_coding_util.o
|
||||
|
||||
ifneq ($(IPPORT),lkm)
|
||||
IPLIBOBJECTS += iprohc_cmd_rohc.o
|
||||
endif
|
||||
|
||||
# Compiles the xxx_config.o if the $SKIP_CONFIG macro is either not defined
|
||||
# or set to anything other than true.
|
||||
ifneq ($(SKIP_CONFIG),true)
|
||||
IPLIBOBJECTS += $(IPLIBOBJECTS_C)
|
||||
endif
|
||||
|
||||
|
||||
#############################################################################
|
||||
# VPATH
|
||||
###########################################################################
|
||||
|
||||
IPSRCDIRS += $(IPROHC_ROOT)/src $(IPROHC_ROOT)/config
|
||||
|
||||
|
||||
#############################################################################
|
||||
# LIB
|
||||
###########################################################################
|
||||
|
||||
IPLIBS += $(IPLIBROOT)/libiprohc.a
|
||||
|
||||
|
||||
#############################################################################
|
||||
# BINARIES
|
||||
#############################################################################
|
||||
|
||||
ifeq ($(IPPORT),las)
|
||||
# Path to binaries
|
||||
IPCMDDIR := $(IPOBJDIR)/bin
|
||||
|
||||
# List of shell commands to build
|
||||
IPROHCSHELLCMDS = rohc
|
||||
_IPROHCSHELLCMDS = $(addprefix $(IPCMDDIR)/,$(IPROHCSHELLCMDS))
|
||||
|
||||
bin: $(_IPROHCSHELLCMDS)
|
||||
|
||||
$(IPOBJDIR)/iprohc_cmd_%.o: $(IPROHC_ROOT)/src/iprohc_cmd_%.c
|
||||
@$(IPECHO) "+++ Compiling IPROHC shell command $<"
|
||||
$(IPVERB)$(IPCC) -Diprohc_cmd_$*=ipcom_cmd_entry_point $(IPCFLAGS) -o $@ $<
|
||||
|
||||
|
||||
$(IPCMDDIR)/%: $(IPOBJDIR)/iprohc_cmd_%.o $(IPOBJDIR)/ipcom_shell_cmd_stub.o
|
||||
@$(IPECHO) "+++ Linking IPROHC shell command $@"
|
||||
$(IPVERB)$(IPLD) -o $@ $(IPLDFLAGS) $^ $(IPLIBS) $(IPLIBS) $(IPLIBS) $(IPLASTLIBS)
|
||||
|
||||
endif
|
||||
|
||||
|
||||
###########################################################################
|
||||
# END OF IPROHC.MK
|
||||
###########################################################################
|
||||
@@ -0,0 +1,480 @@
|
||||
/* 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
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
/* 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
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,463 @@
|
||||
/* iprohc_comp.h - ROHC compressor 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
|
||||
--------------------
|
||||
01j,05Jul12,ggz Defect WIND00351290. Use ipcom_mutex_lock for unix port
|
||||
01i,20oct11,ggz Fix for defect WIND00312450
|
||||
01h,27mar10,ggz Resolve coverity warnings
|
||||
01g,24feb09,tlu Replace ipcom_tmo by ipnet_timeout to port to LKM
|
||||
01f,15jul08,tlu Add CID bit map fields
|
||||
01e,17jun08,tlu Add functin to modify next context ID
|
||||
01d,30may08,ggz Add Normal state for uncompressed profile
|
||||
01c,12may08,tlu Add debugging utilities
|
||||
01b,29apr08,tlu Add CRC validation for feedback with CRC option
|
||||
01a,06mar08,tlu Created.
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_COMP_H
|
||||
#define IPROHC_COMP_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_tags.h>
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_list.h>
|
||||
#include <ipnet_timeout.h>
|
||||
|
||||
|
||||
#include "iprohc_config.h"
|
||||
#include "iprohc_constant.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPROHC_ENABLE_REENTRANT
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
|
||||
#if defined(IP_PORT_VXWORKS) || defined(IP_PORT_UNIX)
|
||||
|
||||
#define IPROHC_COMP_LOCK(comp) ipcom_mutex_lock((comp)->code_mutex)
|
||||
#define IPROHC_COMP_UNLOCK(comp) ipcom_mutex_unlock((comp)->code_mutex)
|
||||
|
||||
#define IPROHC_C_CONTEXT_LOCK(context) ipcom_mutex_lock((context)->code_mutex)
|
||||
#define IPROHC_C_CONTEXT_UNLOCK(context) ipcom_mutex_unlock((context)->code_mutex)
|
||||
|
||||
#else /* NOTIP_PORT_VXWORKS, for linux recursive semaphore */
|
||||
|
||||
#define IPROHC_COMP_LOCK(comp) iprohc_comp_lck(comp)
|
||||
#define IPROHC_COMP_UNLOCK(comp) iprohc_comp_unlck(comp)
|
||||
|
||||
#define IPROHC_C_CONTEXT_LOCK(context) iprohc_c_context_lck(context)
|
||||
#define IPROHC_C_CONTEXT_UNLOCK(context) iprohc_c_context_unlck(context)
|
||||
|
||||
#endif /* IP_PORT_VXWORKS */
|
||||
|
||||
#else
|
||||
|
||||
#define IPROHC_COMP_LOCK(comp) IP_NOOP
|
||||
#define IPROHC_COMP_UNLOCK(comp) IP_NOOP
|
||||
|
||||
#define IPROHC_C_CONTEXT_LOCK(context) IP_NOOP
|
||||
#define IPROHC_C_CONTEXT_UNLOCK(context) IP_NOOP
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_ACK_FEEDBACK
|
||||
*===========================================================================
|
||||
* Process ACK feedback.
|
||||
*/
|
||||
#define IPROHC_ACK_FEEDBACK(context) \
|
||||
{ \
|
||||
if (context->state == ROHC_COMP_STATE_IR) \
|
||||
{ \
|
||||
if (context->trans == ROHC_COMP_TRANS_PENDING) \
|
||||
{ \
|
||||
context->state = ROHC_COMP_STATE_FO; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
context->state = ROHC_COMP_STATE_SO; \
|
||||
context->pkt_type = ROHC_PKT_TYPE_0; \
|
||||
context->ext_type = ROHC_EXT_NO_EXT; \
|
||||
} \
|
||||
} \
|
||||
else if ((context->state == ROHC_COMP_STATE_FO) && \
|
||||
(context->trans != ROHC_COMP_TRANS_PENDING)) \
|
||||
{ \
|
||||
context->state = ROHC_COMP_STATE_SO; \
|
||||
context->pkt_type = ROHC_PKT_TYPE_0; \
|
||||
context->ext_type = ROHC_EXT_NO_EXT; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_PROCESS_FEEDBACK_OPT
|
||||
*===========================================================================
|
||||
* Process feedback options.
|
||||
*/
|
||||
#define IPROHC_PROCESS_FEEDBACK_OPT(context, feedback, pointer, size) \
|
||||
{ \
|
||||
Ip_u8 opt_type, cal_crc, opt_crc; \
|
||||
\
|
||||
while (pointer+1 <= size) \
|
||||
{ \
|
||||
opt_type = (feedback[pointer] & 0xF0) >> 4; \
|
||||
switch (opt_type) \
|
||||
{ \
|
||||
case ROHC_FEEDBACK_OPT_CRC: \
|
||||
/* CRC validation */ \
|
||||
opt_crc = feedback[pointer+1]; \
|
||||
feedback[pointer+1] = 0; \
|
||||
cal_crc = iprohc_crc8((Ip_u8 *)feedback, size); \
|
||||
if (cal_crc != opt_crc) \
|
||||
{ /* Failed CRC validation, discard the feedback element */ \
|
||||
IPROHC_C_CONTEXT_UNLOCK(context); \
|
||||
return IPCOM_ERR_INVALID_PACKET; \
|
||||
} \
|
||||
pointer = (Ip_u8)(pointer + 2); \
|
||||
break; \
|
||||
case ROHC_FEEDBACK_OPT_REJ: \
|
||||
/* Set up reject flag in context, not used */ \
|
||||
context->reject = IP_TRUE; \
|
||||
pointer ++; \
|
||||
break; \
|
||||
case ROHC_FEEDBACK_OPT_SN_NOT_VALID: \
|
||||
/* Not using SN in feedback currently */ \
|
||||
pointer ++; \
|
||||
break; \
|
||||
case ROHC_FEEDBACK_OPT_SN: \
|
||||
/* Not using SN in feedback currently */ \
|
||||
pointer = (Ip_u8)(pointer + 2); \
|
||||
break; \
|
||||
case ROHC_FEEDBACK_OPT_LOSS: \
|
||||
/* Not used */ \
|
||||
pointer = (Ip_u8)(pointer + 2); \
|
||||
break; \
|
||||
case ROHC_FEEDBACK_OPT_CONTEXT_MEMORY: \
|
||||
/* Not used */ \
|
||||
pointer ++; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_PROCESS_MODE
|
||||
*===========================================================================
|
||||
* Process mode field from feedback.
|
||||
*/
|
||||
#define IPROHC_PROCESS_MODE(context, mode) \
|
||||
{ \
|
||||
if (context->mode == mode) \
|
||||
{ \
|
||||
if (context->trans == ROHC_COMP_TRANS_PENDING) \
|
||||
{ \
|
||||
context->trans = ROHC_COMP_TRANS_DONE; \
|
||||
context->decline_mode_trans = IP_FALSE; \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
if (context->trans == ROHC_COMP_TRANS_PENDING) \
|
||||
{ \
|
||||
context->decline_mode_trans = IP_TRUE; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
context->trans = ROHC_COMP_TRANS_PENDING; \
|
||||
context->mode = mode; \
|
||||
} \
|
||||
context->pkt_type = ROHC_PKT_TYPE_2; \
|
||||
context->ext_type = ROHC_EXT_3; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_PROCESS_ACKTYPE
|
||||
*===========================================================================
|
||||
* Process acktype field from feedback.
|
||||
*/
|
||||
#define IPROHC_PROCESS_ACKTYPE(context, acktype) \
|
||||
{ \
|
||||
if (acktype == ROHC_FEEDBACK_ACK) \
|
||||
{ \
|
||||
IPROHC_ACK_FEEDBACK(context); \
|
||||
} \
|
||||
else if (acktype == ROHC_FEEDBACK_NACK) \
|
||||
{ \
|
||||
if (context->state == ROHC_COMP_STATE_SO) \
|
||||
context->state = ROHC_COMP_STATE_FO; \
|
||||
context->pkt_type = ROHC_PKT_IR_DYN; \
|
||||
context->ext_type = ROHC_EXT_NO_EXT; \
|
||||
} \
|
||||
else if (acktype == ROHC_FEEDBACK_STATIC_NACK) \
|
||||
{ \
|
||||
context->state = ROHC_COMP_STATE_IR; \
|
||||
context->pkt_type = ROHC_PKT_IR; \
|
||||
context->ext_type = ROHC_EXT_NO_EXT; \
|
||||
context->num_ir = 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Compressor states
|
||||
*===========================================================================
|
||||
* refer to RFC 3095, section 4.3.1
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ROHC_COMP_STATE_IR = 1,
|
||||
ROHC_COMP_STATE_FO,
|
||||
ROHC_COMP_STATE_SO,
|
||||
ROHC_COMP_STATE_NORMAL
|
||||
} Iprohc_comp_state;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Compressor mode transitions
|
||||
*===========================================================================
|
||||
* refer to RFC 3095, section 5.6.1
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ROHC_COMP_TRANS_DONE = 0,
|
||||
ROHC_COMP_TRANS_PENDING
|
||||
} Iprohc_comp_trans;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* Public TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
struct Iprohc_compressor;
|
||||
struct Iprohc_interface;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_c_context
|
||||
*===========================================================================
|
||||
* This is the ROHC compression context structure
|
||||
*/
|
||||
|
||||
typedef struct Iprohc_c_context_struct
|
||||
{
|
||||
Ipcom_list context_list;
|
||||
|
||||
/* CID allocated for the context */
|
||||
Ip_u16 cid;
|
||||
|
||||
/* compression state */
|
||||
Iprohc_comp_state state;
|
||||
|
||||
/* compression mode */
|
||||
Iprohc_mode mode;
|
||||
|
||||
/* Decline mode transition, RFC 3843, section 3.4 */
|
||||
Ip_bool decline_mode_trans;
|
||||
|
||||
/* compression mode transition */
|
||||
Iprohc_comp_trans trans;
|
||||
|
||||
/* to-be-transmitted compression packet type */
|
||||
Ip_u8 pkt_type;
|
||||
|
||||
/* to-be-transmitted entension type */
|
||||
Iprohc_extension ext_type;
|
||||
|
||||
/* Whether received reject option from feedback */
|
||||
Ip_bool reject;
|
||||
|
||||
/* number of consecutively transmitted IR packets */
|
||||
Ip_u32 num_ir;
|
||||
|
||||
/* number of consecutively transmitted compressed packets */
|
||||
Ip_u32 num_compressed;
|
||||
|
||||
/* stream type: IPv4 or IPv6, for feedback processing */
|
||||
Ip_u8 stream_type;
|
||||
|
||||
/* destination address of the stream, for feedback processing */
|
||||
Iprohc_addr dst;
|
||||
|
||||
/* source address of the stream */
|
||||
Iprohc_addr src;
|
||||
|
||||
/* profile the compressor is associated with */
|
||||
Ip_u8 profileid;
|
||||
|
||||
/* Compressor the context is associated with */
|
||||
struct Iprohc_compressor *compressor;
|
||||
|
||||
/* maximum consecutive compressed header timer: F_MAX_TIME timer */
|
||||
Ipnet_timeout *retx_ir;
|
||||
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
Ipcom_mutex code_mutex; /* Mutex to protect context 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 */
|
||||
|
||||
/* profile specific compression context structure */
|
||||
void *profile_context;
|
||||
}
|
||||
Iprohc_c_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_compressor
|
||||
*===========================================================================
|
||||
* This is the ROHC compressor context structure
|
||||
*/
|
||||
|
||||
typedef struct Iprohc_compressor_struct
|
||||
{
|
||||
/* record the next to be used CID */
|
||||
Ip_u16 to_be_used_cid;
|
||||
|
||||
/* Context list */
|
||||
Ip_u16 context_num; /* number of contexts */
|
||||
Ipcom_list context_head;
|
||||
|
||||
/* interface the compressor is associated with */
|
||||
struct Iprohc_interface *interface;
|
||||
|
||||
/* bit map to record whether a CID is allocated */
|
||||
Ip_u16 *cid_bit_map;
|
||||
Ip_u16 bit_map_size;
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
Ipcom_mutex code_mutex; /* Mutex to protect compressor 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_compressor;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC Iprohc_compressor * iprohc_alloc_compressor(struct Iprohc_interface *interface);
|
||||
IP_PUBLIC Ip_err iprohc_del_compressor(Iprohc_compressor *compressor);
|
||||
IP_PUBLIC Ip_err iprohc_c_del_profile_contexts(Iprohc_compressor *compressor, Ip_u8 profileid);
|
||||
IP_PUBLIC Ip_err iprohc_comp_mod_cid(struct Iprohc_interface *interface,
|
||||
Ip_u8 profileid, Ip_u16 cid);
|
||||
|
||||
IP_PUBLIC Iprohc_c_context * iprohc_c_context_common_create(Ip_u16 cid);
|
||||
IP_PUBLIC Ip_err iprohc_c_context_common_del(Iprohc_c_context *c_context);
|
||||
IP_PUBLIC Ip_err iprohc_c_process_feedback(Iprohc_compressor *compressor,
|
||||
Ip_u8 src_addr_type,
|
||||
void *src_addr,
|
||||
Ip_u16 feedback_num,
|
||||
Ip_u8 *feedbacks);
|
||||
IP_PUBLIC void iprohc_retx_ir_timeout(void *cookie);
|
||||
|
||||
IP_PUBLIC Ip_err iprohc_c_print_context(Iprohc_compressor *compressor, Ip_u8 profile);
|
||||
|
||||
/* Debug functions */
|
||||
IP_PUBLIC void iprohc_c_print_a_context(Iprohc_c_context *context);
|
||||
IP_PUBLIC char * iprohc_comp_state(Iprohc_comp_state state);
|
||||
IP_PUBLIC char * iprohc_comp_trans(Iprohc_comp_trans trans);
|
||||
|
||||
|
||||
#ifndef IP_PORT_VXWORKS /* for Linux recursive semaphore */
|
||||
|
||||
IP_PUBLIC void iprohc_comp_lck(Iprohc_compressor *comp);
|
||||
IP_PUBLIC void iprohc_comp_unlck(Iprohc_compressor *comp);
|
||||
|
||||
IP_PUBLIC void iprohc_c_context_lck(Iprohc_c_context *context);
|
||||
IP_PUBLIC void iprohc_c_context_unlck(Iprohc_c_context *context);
|
||||
|
||||
#endif /* !IP_PORT_VXWORKS */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* #ifndef IPROHC_COMP_H */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
/* iprohc_constant.h - ROHC constants defining 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
|
||||
--------------------
|
||||
01f,14may10,ggz Add TCP/IP profile
|
||||
01e,22feb10,ggz Add ESP/IP,UDP/IP profiles
|
||||
01d,03jul08,tlu Add max number of IP extension header
|
||||
01c,21may08,tlu Add more pkt type and define different MAX CID for
|
||||
small/large CID
|
||||
01b,20may08,tlu Add incremental constant for WLSB/LSB
|
||||
01a,25feb08,tlu Created.
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_CONSTANT_H
|
||||
#define IPROHC_CONSTANT_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
**************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* Max size of a ROHC package. */
|
||||
#define IPROHC_MAX_PKT_SIZE 1440
|
||||
|
||||
/* Max number of ROHC profile IDs. */
|
||||
/* Refer to RFC 3095, section 5.1.2, and RFC 3843, section 3 */
|
||||
/* 0 -- uncompressed profile */
|
||||
/* 1 -- RTP/UDP/IP compression profile */
|
||||
/* 2 -- UDP/IP compression profile */
|
||||
/* 3 -- ESP/IP compression profile */
|
||||
/* 4 -- IP compression profile */
|
||||
/* 5 -- LLA IP/UDP/RTP compression profile */
|
||||
/* 6 -- TCP/IP compression profile */
|
||||
#define IPROHC_MIN_PROFILE_ID 0
|
||||
#define IPROHC_MAX_PROFILE_ID 6
|
||||
#define IPROHC_MAX_PROFILE_IDS 7
|
||||
|
||||
/* Max size of a ROHC interface name. */
|
||||
#define IPROHC_IF_NAME_MAX 16
|
||||
|
||||
/* Max small CID of ROHC context. */
|
||||
#define IPROHC_MAX_SMALL_CID 15
|
||||
|
||||
/* Max large CID of ROHC context. */
|
||||
#define IPROHC_MAX_LARGE_CID 16383
|
||||
|
||||
/* IPv4 header size */
|
||||
#define IPROHC_IP4_HDR_SIZE 20
|
||||
|
||||
/* IPv6 header size */
|
||||
#define IPROHC_IP6_HDR_SIZE 40
|
||||
|
||||
/* Max number of transmitted IR pkts before state changes from IR-->FO/SO */
|
||||
#define IPROHC_MAX_IRS 5
|
||||
|
||||
/* Max length of one ROHC feedback buffer. */
|
||||
#define IPROHC_MAX_FEEDBCK_BUF 20
|
||||
|
||||
/* RFC 3095, 5.3.2.2.3, k_1%n_1 in percentage */
|
||||
#define IPROHC_D_FULL_RATIO 30
|
||||
|
||||
/* RFC 3095, 5.3.2.2.3, k_2%n_2 in percentage */
|
||||
#define IPROHC_D_STATIC_RATIO 40
|
||||
|
||||
/* Increment value for WLSB/LSB */
|
||||
#define IPROHC_LSB_INC -1
|
||||
|
||||
/* Max number of compressed list items */
|
||||
#define IPROHC_MAX_LIST_ITEMS 127
|
||||
|
||||
|
||||
/* IPROHC product name */
|
||||
#define IPROHC_PRODUCT_NAME "WR Robust Header Compression"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ROHC profile IDs
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define ROHC_PROFILE_UNCOMPRESSED 0
|
||||
#define ROHC_PROFILE_RTP_UDP_IP 1
|
||||
#define ROHC_PROFILE_UDP_IP 2
|
||||
#define ROHC_PROFILE_ESP_IP 3
|
||||
#define ROHC_PROFILE_IP 4
|
||||
#define ROHC_PROFILE_LLA_IP_UDP_RTP 5
|
||||
#define ROHC_PROFILE_TCP_IP 6
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ROHC modes
|
||||
*===========================================================================
|
||||
* refer to RFC 3095, section 5.7.6.1, and RFC 3843, section 3.4
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ROHC_MODE_C = 0, /* Used in IR/IR-DYN/UOR-2 to decline a mode transition */
|
||||
ROHC_MODE_U,
|
||||
ROHC_MODE_O,
|
||||
ROHC_MODE_R
|
||||
} Iprohc_mode;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ROHC feedback ACK types
|
||||
*===========================================================================
|
||||
* refer to RFC 3095, section 5.7.6.1
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ROHC_FEEDBACK_ACK = 0,
|
||||
ROHC_FEEDBACK_NACK,
|
||||
ROHC_FEEDBACK_STATIC_NACK
|
||||
} Iprohc_feedback_acktype;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ROHC feedback Options
|
||||
*===========================================================================
|
||||
* refer to RFC 3095, section 5.7.6.2, and RFC 3843, section 3.7
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ROHC_FEEDBACK_OPT_CRC = 1,
|
||||
ROHC_FEEDBACK_OPT_REJ,
|
||||
ROHC_FEEDBACK_OPT_SN_NOT_VALID,
|
||||
ROHC_FEEDBACK_OPT_SN,
|
||||
ROHC_FEEDBACK_OPT_CLOCK,
|
||||
ROHC_FEEDBACK_OPT_JITTER,
|
||||
ROHC_FEEDBACK_OPT_LOSS,
|
||||
ROHC_FEEDBACK_OPT_NOT_USED,
|
||||
ROHC_FEEDBACK_OPT_CONTEXT_MEMORY
|
||||
} Iprohc_feedback_opt;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ROHC packet type codes
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define ROHC_PKT_NORMAL 3
|
||||
#define ROHC_PKT_IPV4 4 /* 0100 */
|
||||
#define ROHC_PKT_IPV6 6 /* 0110 */
|
||||
|
||||
#define ROHC_PKT_COMPRESSED 1
|
||||
#define ROHC_PKT_PAD 224 /* 11100000 */
|
||||
#define ROHC_PKT_ADD_CID 14 /* 1110 */
|
||||
#define ROHC_PKT_FEEDBACK 30 /* 11110 */
|
||||
#define ROHC_PKT_IR_DYN 248 /* 11111000 */
|
||||
#define ROHC_PKT_IR 126 /* 1111110 */
|
||||
#define ROHC_PKT_SEGMENT 127 /* 1111111 */
|
||||
#define ROHC_PKT_TYPE_0 0 /* 0 */
|
||||
#define ROHC_PKT_TYPE_1 2 /* 10 */
|
||||
#define ROHC_PKT_TYPE_2 6 /* 110 */
|
||||
#define ROHC_PKT_COMP_UNCOMPRESSED 5
|
||||
#define ROHC_TCP_PKT_IR 253 /* 11111101 */
|
||||
|
||||
#define ROHC_TCP_PKT_CO 0x7D /* '1111101' */
|
||||
#define ROHC_TCP_PKT_RND_1 0x2E /* '101110' */
|
||||
#define ROHC_TCP_PKT_RND_2 0xC /* '1100' */
|
||||
#define ROHC_TCP_PKT_RND_3 0x0 /* '0' */
|
||||
#define ROHC_TCP_PKT_RND_4 0xD /* '1101' */
|
||||
#define ROHC_TCP_PKT_RND_5 0x4 /* '100' */
|
||||
#define ROHC_TCP_PKT_RND_6 0xA /* '1010' */
|
||||
#define ROHC_TCP_PKT_RND_7 0x2F /* '101111' */
|
||||
#define ROHC_TCP_PKT_RND_8 0x16 /* '10110' */
|
||||
#define ROHC_TCP_PKT_SEQ_1 0xA /* '1010' */
|
||||
#define ROHC_TCP_PKT_SEQ_2 0x1A /* '11010' */
|
||||
#define ROHC_TCP_PKT_SEQ_3 0x9 /* '1001' */
|
||||
#define ROHC_TCP_PKT_SEQ_4 0x0 /* '0' */
|
||||
#define ROHC_TCP_PKT_SEQ_5 0x8 /* '1000' */
|
||||
#define ROHC_TCP_PKT_SEQ_6 0x1B /* '11011' */
|
||||
#define ROHC_TCP_PKT_SEQ_7 0xC /* '1100' */
|
||||
#define ROHC_TCP_PKT_SEQ_8 0xB /* '1011' */
|
||||
#define ROHC_TCP_PKT_NONE 0xFF
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ROHC packet type shift bits
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define ROHC_PKT_IP_SHIFT 4
|
||||
#define ROHC_PKT_ADD_CID_SHIFT 4
|
||||
#define ROHC_PKT_FEEDBACK_SHIFT 3
|
||||
#define ROHC_PKT_IR_DYN_SHIFT 0
|
||||
#define ROHC_PKT_IR_SHIFT 1
|
||||
#define ROHC_PKT_SEGMENT_SHIFT 1
|
||||
#define ROHC_PKT_TYPE_0_SHIFT 7
|
||||
#define ROHC_PKT_TYPE_1_SHIFT 6
|
||||
#define ROHC_PKT_TYPE_2_SHIFT 5
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ROHC extension type codes
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ROHC_EXT_NO_EXT = 0,
|
||||
ROHC_EXT_0,
|
||||
ROHC_EXT_1,
|
||||
ROHC_EXT_2,
|
||||
ROHC_EXT_3
|
||||
} Iprohc_extension;
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* #ifndef IPROHC__CONSTANT_H */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,554 @@
|
||||
/* iprohc_decomp.h - ROHC decompressor 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,05Jul12,ggz Defect WIND00351290. Use ipcom_mutex_lock for unix port
|
||||
01h,26aug11,ggz Fix defect WIND00294683. Incorrect ext order in decompressed packet
|
||||
01g,12apr10,ggz Resolve 64bit compiler warnings
|
||||
01f,20apr09,tlu Fix Linux build warnings for mips64 gcc (cav_ebt5800)
|
||||
01e,08jul08,tlu Add to handle IP extension headers
|
||||
01d,10jun08,tlu Fix to convert payload length to network format for IPv6
|
||||
01c,15may08,tlu Fix the macro to check whether decompression is allowed
|
||||
01b,01may08,tlu Add debug function
|
||||
01a,06mar08,tlu Created.
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_DECOMP_H
|
||||
#define IPROHC_DECOMP_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_tags.h>
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_list.h>
|
||||
|
||||
|
||||
#include "iprohc_config.h"
|
||||
#include "iprohc_constant.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPROHC_ENABLE_REENTRANT
|
||||
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
|
||||
#if defined(IP_PORT_VXWORKS) || defined(IP_PORT_UNIX)
|
||||
|
||||
#define IPROHC_DECOMP_LOCK(decomp) ipcom_mutex_lock((decomp)->code_mutex)
|
||||
#define IPROHC_DECOMP_UNLOCK(decomp) ipcom_mutex_unlock((decomp)->code_mutex)
|
||||
|
||||
#define IPROHC_D_CONTEXT_LOCK(context) ipcom_mutex_lock((context)->code_mutex)
|
||||
#define IPROHC_D_CONTEXT_UNLOCK(context) ipcom_mutex_unlock((context)->code_mutex)
|
||||
|
||||
#else /* !IP_PORT_VXWORKS, Linux recursive semaphore */
|
||||
|
||||
#define IPROHC_DECOMP_LOCK(decomp) iprohc_decomp_lck(decomp)
|
||||
#define IPROHC_DECOMP_UNLOCK(decomp) iprohc_decomp_unlck(decomp)
|
||||
|
||||
#define IPROHC_D_CONTEXT_LOCK(context) iprohc_d_context_lck(context)
|
||||
#define IPROHC_D_CONTEXT_UNLOCK(context) iprohc_d_context_unlck(context)
|
||||
|
||||
#endif /* IP_PORT_VXWORKS */
|
||||
|
||||
#else
|
||||
|
||||
#define IPROHC_DECOMP_LOCK(comp) IP_NOOP
|
||||
#define IPROHC_DECOMP_UNLOCK(comp) IP_NOOP
|
||||
|
||||
#define IPROHC_D_CONTEXT_LOCK(context) IP_NOOP
|
||||
#define IPROHC_D_CONTEXT_UNLOCK(context) IP_NOOP
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_DECOMP_ALLOWED
|
||||
*===========================================================================
|
||||
* Check whether decompression is allowed according to RFC 3095, 5.3.2.2.1:
|
||||
* In Full context state, allow to decompress any type of packets;
|
||||
* In Static context state, only IR, IR-DYN, and UOR-2 packets are allowed;
|
||||
* In No context state, only IR packets are allowed.
|
||||
*/
|
||||
#define IPROHC_DECOMP_ALLOWED(context, pkt_type, sn) \
|
||||
{ \
|
||||
Iprohc_feedback *feedback = IP_NULL; \
|
||||
\
|
||||
if (context->state == ROHC_DECOMP_STATE_NO) \
|
||||
{ \
|
||||
if (pkt_type != ROHC_PKT_IR) \
|
||||
{ \
|
||||
/* Send STATIC-NACK feedback */ \
|
||||
feedback = iprohc_create_feedback_2(context, \
|
||||
ROHC_FEEDBACK_STATIC_NACK, sn); \
|
||||
} \
|
||||
} \
|
||||
else if (context->state == ROHC_DECOMP_STATE_STATIC) \
|
||||
{ \
|
||||
if ((pkt_type != ROHC_PKT_IR) && \
|
||||
(pkt_type != ROHC_PKT_IR_DYN) && \
|
||||
(pkt_type != ROHC_PKT_TYPE_2)) \
|
||||
{ \
|
||||
/* Send NACK feedback */ \
|
||||
feedback = iprohc_create_feedback_2(context, \
|
||||
ROHC_FEEDBACK_NACK, sn); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
if (feedback != IP_NULL) \
|
||||
{ \
|
||||
if (context->trans == ROHC_DECOMP_TRANS_INITIATED) \
|
||||
/* Feedback pkts that initiate the mode transition must */ \
|
||||
/* carry CRC option */ \
|
||||
iprohc_feedback_add_option(feedback, ROHC_FEEDBACK_OPT_CRC, 1, 0); \
|
||||
\
|
||||
IPROHC_ERROUT(IPCOM_ERR_PERMISSION_DENIED); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_RECONSTRUCT_IP_EXT
|
||||
*===========================================================================
|
||||
* Re-construct an IP extension header from the decompressor context:
|
||||
* - Loop through the reference list to re-construct IP extension headers
|
||||
*/
|
||||
#define IPROHC_RECONSTRUCT_IP_EXT(iprohc_header, pkt) \
|
||||
{ \
|
||||
Iprohc_ref_list *ext_hdr, *n_ext_hdr; \
|
||||
\
|
||||
for (ext_hdr = IPCOM_LIST_LAST(&iprohc_header->ref_head); \
|
||||
ext_hdr; \
|
||||
ext_hdr = n_ext_hdr) \
|
||||
{ \
|
||||
n_ext_hdr = IPCOM_LIST_PREV(&ext_hdr->ref_list); \
|
||||
/* move pointer back for the extension header */ \
|
||||
pkt->ipstart -= ext_hdr->length; \
|
||||
pkt->start = pkt->ipstart; \
|
||||
/* copy the extension header to the packet */ \
|
||||
ipcom_memcpy(&(pkt->data[pkt->ipstart]), ext_hdr->data, \
|
||||
ext_hdr->length); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_RECONSTRUCT_IPV4
|
||||
*===========================================================================
|
||||
* Re-construct an IP header from the decompressor context:
|
||||
* - Calculate datagram length from ipstart/start and end pointers.
|
||||
* - Calculate header checksum.
|
||||
* - Move the ipstart and start pointers
|
||||
* - Copy the IP header to the packet
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_RECONSTRUCT_IPV4(iprohc_header, pkt) \
|
||||
{ \
|
||||
if (iprohc_header->has_exten) \
|
||||
{ \
|
||||
/* Re-construct IP extenstion headers */ \
|
||||
IPROHC_RECONSTRUCT_IP_EXT(iprohc_header, pkt); \
|
||||
} \
|
||||
\
|
||||
/* IHL = 5, 20 octets */ \
|
||||
pkt->ipstart -= IPROHC_IP4_HDR_SIZE; \
|
||||
pkt->start = pkt->ipstart; \
|
||||
iprohc_header->header.ip4.length = ip_htons(pkt->end - pkt->start); \
|
||||
\
|
||||
/* Reset checksum to 0 to calculate header checksum */ \
|
||||
iprohc_header->header.ip4.checksum = 0; \
|
||||
iprohc_header->header.ip4.checksum = \
|
||||
ipcom_in_checksum(&iprohc_header->header.ip4, \
|
||||
(Ip_size_t)((iprohc_header->header.ip4.vers_len & 0x0F)*4)); \
|
||||
ipcom_memcpy(&(pkt->data[pkt->ipstart]), &(iprohc_header->header.ip4), \
|
||||
IPROHC_IP4_HDR_SIZE); \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_RECONSTRUCT_IPV4(iprohc_header, pkt) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_RECONSTRUCT_IPV6
|
||||
*===========================================================================
|
||||
* Re-construct an IPv6 header from the decompressor context:
|
||||
* - Calculate payload length from ipstart/start and end pointers.
|
||||
* - Move the ipstart and start pointers
|
||||
* - Copy the IPv6 header to the packet
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET6
|
||||
#define IPROHC_RECONSTRUCT_IPV6(iprohc_header, pkt) \
|
||||
{ \
|
||||
if (iprohc_header->has_exten) \
|
||||
{ \
|
||||
/* Re-construct IP extenstion headers */ \
|
||||
IPROHC_RECONSTRUCT_IP_EXT(iprohc_header, pkt); \
|
||||
} \
|
||||
\
|
||||
iprohc_header->header.ip6.plen = ip_htons(pkt->end - pkt->start); \
|
||||
/* IPv6 header length = 40 octets */ \
|
||||
pkt->ipstart -= IPROHC_IP6_HDR_SIZE; \
|
||||
pkt->start = pkt->ipstart; \
|
||||
ipcom_memcpy(&pkt->data[pkt->ipstart], &(iprohc_header->header.ip6), \
|
||||
IPROHC_IP6_HDR_SIZE); \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_RECONSTRUCT_IPV6(iprohc_header, pkt) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_RECONSTRUCT_IP
|
||||
*===========================================================================
|
||||
* Re-construct IP headers from the context
|
||||
*/
|
||||
#define IPROHC_RECONSTRUCT_IP(ip_context, pkt) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header, *p_ip_header; \
|
||||
\
|
||||
for (ip_header = IPCOM_LIST_LAST(&ip_context->ip_head); \
|
||||
ip_header; \
|
||||
ip_header = p_ip_header) \
|
||||
{ \
|
||||
p_ip_header = IPCOM_LIST_PREV(&ip_header->ip_list); \
|
||||
\
|
||||
if (ip_header->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
/* Re-construct an IPv4 header */ \
|
||||
IPROHC_RECONSTRUCT_IPV4(ip_header, pkt); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Re-construct an IPv6 header */ \
|
||||
IPROHC_RECONSTRUCT_IPV6(ip_header, pkt); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_D_F_STATE_TRANS
|
||||
*===========================================================================
|
||||
* Process state transition at decompressor when a decompression fails
|
||||
*/
|
||||
#define IPROHC_D_F_STATE_TRANS(d_context, sn) \
|
||||
{ \
|
||||
Ip_u8 ratio; \
|
||||
Iprohc_feedback *feedback_v = IP_NULL; \
|
||||
\
|
||||
/* Calculate the failure ratio */ \
|
||||
ratio = (Ip_u8)((d_context->num_decompressed * 100) % d_context->num_failed); \
|
||||
\
|
||||
/* State transits to Static/No Context: RFC 3095, 5.3.2.1 */ \
|
||||
if (d_context->state == ROHC_DECOMP_STATE_FULL) \
|
||||
{ \
|
||||
if (ratio >= IPROHC_D_FULL_RATIO) \
|
||||
{ \
|
||||
d_context->state = ROHC_DECOMP_STATE_STATIC; \
|
||||
\
|
||||
/* Send NACK */ \
|
||||
feedback_v = iprohc_create_feedback_2(d_context, \
|
||||
ROHC_FEEDBACK_NACK, sn); \
|
||||
} \
|
||||
} \
|
||||
else if (d_context->state == ROHC_DECOMP_STATE_STATIC) \
|
||||
{ \
|
||||
if (ratio >= IPROHC_D_STATIC_RATIO) \
|
||||
{ \
|
||||
d_context->state = ROHC_DECOMP_STATE_NO; \
|
||||
\
|
||||
/* Send NACK */ \
|
||||
feedback_v = iprohc_create_feedback_2(d_context, \
|
||||
ROHC_FEEDBACK_NACK, sn); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
if ((feedback_v != IP_NULL) && \
|
||||
(context->trans == ROHC_DECOMP_TRANS_INITIATED)) \
|
||||
{ \
|
||||
/* Feedback pkts that initiate the mode transition must */ \
|
||||
/* carry CRC option */ \
|
||||
iprohc_feedback_add_option(feedback_v, ROHC_FEEDBACK_OPT_CRC, 1, 0); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_D_MODE_TRANS
|
||||
*===========================================================================
|
||||
* Process mode transition at decompressor
|
||||
*/
|
||||
#define IPROHC_D_MODE_TRANS(d_context, mode) \
|
||||
{ \
|
||||
if (mode == ROHC_MODE_C) \
|
||||
{ \
|
||||
/* mode transition request is declined at compressor, */ \
|
||||
/* -- reset trans mode back to mode, and set trans as Pending */ \
|
||||
d_context->trans_mode = d_context->mode; \
|
||||
d_context->trans = ROHC_DECOMP_TRANS_PENDING; \
|
||||
} \
|
||||
else if ((d_context->mode == ROHC_MODE_U) && \
|
||||
(d_context->trans == ROHC_DECOMP_TRANS_DONE)) \
|
||||
{ \
|
||||
/* Initiate the mode transition: U-mode-->O-mode */ \
|
||||
d_context->trans_mode = ROHC_MODE_O; \
|
||||
d_context->trans = ROHC_DECOMP_TRANS_INITIATED; \
|
||||
} \
|
||||
else if (mode == (int)d_context->trans_mode) \
|
||||
{ \
|
||||
/* mode transition request is accepted at compressor, */ \
|
||||
/* -- set trans and mode */ \
|
||||
if (d_context->trans == ROHC_DECOMP_TRANS_INITIATED) \
|
||||
{ \
|
||||
d_context->mode = d_context->trans_mode; \
|
||||
d_context->trans = ROHC_DECOMP_TRANS_PENDING; \
|
||||
} \
|
||||
else if (d_context->trans == ROHC_DECOMP_TRANS_PENDING) \
|
||||
d_context->trans = ROHC_DECOMP_TRANS_DONE; \
|
||||
} \
|
||||
else if ((mode == -1) && (d_context->trans == ROHC_DECOMP_TRANS_PENDING))\
|
||||
{ \
|
||||
d_context->trans = ROHC_DECOMP_TRANS_DONE; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Deompressor states
|
||||
*===========================================================================
|
||||
* refer to RFC 3095, section 4.3.2
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ROHC_DECOMP_STATE_NO = 1,
|
||||
ROHC_DECOMP_STATE_STATIC,
|
||||
ROHC_DECOMP_STATE_FULL
|
||||
} Iprohc_decomp_state;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* De-compressor mode transitions
|
||||
*===========================================================================
|
||||
* refer to RFC 3095, section 5.6.1
|
||||
*/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ROHC_DECOMP_TRANS_DONE = 0,
|
||||
ROHC_DECOMP_TRANS_INITIATED,
|
||||
ROHC_DECOMP_TRANS_PENDING
|
||||
} Iprohc_decomp_trans;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* Public TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
struct Iprohc_decompressor;
|
||||
struct Iprohc_interface;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_d_context
|
||||
*===========================================================================
|
||||
* This is the ROHC decompression context structure
|
||||
*/
|
||||
|
||||
typedef struct Iprohc_d_context_struct
|
||||
{
|
||||
Ipcom_list context_list;
|
||||
|
||||
/* CID allocated for the context */
|
||||
Ip_u16 cid;
|
||||
|
||||
/* decompression state */
|
||||
Iprohc_decomp_state state;
|
||||
|
||||
/* decompression mode */
|
||||
Iprohc_mode mode;
|
||||
|
||||
/* decompression mode transition */
|
||||
Iprohc_decomp_trans trans;
|
||||
|
||||
/* decompression mode to be transited to */
|
||||
Iprohc_mode trans_mode;
|
||||
|
||||
/* first IR received for context, parsed during creating the context */
|
||||
Ip_bool first_ir;
|
||||
|
||||
/* number of successfully decompressed packets */
|
||||
Ip_u32 num_decompressed;
|
||||
|
||||
/* number of failed decompressed packets */
|
||||
Ip_u32 num_failed;
|
||||
|
||||
/* stream type: IPv4 or IPv6, for feedback processing */
|
||||
Ip_u8 stream_type;
|
||||
|
||||
/* source address of the stream, for feedback processing */
|
||||
Iprohc_addr src;
|
||||
|
||||
/* destination address of the stream, for feedback processing */
|
||||
Iprohc_addr dst;
|
||||
|
||||
/* profile the context is associated with */
|
||||
Ip_u8 profileid;
|
||||
|
||||
/* Compressor the context is associated with */
|
||||
struct Iprohc_decompressor *decompressor;
|
||||
|
||||
/* CRC used to validate the packet */
|
||||
Ip_u8 crc;
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
Ipcom_mutex code_mutex; /* Mutex to protect compressor 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 */
|
||||
|
||||
/* profile specific decompression context structure */
|
||||
void *profile_context;
|
||||
}
|
||||
Iprohc_d_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_decompressor
|
||||
*===========================================================================
|
||||
* This is the ROHC decompressor context structure
|
||||
*/
|
||||
|
||||
typedef struct Iprohc_decompressor_struct
|
||||
{
|
||||
|
||||
/* Context list */
|
||||
Ip_u16 context_num; /* number of contexts */
|
||||
Ipcom_list context_head;
|
||||
|
||||
/* interface the decompressor is associated with */
|
||||
struct Iprohc_interface *interface;
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
Ipcom_mutex code_mutex; /* Mutex to protect compressor 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_decompressor;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC Iprohc_decompressor * iprohc_alloc_decompressor(struct Iprohc_interface *interface);
|
||||
IP_PUBLIC Ip_err iprohc_del_decompressor(Iprohc_decompressor *decompressor);
|
||||
IP_PUBLIC Ip_err iprohc_d_del_profile_contexts(Iprohc_decompressor *decompressor, Ip_u8 profileid);
|
||||
|
||||
IP_PUBLIC Iprohc_d_context * iprohc_d_context_common_create(Ip_u16 cid);
|
||||
IP_PUBLIC Ip_err iprohc_d_context_common_del(Iprohc_d_context *d_context);
|
||||
IP_PUBLIC Ip_err iprohc_d_print_context(Iprohc_decompressor *decompressor, Ip_u8 profile);
|
||||
|
||||
/* Debug functions */
|
||||
IP_PUBLIC void iprohc_d_print_a_context(Iprohc_d_context *context);
|
||||
IP_PUBLIC char * iprohc_decomp_state(Iprohc_decomp_state state);
|
||||
IP_PUBLIC char * iprohc_decomp_trans(Iprohc_decomp_trans trans);
|
||||
|
||||
|
||||
#ifndef IP_PORT_VXWORKS /* for Linux recursive semaphore */
|
||||
|
||||
IP_PUBLIC void iprohc_decomp_lck(Iprohc_decompressor *decomp);
|
||||
IP_PUBLIC void iprohc_decomp_unlck(Iprohc_decompressor *decomp);
|
||||
|
||||
IP_PUBLIC void iprohc_d_context_lck(Iprohc_d_context *context);
|
||||
IP_PUBLIC void iprohc_d_context_unlck(Iprohc_d_context *context);
|
||||
|
||||
#endif /* !IP_PORT_VXWORKS */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* #ifndef IPROHC_DECOMP_H */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,470 @@
|
||||
/* iprohc_esp_ip.h - ROHC ESP IP profile head file */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 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
|
||||
--------------------
|
||||
01b,10mar10,ggz Include WLSB
|
||||
01a,10feb09,ggz Created
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_ESP_IP_H
|
||||
#define IPROHC_ESP_IP_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_tags.h>
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_list.h>
|
||||
|
||||
|
||||
#include "iprohc_config.h"
|
||||
#include "iprohc_ip.h"
|
||||
#include "iprohc_constant.h"
|
||||
#include "iprohc_coding_util.h"
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPROHC_ENABLE_REENTRANT
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_ESP_DYNAMIC
|
||||
*===========================================================================
|
||||
* Fomat ESP dynamic chain in a IR/IR-DYN packet
|
||||
*
|
||||
* ESP header dynamic part(5.7.7.7)
|
||||
* +---+---+---+---+---+---+---+---+
|
||||
* / Sequence Number / 4 octets
|
||||
* +---+---+---+---+---+---+---+---+
|
||||
*/
|
||||
#define IPROHC_FMT_ESP_DYNAMC(esp_context, pointer, has_dynamic, pkt) \
|
||||
{ \
|
||||
/* Add ESP SN dynamic part to the end of dynamic chain */ \
|
||||
pointer -= 4; \
|
||||
ipcom_memcpy(&pkt->data[pointer], &esp_context->sn, 4); \
|
||||
has_dynamic = IP_TRUE; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_ESP_STATIC
|
||||
*===========================================================================
|
||||
* Fomat dynamic chain in a IR/IR-DYN packet
|
||||
*
|
||||
* ESP header static part(5.7.7.7)
|
||||
* +---+---+---+---+---+---+---+---+
|
||||
* / SPI / 4 octets
|
||||
* +---+---+---+---+---+---+---+---+
|
||||
*/
|
||||
#define IPROHC_FMT_ESP_STATIC(esp_context, pointer, pkt) \
|
||||
{ \
|
||||
/* Add ESP SPI static part to the end of static chain */ \
|
||||
pointer -= 4; \
|
||||
ipcom_memcpy(&pkt->data[pointer], &esp_context->spi, 4); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_ESP_UPDATE_CONTEXT
|
||||
*===========================================================================
|
||||
* Update the ESP context
|
||||
*/
|
||||
#define IPROHC_ESP_UPDATE_CONTEXT(esp_context, esp_header) \
|
||||
{ \
|
||||
esp_context->spi = esp_header.spi; \
|
||||
esp_context->sn_prev = esp_context->sn; \
|
||||
esp_context->sn = esp_header.sn; \
|
||||
esp_context->payload = esp_header.payload; \
|
||||
/* Handle SN wraparround */ \
|
||||
if (esp_context->sn < esp_context->sn_prev) \
|
||||
{ \
|
||||
/* Update the state of the context to IR */ \
|
||||
c_context->state = ROHC_COMP_STATE_IR; \
|
||||
c_context->num_ir = 0; \
|
||||
c_context->pkt_type = ROHC_PKT_IR; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_ESP_IP_STATIC
|
||||
*===========================================================================
|
||||
* GET ESP static chain in IR packet
|
||||
*/
|
||||
#define IPROHC_GET_ESP_STATIC(esp_context, pointer, pkt) \
|
||||
{ \
|
||||
/* ESP SPI static part is 4 byte long */ \
|
||||
ipcom_memcpy(&esp_context->spi, &pkt->data[pointer], 4); \
|
||||
pointer += 4; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_ESP_DYNAMIC
|
||||
*===========================================================================
|
||||
* Get ESP dynamic chain in IR/IP-DYN packet
|
||||
*/
|
||||
#define IPROHC_GET_ESP_DYNAMIC(esp_context, pointer, pkt) \
|
||||
{ \
|
||||
/* ESP SN dynamic part is 4 byte long */ \
|
||||
ipcom_memcpy(&esp_context->sn, &pkt->data[pointer], 4); \
|
||||
pointer += 4; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_ESP_STATIC
|
||||
*===========================================================================
|
||||
* Update ESP static header
|
||||
*/
|
||||
#define IPROHC_UPD_ESP_STATIC(esp_context, pointer, pkt) \
|
||||
{ \
|
||||
IPROHC_GET_ESP_STATIC(esp_context, pointer, pkt) \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_ESP_DYNAMIC
|
||||
*===========================================================================
|
||||
* Update ESP dynamic header
|
||||
*/
|
||||
#define IPROHC_UPD_ESP_DYNAMIC(esp_context, pointer, pkt) \
|
||||
{ \
|
||||
IPROHC_GET_ESP_DYNAMIC(esp_context, pointer, pkt) \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_RECONSTRUCT_ESP
|
||||
*===========================================================================
|
||||
* Reconstruct ESP header
|
||||
*/
|
||||
#define IPROHC_RECONSTRUCT_ESP(esp_context, pkt) \
|
||||
{ \
|
||||
pkt->ipstart -= 4; \
|
||||
ipcom_memcpy(&pkt->data[pkt->ipstart], &esp_context->sn, 4); \
|
||||
pkt->ipstart -= 4; \
|
||||
ipcom_memcpy(&pkt->data[pkt->ipstart], &esp_context->spi, 4); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_IPID_OFFSET
|
||||
*===========================================================================
|
||||
* Loop through IP headers and update ip_id offset: ip_id - sn for each
|
||||
* IPv4 header.
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_UPD_ESP_IPID_OFFSET(ip_context) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header_; \
|
||||
\
|
||||
/* Calcualte IP-ID offset for each IPv4 header : IP-ID - SN */ \
|
||||
for (ip_header_ = IPCOM_LIST_FIRST(&ip_context->ip_head); \
|
||||
ip_header_; \
|
||||
ip_header_ = IPCOM_LIST_NEXT(&ip_header_->ip_list)) \
|
||||
{ \
|
||||
if (ip_header_->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
/* An IPv4 packet */ \
|
||||
ip_header_->offset = ip_header_->header.ip4.id - ip_context->sn; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_UPD_ESP_IPID_OFFSET(ip_context) IP_NOOP
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_IPID_NTOHS
|
||||
*===========================================================================
|
||||
* Loop through IP headers and convert ip_id from network to host order.
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_ESP_IPID_NTOHS(ip_context) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header; \
|
||||
\
|
||||
for (ip_header = IPCOM_LIST_FIRST(&ip_context->ip_head); \
|
||||
ip_header; \
|
||||
ip_header = IPCOM_LIST_NEXT(&ip_header->ip_list)) \
|
||||
{ \
|
||||
if (ip_header->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
ip_header->header.ip4.id = ip_ntohs(ip_header->header.ip4.id); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_ESP_IPID_NTOHS(ip_context) IP_NOOP
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_ESP_IP_USE_RND_IPID
|
||||
*===========================================================================
|
||||
* Use IP ID as a random value.
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_ESP_IP_USE_RND_IPID(ip_context) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header; \
|
||||
\
|
||||
for (ip_header = IPCOM_LIST_FIRST(&ip_context->ip_head); \
|
||||
ip_header; \
|
||||
ip_header = IPCOM_LIST_NEXT(&ip_header->ip_list)) \
|
||||
{ \
|
||||
if (ip_header->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
ip_header->rnd = 1; \
|
||||
ip_header->header_flags |= 0x02; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_ESP_IP_USE_RND_IPID(ip_context) IP_NOOP
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_IPID_HTONS
|
||||
*===========================================================================
|
||||
* Loop through IP headers and convert ip_id from host to network order.
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_ESP_IPID_HTONS(ip_context) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header; \
|
||||
\
|
||||
for (ip_header = IPCOM_LIST_FIRST(&ip_context->ip_head); \
|
||||
ip_header; \
|
||||
ip_header = IPCOM_LIST_NEXT(&ip_header->ip_list)) \
|
||||
{ \
|
||||
if (ip_header->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
ip_header->header.ip4.id = ip_htons(ip_header->header.ip4.id); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_ESP_IPID_HTONS(ip_context) IP_NOOP
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* Public TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* ESP header struct for non null esp algorithm */
|
||||
typedef struct esp_header
|
||||
{
|
||||
Ip_u32 spi;
|
||||
Ip_u32 sn;
|
||||
int payload;
|
||||
}
|
||||
esp_header;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_c_esp_ip_context_struct
|
||||
*===========================================================================
|
||||
* ROHC compression ESP profile specific context structure
|
||||
*/
|
||||
typedef struct Iprohc_c_esp_context_struct
|
||||
{
|
||||
/* Security parameters index in network order */
|
||||
Ip_u32 spi;
|
||||
|
||||
/* ESP seqence number in network order. Increments by 1 */
|
||||
Ip_u32 sn;
|
||||
|
||||
/* Previous ESP seqence number */
|
||||
Ip_u32 sn_prev;
|
||||
|
||||
/* Pointer to ESP encrypted payload in the packet */
|
||||
int payload;
|
||||
|
||||
/*#ifdef IPROHC_WLSB_LSB*/
|
||||
/* WLSB for ESP SN (sn is saved in a host order) */
|
||||
iprohc_create_cmp_wlsb_struct(sn_wlsb, 32);
|
||||
/*#endif*/ /* IPROHC_WLSB_LSB */
|
||||
|
||||
}
|
||||
Iprohc_c_esp_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_c_esp_ip_context_struct
|
||||
*===========================================================================
|
||||
* ROHC compression ESP_IP profile specific context structure
|
||||
*/
|
||||
typedef struct Iprohc_c_esp_ip_context_struct
|
||||
{
|
||||
/* IP specific context */
|
||||
Iprohc_c_ip_context *ip_context;
|
||||
|
||||
/* ESP sepecific context */
|
||||
Iprohc_c_esp_context *esp_context;
|
||||
}
|
||||
Iprohc_c_esp_ip_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_d_esp_ip_context_struct
|
||||
*===========================================================================
|
||||
* ROHC decompression ESP profile specific context structure
|
||||
*/
|
||||
typedef struct Iprohc_d_esp_context_struct
|
||||
{
|
||||
/* Security parameters index */
|
||||
Ip_u32 spi;
|
||||
|
||||
/* ESP Seqence number in network order. Increments by 1 */
|
||||
Ip_u32 sn;
|
||||
|
||||
/* Pointer to ESP encripted payload in the ip packet */
|
||||
int payload;
|
||||
|
||||
/*#ifdef IPROHC_WLSB_LSB*/
|
||||
/* LSB for decoding ESP SN (sn is saved in a host order) */
|
||||
iprohc_create_dmp_lsb_struct(sn_lsb);
|
||||
/*#endif*/ /* IPROHC_WLSB_LSB */
|
||||
}
|
||||
Iprohc_d_esp_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_d_esp_ip_context_struct
|
||||
*===========================================================================
|
||||
* The ROHC decompression ESP_IP profile specific context structure
|
||||
*/
|
||||
typedef struct Iprohc_d_esp_ip_context_struct
|
||||
{
|
||||
Iprohc_d_ip_context *ip_context;
|
||||
Iprohc_d_esp_context *esp_context;
|
||||
|
||||
}
|
||||
Iprohc_d_esp_ip_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Profile registration/de-registration functions */
|
||||
IP_PUBLIC Ip_err iprohc_profile_esp_ip_register(void);
|
||||
IP_PUBLIC Ip_err iprohc_esp_ip_deregister(void);
|
||||
|
||||
/* Profile specific compression functions */
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_esp_ip_c_find_context(Iprohc_compressor *comp, Ipcom_pkt *pkt,
|
||||
Iprohc_c_context **c_context);
|
||||
IP_PUBLIC Iprohc_c_context *
|
||||
iprohc_esp_ip_c_create_context(Iprohc_compressor *comp,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_err iprohc_esp_ip_c_del_context(Iprohc_c_context *context);
|
||||
IP_PUBLIC Ip_err iprohc_esp_ip_c_process_feedback(Iprohc_c_context *context,
|
||||
Ip_u8 *feedback, Ip_u8 size);
|
||||
IP_PUBLIC Ip_err iprohc_esp_ip_c_compress(Iprohc_c_context *context,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC void iprohc_esp_ip_c_print_context(Iprohc_c_context *context);
|
||||
|
||||
|
||||
/* Profile specific decompression functions */
|
||||
IP_PUBLIC Iprohc_d_context *
|
||||
iprohc_esp_ip_d_find_context(Iprohc_decompressor *decomp, Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Iprohc_d_context *
|
||||
iprohc_esp_ip_d_create_context(Iprohc_decompressor *decomp,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_err iprohc_esp_ip_d_del_context(Iprohc_d_context *context);
|
||||
IP_PUBLIC void iprohc_esp_ip_d_print_context(Iprohc_d_context *context);
|
||||
IP_PUBLIC Ip_err iprohc_esp_ip_d_decompress(Iprohc_d_context *context,
|
||||
Ipcom_pkt *pkt);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* #ifndef IPROHC_ESP_IP_H */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,436 @@
|
||||
/* iprohc_format.h - ROHC formatting 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,20mar12,ggz Fix WIND00340441
|
||||
01h,25aug11,ggz Fix WIND00290718
|
||||
01g,09apr10,ggz Fix 64bit compiler warnings
|
||||
01f,20apr09,tlu Fix Linux build warnings for mips64 gcc (cav_ebt5800)
|
||||
01e,26sep08,tlu Initialize buff[4] in IPv4 dynamic format macro to 0
|
||||
01d,03jul08,tlu Add to handle IP extension headers
|
||||
01c,21may08,tlu Use encoded SN to format base header
|
||||
01b,20may08,tlu Add large CID encoding macro
|
||||
01a,25mar08,tlu Created.
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_FORMAT_H
|
||||
#define IPROHC_FORMAT_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_inet.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
|
||||
|
||||
#include "iprohc_constant.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_LIST_ET0
|
||||
*===========================================================================
|
||||
* Add the compressed list encoding type 0
|
||||
*
|
||||
* 5.8.6.1 Encoding Type 0 (generic scheme)
|
||||
*
|
||||
* ---------------------------------
|
||||
* | ET=0 |GP|PS| CC = m |
|
||||
* ---------------------------------
|
||||
* : gen_id : 1 octet, if GP = 1
|
||||
* ---------------------------------
|
||||
* | XI 1, ..., XI m | m octets, or m * 4 bits
|
||||
* / -----------------/
|
||||
* | : Padding : if PS = 0 and m is odd
|
||||
* ---------------------------------
|
||||
* / item1, ..., item n / variable
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#define IPROHC_FMT_LIST_ET0(iprohc_header, edata) \
|
||||
{ \
|
||||
int i; \
|
||||
Iprohc_ref_list *ext_hdr, *n_ext_hdr; \
|
||||
Ip_u8 *ebuff = (Ip_u8 *)edata; \
|
||||
\
|
||||
ebuff[0] = iprohc_header->ref_num; \
|
||||
ebuff[1] = iprohc_header->gen_id; \
|
||||
\
|
||||
if (iprohc_header->ref_num < 8) \
|
||||
{ \
|
||||
ebuff[0] |= 0x20; \
|
||||
for (i = 1; i <= iprohc_header->ref_num/2; i++) \
|
||||
{ \
|
||||
ebuff[i+1] = (Ip_u8)(0x88 | (i<<4)); \
|
||||
ebuff[i+1] |= (Ip_u8)(i+1); \
|
||||
} \
|
||||
if (iprohc_header->ref_num % 2) \
|
||||
{ \
|
||||
ebuff[i+1] = (Ip_u8)(0x80 | (i<<4)); \
|
||||
i++; /* point to next byte to be formatted */ \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ebuff[0] |= 0x30; \
|
||||
for (i=1; i <= iprohc_header->ref_num; i++) \
|
||||
ebuff[i+1] = (Ip_u8)(0x80 | i); \
|
||||
} \
|
||||
\
|
||||
for (ext_hdr = IPCOM_LIST_FIRST(&iprohc_header->ref_head); \
|
||||
ext_hdr; \
|
||||
ext_hdr = n_ext_hdr) \
|
||||
{ \
|
||||
n_ext_hdr = IPCOM_LIST_NEXT(&ext_hdr->ref_list); \
|
||||
ipcom_memcpy(&ebuff[i+1], ext_hdr->data, ext_hdr->length); \
|
||||
i += ext_hdr->length; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_IPV4_STATIC
|
||||
*===========================================================================
|
||||
* Add an IPv4 static part to Static chain in a IR packet
|
||||
*
|
||||
* 5.7.7.4 IPv4 header static part format
|
||||
*
|
||||
* ---------------------------------
|
||||
* | version = 4 | 0 |
|
||||
* ---------------------------------
|
||||
* | Protocol |
|
||||
* ---------------------------------
|
||||
* / Source Address / 4 octets
|
||||
* ---------------------------------
|
||||
* / Destination Address / 4 octets
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_FMT_IPV4_STATIC(iprohc_header, data) \
|
||||
{ \
|
||||
Ipcom_ip_header *ip4_header = &(iprohc_header->header.ip4); \
|
||||
Ip_u8 *buff = (Ip_u8 *)data; \
|
||||
\
|
||||
buff[0] = 0x40; \
|
||||
buff[1] = ip4_header->protocol; \
|
||||
ipcom_memcpy(&buff[2], &ip4_header->src, 4); \
|
||||
ipcom_memcpy(&buff[6], &ip4_header->dst, 4); \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_FMT_IPV4_STATIC(iprohc_header, data) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_IPV6_STATIC
|
||||
*===========================================================================
|
||||
* Add an IPv6 static part to Static chain in a IR packet
|
||||
*
|
||||
* 5.7.7.3 IPv6 header static part format
|
||||
*
|
||||
* ---------------------------------
|
||||
* | version = 6 |Flow Label (msb) | 1 octet
|
||||
* ---------------------------------
|
||||
* | Flow Label (lsb) | 2 octets
|
||||
* ---------------------------------
|
||||
* | Next Header | 1 octet
|
||||
* ---------------------------------
|
||||
* / Source Address / 16 octets
|
||||
* ---------------------------------
|
||||
* / Destination Address / 16 octets
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET6
|
||||
#define IPROHC_FMT_IPV6_STATIC(iprohc_header, data) \
|
||||
{ \
|
||||
Ipcom_ip6_header *ip6_header = &(iprohc_header->header.ip6); \
|
||||
Ip_u32 flow; \
|
||||
Ip_u16 flow_lsb; \
|
||||
Ip_u8 *buff = (Ip_u8 *)data; \
|
||||
\
|
||||
buff[0] = 0x60; \
|
||||
flow = IP_GET_NTOHL(&ip6_header->ver_class_flow) & 0xfffff; \
|
||||
flow_lsb = (Ip_u16)(flow & 0xffff); \
|
||||
buff[0] = (Ip_u8)(buff[0] | ((flow >> 16) & 0x0f)); \
|
||||
flow_lsb = ip_htons(flow_lsb); \
|
||||
ipcom_memcpy(&buff[1], &flow_lsb, 2); \
|
||||
buff[3] = ip6_header->nxt; \
|
||||
ipcom_memcpy(&buff[4], &ip6_header->src, 16); \
|
||||
ipcom_memcpy(&buff[20], &ip6_header->dst, 16); \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_FMT_IPV6_STATIC(iprohc_header, data) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_IPV4_DYNAMIC
|
||||
*===========================================================================
|
||||
* Add an IPv4 dynamic part to Dynamic chain in a IR/IR-DYN packet
|
||||
*
|
||||
* 5.7.7.4 IPv4 header dynamic part format
|
||||
*
|
||||
* ---------------------------------
|
||||
* | Type of Service |
|
||||
* ---------------------------------
|
||||
* | Time to Live |
|
||||
* ---------------------------------
|
||||
* / Identification / 2 octets
|
||||
* ---------------------------------
|
||||
* | DF|RND|NBO|SID| 0 |
|
||||
* ---------------------------------
|
||||
* / Generic extension Header list / (not supported)
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_FMT_IPV4_DYNAMIC(iprohc_header, data) \
|
||||
{ \
|
||||
Ipcom_ip_header *ip4_header = &(iprohc_header->header.ip4); \
|
||||
Ip_u8 *buff = (Ip_u8 *)data; \
|
||||
\
|
||||
buff[0] = ip4_header->tos; \
|
||||
buff[1] = ip4_header->ttl; \
|
||||
ipcom_memcpy(&buff[2], &(ip4_header->id), 2); \
|
||||
buff[4] = 0x00; \
|
||||
if (ip4_header->frag & IPCOM_IPFRAG_DF) buff[4] = 0x80; \
|
||||
if (iprohc_header->rnd) buff[4] |= 0x40; \
|
||||
if (iprohc_header->nbo) buff[4] |= 0x20; \
|
||||
if (iprohc_header->sid) buff[4] |= 0x10; \
|
||||
if (iprohc_header->has_exten) \
|
||||
IPROHC_FMT_LIST_ET0(iprohc_header, &buff[5]); \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_FMT_IPV4_DYNAMIC(iprohc_header, data) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_IPV6_DYNAMIC
|
||||
*===========================================================================
|
||||
* Add an IPv6 dynamic part to Dynamic chain in a IR/IR-DYN packet
|
||||
*
|
||||
* 5.7.7.3 IPv6 header dynamic part format
|
||||
*
|
||||
* ---------------------------------
|
||||
* | Traffic Class | 1 octet
|
||||
* ---------------------------------
|
||||
* | Hop Limit | 1 octet
|
||||
* ---------------------------------
|
||||
* / Generic extension Header list / (not supported)
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET6
|
||||
#define IPROHC_FMT_IPV6_DYNAMIC(iprohc_header, data) \
|
||||
{ \
|
||||
Ipcom_ip6_header *ip6_header; \
|
||||
Ip_u8 *buff = (Ip_u8 *)data; \
|
||||
\
|
||||
ip6_header = (Ipcom_ip6_header *)&(iprohc_header->header.ip6); \
|
||||
buff[0] = (Ip_u8)((IP_GET_NTOHL(&ip6_header->ver_class_flow)>>20)&0xff); \
|
||||
buff[1] = ip6_header->hlim; \
|
||||
if (iprohc_header->has_exten) \
|
||||
IPROHC_FMT_LIST_ET0(iprohc_header, &buff[2]); \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_FMT_IPV6_DYNAMIC(iprohc_header, data) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_IP_STATIC
|
||||
*===========================================================================
|
||||
* Fomat Static chain in a IR packet
|
||||
*/
|
||||
#define IPROHC_FMT_IP_STATIC(ip_context, pointer, pkt) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header, *p_ip_header; \
|
||||
\
|
||||
for (ip_header = IPCOM_LIST_LAST(&ip_context->ip_head); ip_header; \
|
||||
ip_header = p_ip_header) \
|
||||
{ \
|
||||
p_ip_header = IPCOM_LIST_PREV(&ip_header->ip_list); \
|
||||
\
|
||||
if (ip_header->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
/* Move pointer back for one IPv4 static part */ \
|
||||
pointer -= 10; \
|
||||
\
|
||||
/* Add an IPv4 static part to Static chain */ \
|
||||
IPROHC_FMT_IPV4_STATIC(ip_header, &pkt->data[pointer]); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Move pointer back for one IPv6 static part */ \
|
||||
pointer -= 36; \
|
||||
\
|
||||
/* Add an IPv6 static part to static chain */ \
|
||||
IPROHC_FMT_IPV6_STATIC(ip_header, &pkt->data[pointer]); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_IP_DYNAMIC
|
||||
*===========================================================================
|
||||
* Fomat Dynamic chain in a IR/IR-DYN packet
|
||||
*/
|
||||
#define IPROHC_FMT_IP_DYNAMC(ip_context, pointer, pkt, has_dynamic, num_h) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header, *p_ip_header; \
|
||||
Ip_u8 et0_len; \
|
||||
\
|
||||
for (ip_header = IPCOM_LIST_LAST(&ip_context->ip_head); \
|
||||
(ip_header && num_h); \
|
||||
ip_header = p_ip_header, num_h--) \
|
||||
{ \
|
||||
p_ip_header = IPCOM_LIST_PREV(&ip_header->ip_list); \
|
||||
has_dynamic = IP_TRUE; \
|
||||
et0_len = 0; \
|
||||
\
|
||||
/* Calculate compressed list ET0 header length */ \
|
||||
if (ip_header->ref_num != 0) \
|
||||
{ \
|
||||
if (ip_header->ref_num < 8) \
|
||||
et0_len = (Ip_u8)(2 + (ip_header->ref_num/2) + (ip_header->ref_num%2)); \
|
||||
else \
|
||||
et0_len = (Ip_u8)(2 + ip_header->ref_num); \
|
||||
} \
|
||||
\
|
||||
if (ip_header->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
/* Move pointer back for one IPv4 dynamic part */ \
|
||||
/* and IP extension length */ \
|
||||
pointer -= (5 + ip_header->ref_len + et0_len); \
|
||||
\
|
||||
/* Add an IPv4 dynamic part to Dynamic chain */ \
|
||||
IPROHC_FMT_IPV4_DYNAMIC(ip_header, &pkt->data[pointer]); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Move pointer back for one IPv6 dynamic part */ \
|
||||
pointer -= (2 + ip_header->ref_len + et0_len); \
|
||||
\
|
||||
/* Add an IPv6 dynamic part to Dynamic chain */ \
|
||||
IPROHC_FMT_IPV6_DYNAMIC(ip_header, &pkt->data[pointer]); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_ENCODE_LARGE_CID
|
||||
*===========================================================================
|
||||
* Encode large CID according to RFC 3095, section 4.5.6.
|
||||
* RFC 3095, section 5.2.2: If the first bit is 0, the CID uses
|
||||
* one octet. If the first bit is 1, the CID uses two octets.
|
||||
*/
|
||||
#define IPROHC_ENCODE_LARGE_CID(data, pointer, cid, cid_size) \
|
||||
{ \
|
||||
if (cid < 128) \
|
||||
{ \
|
||||
/* 0 < cid < 128 (0x80) */ \
|
||||
data[pointer] = (Ip_u8)cid; \
|
||||
cid_size = 1; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* 127 (0x7F) < cid < 16384 (0x4000): set the first bit to 1 */ \
|
||||
cid |= 0x8000; \
|
||||
cid = ip_htons(cid); \
|
||||
ipcom_memcpy(&(data[pointer]), &cid, 2); \
|
||||
cid_size = 2; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* Public TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_PUBLIC Ip_err iprohc_fmt_extension(Ipcom_pkt *pkt, int *pointer,
|
||||
Iprohc_extension ext_type,
|
||||
void *ip_header1, void *ip_header2,
|
||||
Ip_u16 sn, Iprohc_mode mode,
|
||||
Ip_u8 flags1, Ip_u8 flags2);
|
||||
|
||||
IP_PUBLIC Ip_u8 iprohc_fmt_base_header(Ip_u8 *base_header,
|
||||
Iprohc_c_context *context, void *header1,
|
||||
Ip_u8 sn, Ip_u8 crc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* #ifndef IPROHC_FORMAT_H */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,449 @@
|
||||
/* iprohc_ip.h - ROHC IP profile 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
|
||||
--------------------
|
||||
01j,25aug11,ggz Fix WIND00289753. IP ext list assert failure
|
||||
01l,10jun10,ggz Declare some functions public for use in ESP_IP and
|
||||
UDP_IP profiles
|
||||
01h,20apr09,tlu Fix Linux build warnings for mips64 gcc (cav_ebt5800)
|
||||
01g,02jul08,tlu Add to handle IP extension headers
|
||||
01f,27may08,tlu Add compile condition to include WLSB/LSB
|
||||
01e,21may08,tlu Add macro to update IP-ID offset from SN
|
||||
01d,20may08,tlu Add SN WLSB encoding/decoding
|
||||
01c,07may08,tlu Add debug functions to print a context
|
||||
01b,29apr08,tlu Change type for payload_offset
|
||||
01a,12mar08,tlu Created.
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_IP_H
|
||||
#define IPROHC_IP_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_tags.h>
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_list.h>
|
||||
|
||||
|
||||
#include "iprohc_config.h"
|
||||
#include "iprohc_constant.h"
|
||||
|
||||
#ifdef IPROHC_WLSB_LSB
|
||||
#include "iprohc_coding_util.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPROHC_ENABLE_REENTRANT
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_PROC_EXT
|
||||
*===========================================================================
|
||||
* Check whether Next Header (IPv6)/Protocol (IPv4) is a to-be-processed
|
||||
* IP extension header.
|
||||
*/
|
||||
|
||||
#define IPROHC_PROC_EXT(nxt) \
|
||||
((nxt == IP_IPPROTO_ROUTING) || \
|
||||
(nxt == IP_IPPROTO_DSTOPTS) || \
|
||||
(nxt == IP_IPPROTO_HOPOPTS) || \
|
||||
(nxt == IP_IPPROTO_MOBILE))
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_IP6_EXT
|
||||
*===========================================================================
|
||||
* Check whether it is a to-be-processed IPv6 extension header.
|
||||
*/
|
||||
|
||||
#define IPROHC_IP6_EXT(type) \
|
||||
((type == IP_IPPROTO_ROUTING) || \
|
||||
(type == IP_IPPROTO_DSTOPTS) || \
|
||||
(type == IP_IPPROTO_HOPOPTS))
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FREE_REF_LIST
|
||||
*===========================================================================
|
||||
* Free the compression list which contains the IP extension headers.
|
||||
*/
|
||||
#define IPROHC_FREE_REF_LIST(ip_head) \
|
||||
{ \
|
||||
Iprohc_ref_list *ext_hdr, *n_ext_hdr; \
|
||||
\
|
||||
ip_head->has_exten = IP_FALSE; \
|
||||
ip_head->ref_num = 0; \
|
||||
ip_head->ref_len = 0; \
|
||||
ip_head->gen_id = 0; \
|
||||
for (ext_hdr = IPCOM_LIST_FIRST(&ip_head->ref_head); \
|
||||
ext_hdr; \
|
||||
ext_hdr = n_ext_hdr) \
|
||||
{ \
|
||||
n_ext_hdr = IPCOM_LIST_NEXT(&ext_hdr->ref_list); \
|
||||
ipcom_list_remove(&ext_hdr->ref_list); \
|
||||
\
|
||||
if (ext_hdr->data) \
|
||||
ipcom_free(ext_hdr->data); \
|
||||
\
|
||||
ipcom_free(ext_hdr); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_COPY_REF_LIST
|
||||
*===========================================================================
|
||||
* Copy the IP extension headers from the list structure from_ip_head to
|
||||
* the list structure to_ip_head.
|
||||
*/
|
||||
#define IPROHC_COPY_REF_LIST(to_ip_head, from_ip_head) \
|
||||
{ \
|
||||
Iprohc_ref_list *ext_hdr, *n_ext_hdr; \
|
||||
\
|
||||
ipcom_list_init(&to_ip_head->ref_head); \
|
||||
to_ip_head->has_exten = from_ip_head->has_exten; \
|
||||
to_ip_head->ref_num = from_ip_head->ref_num; \
|
||||
to_ip_head->ref_len = from_ip_head->ref_len; \
|
||||
to_ip_head->gen_id = from_ip_head->gen_id; \
|
||||
for (ext_hdr = IPCOM_LIST_FIRST(&from_ip_head->ref_head); \
|
||||
ext_hdr; \
|
||||
ext_hdr = n_ext_hdr) \
|
||||
{ \
|
||||
n_ext_hdr = IPCOM_LIST_NEXT(&ext_hdr->ref_list); \
|
||||
\
|
||||
ipcom_list_remove(&ext_hdr->ref_list); \
|
||||
/* Add the ref list structure to to_ref_head */ \
|
||||
ipcom_list_insert_last(&to_ip_head->ref_head, &ext_hdr->ref_list); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_REF_LIST
|
||||
*===========================================================================
|
||||
* Parse the packet to get the reference list for to-be-processed IP
|
||||
* extension headers.
|
||||
*/
|
||||
|
||||
#define IPROHC_GET_REF_LIST(ip_header, ptype, pkt, pointer) \
|
||||
{ \
|
||||
Iprohc_ref_list *ref_list; \
|
||||
Ip_u8 index_v = 1; \
|
||||
\
|
||||
ip_header->has_exten = IP_TRUE; \
|
||||
ip_header->ref_len = 0; \
|
||||
ip_header->ref_num = 0; \
|
||||
\
|
||||
do { \
|
||||
/* Record the reference list */ \
|
||||
ref_list = (Iprohc_ref_list *)ipcom_malloc(sizeof(Iprohc_ref_list)); \
|
||||
if (ref_list == IP_NULL) \
|
||||
{ \
|
||||
IPCOM_LOG0(ERR, "IPROHC_GET_REF_LIST, out of memory(ref_list)"); \
|
||||
goto errout; \
|
||||
} \
|
||||
\
|
||||
ipcom_memset(ref_list, 0, sizeof(Iprohc_ref_list)); \
|
||||
\
|
||||
/* Add the ref list structure to ROHC IP header structure */ \
|
||||
ipcom_list_insert_last(&ip_header->ref_head, &ref_list->ref_list); \
|
||||
ip_header->ref_num++; \
|
||||
\
|
||||
/* Record the IP extension header */ \
|
||||
ref_list->type = ptype; \
|
||||
ref_list->index = index_v; \
|
||||
index_v++; \
|
||||
if (IPROHC_IP6_EXT(ptype)) \
|
||||
/* \
|
||||
* IPv6 ext header, Hdr-ext-len (second octet of the ext header) \
|
||||
* is the length of the extension header in 8-octet units, not \
|
||||
* including the first 8 octets. \
|
||||
*/ \
|
||||
ref_list->length = (Ip_u8)(8 * (pkt->data[*pointer+1] + 1)); \
|
||||
else \
|
||||
{ \
|
||||
/* minimal encapsulation header */ \
|
||||
if (pkt->data[*pointer+1] & 0x80) \
|
||||
ref_list->length = 12; \
|
||||
else \
|
||||
ref_list->length = 8; \
|
||||
} \
|
||||
\
|
||||
ip_header->ref_len = (Ip_u16)(ip_header->ref_len + ref_list->length); \
|
||||
ref_list->data = ipcom_malloc(ref_list->length); \
|
||||
if (ref_list->data == IP_NULL) \
|
||||
{ \
|
||||
IPCOM_LOG0(ERR, "IPROHC_GET_REF_LIST, out of memory(ref->data)"); \
|
||||
goto errout; \
|
||||
} \
|
||||
\
|
||||
/* Make a copy of the ext header */ \
|
||||
ipcom_memcpy(ref_list->data, &(pkt->data[*pointer]), ref_list->length); \
|
||||
\
|
||||
/* Get type of next header and move the pointer to next ext header */ \
|
||||
ptype = pkt->data[*pointer]; \
|
||||
(*pointer) += ref_list->length; \
|
||||
} while (IPROHC_PROC_EXT(ptype) && (ip_header->ref_num <= IPROHC_MAX_LIST_ITEMS)); \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_IPID_OFFSET
|
||||
*===========================================================================
|
||||
* Loop through IP headers and update ip_id offset: ip_id - sn for each
|
||||
* IPv4 header.
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_UPD_IPID_OFFSET(ip_context) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header; \
|
||||
\
|
||||
/* Calcualte IP-ID offset for each IPv4 header : IP-ID - SN */ \
|
||||
for (ip_header = IPCOM_LIST_FIRST(&ip_context->ip_head); \
|
||||
ip_header; \
|
||||
ip_header = IPCOM_LIST_NEXT(&ip_header->ip_list)) \
|
||||
{ \
|
||||
if (ip_header->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
/* An IPv4 packet */ \
|
||||
ip_header->offset = ip_header->header.ip4.id - \
|
||||
ip_htons(ip_context->sn); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_UPD_IPID_OFFSET(ip_context) IP_NOOP
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* Public TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_ip_header
|
||||
*===========================================================================
|
||||
* The ROHC IP header structure
|
||||
*/
|
||||
|
||||
typedef struct Iprohc_ip_header_struct
|
||||
{
|
||||
Ipcom_list ip_list;
|
||||
|
||||
/* an IPv4 or IPv6 packet */
|
||||
Ip_u8 packet_type;
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
Ip_bool nbo; /* IP-ID in IPv4 header is in network byte order */
|
||||
Ip_bool rnd; /* IP-ID in IPv4 header is a pseudo-random number */
|
||||
Ip_bool sid; /* IP-ID in IPv4 header is a static value */
|
||||
Ip_s32 offset; /* offset = IP-ID - SN */
|
||||
#endif /* IPCOM_USE_INET */
|
||||
|
||||
/*
|
||||
* Header flags according to the RFC 3095, section 5.7.5.
|
||||
* Only for compressor side.
|
||||
* Format:
|
||||
* ---------------------------------------------
|
||||
* | TOS | TTL | DF | PR | IPX | NBO | RND | X |
|
||||
* ---------------------------------------------
|
||||
*
|
||||
* If X is set, means NBO flag is changed;
|
||||
* RND bit represents pseudo-randomness of IP-ID;
|
||||
* For all other bits, if set, means the corresponding field is changed.
|
||||
*/
|
||||
Ip_u8 header_flags;
|
||||
|
||||
union ip_header
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
/* IPv4 headers */
|
||||
Ipcom_ip_header ip4;
|
||||
#endif /* IPCOM_USE_INET */
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
/* IPv6 headers */
|
||||
Ipcom_ip6_header ip6;
|
||||
#endif /* IPCOM_USE_INET6 */
|
||||
} header;
|
||||
|
||||
/* IP extension headers */
|
||||
Ip_bool has_exten; /* whether has to-be-processed IP extension */
|
||||
Ip_u8 ref_num; /* number of IP extension headers */
|
||||
Ip_u16 ref_len; /* total length of IP extension headers */
|
||||
Ip_u8 gen_id; /* generation ID */
|
||||
Ipcom_list ref_head;
|
||||
}
|
||||
Iprohc_ip_header;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_c_ip_context
|
||||
*===========================================================================
|
||||
* The ROHC compression IP profile specific context structure
|
||||
*/
|
||||
|
||||
typedef struct Iprohc_c_ip_context_struct
|
||||
{
|
||||
/* Seqence number, increments in network order by 1 */
|
||||
Ip_u16 sn;
|
||||
|
||||
#ifdef IPROHC_WLSB_LSB
|
||||
/* WLSB for encoding SN */
|
||||
iprohc_create_cmp_wlsb_struct(sn_wlsb, 16);
|
||||
#endif /* IPROHC_WLSB_LSB */
|
||||
|
||||
/* Whether to add list of dynamic chains for additional IP headers */
|
||||
/* in a non IR/IR-DYN packet */
|
||||
Ip_bool add_dynamic_chain;
|
||||
|
||||
/* Payload offset in Ipcom_pkt structure */
|
||||
int payload_offset;
|
||||
|
||||
Ip_u8 ip_num; /* number of IP headers */
|
||||
Ipcom_list ip_head;
|
||||
}
|
||||
Iprohc_c_ip_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_d_ip_context
|
||||
*===========================================================================
|
||||
* The ROHC decompression IP profile specific context structure
|
||||
*/
|
||||
|
||||
typedef struct Iprohc_d_ip_context_struct
|
||||
{
|
||||
/* Seqence number for the context, increments in network order by 1 */
|
||||
Ip_u16 sn;
|
||||
|
||||
#ifdef IPROHC_WLSB_LSB
|
||||
/* LSB for decoding SN */
|
||||
iprohc_create_dmp_lsb_struct(sn_lsb);
|
||||
#endif /* IPROHC_WLSB_LSB */
|
||||
|
||||
/* Payload offset in a received compressed Ipcom_pkt structure */
|
||||
int payload_offset;
|
||||
|
||||
Ip_u8 ip_num; /* number of IP headers */
|
||||
Ipcom_list ip_head;
|
||||
}
|
||||
Iprohc_d_ip_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Profile registration/de-registration functions */
|
||||
IP_PUBLIC Ip_err iprohc_profile_ip_register(void);
|
||||
IP_PUBLIC Ip_err iprohc_ip_deregister(void);
|
||||
|
||||
|
||||
/* Profile specific compression functions */
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_ip_c_find_context(Iprohc_compressor *comp, Ipcom_pkt *pkt,
|
||||
Iprohc_c_context **c_context);
|
||||
IP_PUBLIC Iprohc_c_context *
|
||||
iprohc_ip_c_create_context(Iprohc_compressor *comp,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_err iprohc_ip_c_del_context(Iprohc_c_context *context);
|
||||
IP_PUBLIC Ip_err iprohc_ip_c_process_feedback(Iprohc_c_context *context,
|
||||
Ip_u8 *feedback, Ip_u8 size);
|
||||
IP_PUBLIC Ip_err iprohc_ip_c_compress(Iprohc_c_context *context,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC void iprohc_ip_c_print_context(Iprohc_c_context *context);
|
||||
|
||||
|
||||
/* Profile specific decompression functions */
|
||||
IP_PUBLIC Iprohc_d_context *
|
||||
iprohc_ip_d_find_context(Iprohc_decompressor *decomp, Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Iprohc_d_context *
|
||||
iprohc_ip_d_create_context(Iprohc_decompressor *decomp,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_err iprohc_ip_d_del_context(Iprohc_d_context *context);
|
||||
IP_PUBLIC void iprohc_ip_d_print_context(Iprohc_d_context *context);
|
||||
IP_PUBLIC Ip_err iprohc_ip_d_decompress(Iprohc_d_context *context,
|
||||
Ipcom_pkt *pkt);
|
||||
|
||||
/* IP profile routines used in other sprofiles */
|
||||
IP_PUBLIC Ip_err iprohc_del_ip_context(void *context, Ip_bool is_comp);
|
||||
IP_PUBLIC Ip_err iprohc_d_copy_ip_context(Iprohc_d_ip_context **to_context,
|
||||
Iprohc_d_ip_context *from_context);
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_c_update_ip_hdrs(Iprohc_c_ip_context *context, Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_err iprohc_c_update_ip_context(Iprohc_c_context *context,
|
||||
Ipcom_pkt *pkt);
|
||||
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_c_update_ip_ext(Iprohc_ip_header *ip_header, Ip_u8 type,
|
||||
Ipcom_pkt *pkt, int *pointer, Ip_bool *updated);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* #ifndef IPROHC_IP_H */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,648 @@
|
||||
/* iprohc_parser.h - ROHC parsing head file */
|
||||
|
||||
/*
|
||||
* Copyright (c) 20013 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,30jul13,j_y Clean medium impact code review defects
|
||||
01g,15dec10,ggz Fix for defect WIND00254509
|
||||
01f,10apr10,ggz Resolve 64bit compiler warnings
|
||||
01e,20apr09,tlu Fix Linux build warnings for mips64 gcc (cav_ebt5800)
|
||||
01d,04jul08,tlu Add to handle IP extension headers
|
||||
01c,11jun08,tlu Fix to parse large CID
|
||||
01b,14may08,tlu Change function prototyping for parsing pkt types
|
||||
01a,04apr08,tlu Created.
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_PARSER_H
|
||||
#define IPROHC_PARSER_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_inet.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
|
||||
|
||||
#include "iprohc_constant.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_CID
|
||||
*===========================================================================
|
||||
* Get CID from a received compressed packet. pointer will be moved to
|
||||
* point to Body. type_data will store (type indication + body) octet.
|
||||
*
|
||||
* Passed in packet has the following general format:
|
||||
* RFC 3095, 5.2
|
||||
*
|
||||
* --------------------------
|
||||
* : Add-CID octet : if (CID 1-15) and (small CIDs)
|
||||
* --------------------------
|
||||
* | type indication | body |
|
||||
* --------------------------
|
||||
* : :
|
||||
* / 0 - 2 octets of CID / 1 or 2 octets if (large CIDs)
|
||||
* : :
|
||||
* --------------------------
|
||||
* / Body / variable length
|
||||
* --------------------------
|
||||
*
|
||||
*/
|
||||
#define IPROHC_GET_CID(pkt, pointer, cid, type_data) \
|
||||
{ \
|
||||
pointer = pkt->ipstart; \
|
||||
if ((pkt->data[pointer] >> ROHC_PKT_ADD_CID_SHIFT) == \
|
||||
ROHC_PKT_ADD_CID) \
|
||||
{ \
|
||||
/* small CID */ \
|
||||
cid = (Ip_u16)(pkt->data[pointer] & 0x0F); \
|
||||
type_data = pkt->data[pointer+1]; \
|
||||
pointer += 2; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* large CID */ \
|
||||
type_data = pkt->data[pointer]; \
|
||||
\
|
||||
/* \
|
||||
* Decode cid according to RFC 3095, 4.5.6. \
|
||||
* RFC 3095, section 5.2.2: If the first bit is 0, the CID uses \
|
||||
* one octet. If the first bit is 1, the CID uses two octet. \
|
||||
*/ \
|
||||
if ((pkt->data[pointer+1] & 0x80) == 0) \
|
||||
{ \
|
||||
cid = pkt->data[pointer+1]; \
|
||||
pointer += 2; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ipcom_memcpy(&cid, &(pkt->data[pointer+1]), 2); \
|
||||
cid = ip_ntohs(cid); \
|
||||
cid = (Ip_u16)(cid & 0x7fff); \
|
||||
pointer += 3; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_LIST_ET0
|
||||
*===========================================================================
|
||||
* Parse the compressed list encoding type 0
|
||||
*
|
||||
* 5.8.6.1 Encoding Type 0 (generic scheme)
|
||||
*
|
||||
* ---------------------------------
|
||||
* | ET=0 |GP|PS| CC = m |
|
||||
* ---------------------------------
|
||||
* : gen_id : 1 octet, if GP = 1
|
||||
* ---------------------------------
|
||||
* | XI 1, ..., XI m | m octets, or m * 4 bits
|
||||
* / -----------------/
|
||||
* | : Padding : if PS = 0 and m is odd
|
||||
* ---------------------------------
|
||||
* / item1, ..., item n / variable
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#define IPROHC_GET_LIST_ET0(ip_head, ptype, pointer, pkt, updated) \
|
||||
{ \
|
||||
int i, et_type; \
|
||||
Iprohc_ref_list *ref_list; \
|
||||
\
|
||||
et_type = pkt->data[pointer]; \
|
||||
ip_head.has_exten = IP_TRUE; \
|
||||
ip_head.ref_num = (Ip_u8)(et_type & 0x0F); \
|
||||
ip_head.gen_id = pkt->data[pointer+1]; \
|
||||
/* move the item pointer to items */ \
|
||||
if (ip_head.ref_num < 8) \
|
||||
pointer += 2 + (int)(ip_head.ref_num/2) + (ip_head.ref_num%2); \
|
||||
else \
|
||||
pointer += 2 + ip_head.ref_num; \
|
||||
\
|
||||
/* create extension header list */ \
|
||||
for (i = 1; i <= ip_head.ref_num; i++) \
|
||||
{ \
|
||||
/* Record the reference list */ \
|
||||
ref_list = (Iprohc_ref_list *)ipcom_malloc(sizeof(Iprohc_ref_list)); \
|
||||
if (ref_list == IP_NULL) \
|
||||
{ \
|
||||
IPCOM_LOG0(ERR, "IPROHC_GET_LIST_ET0, out of memory(ref_list)"); \
|
||||
updated = IP_FALSE; \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
ipcom_memset(ref_list, 0, sizeof(Iprohc_ref_list)); \
|
||||
\
|
||||
/* Add the ref list structure to ROHC IP header structure */ \
|
||||
ipcom_list_insert_last(&ip_head.ref_head, &ref_list->ref_list); \
|
||||
\
|
||||
/* Record the IP extension header */ \
|
||||
ref_list->type = ptype; \
|
||||
if (IPROHC_IP6_EXT(ptype)) \
|
||||
/* \
|
||||
* IPv6 ext header, Hdr-ext-len (second octet of the ext header) \
|
||||
* is the length of the extension header in 8-octet units, not \
|
||||
* including the first 8 octets. \
|
||||
*/ \
|
||||
ref_list->length = (Ip_u8)(8 * (pkt->data[pointer+1] + 1)); \
|
||||
else \
|
||||
{ \
|
||||
/* minimal encapsulation header */ \
|
||||
if (pkt->data[pointer+1] & 0x80) \
|
||||
ref_list->length = 12; \
|
||||
else \
|
||||
ref_list->length = 8; \
|
||||
} \
|
||||
\
|
||||
ip_head.ref_len = (Ip_u16)(ip_head.ref_len + ref_list->length); \
|
||||
ref_list->data = ipcom_malloc(ref_list->length); \
|
||||
if (ref_list->data == IP_NULL) \
|
||||
{ \
|
||||
IPCOM_LOG0(ERR, "IPROHC_GET_LIST_ET0, out of memory(ref->data)"); \
|
||||
updated = IP_FALSE; \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
/* Make a copy of the ext header */ \
|
||||
ipcom_memcpy(ref_list->data, &pkt->data[pointer], ref_list->length); \
|
||||
\
|
||||
/* Move the pointer to next item */ \
|
||||
ptype = pkt->data[pointer]; \
|
||||
pointer += ref_list->length; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_LIST_ET0
|
||||
*===========================================================================
|
||||
* Update the compressed list encoding type 0
|
||||
*
|
||||
*/
|
||||
#define IPROHC_UPD_LIST_ET0(iprohc_header, protocol, pointer, pkt) \
|
||||
{ \
|
||||
Iprohc_ip_header tmp_ip_header; \
|
||||
Ip_bool updated = IP_TRUE; \
|
||||
Ip_u8 proto = protocol; \
|
||||
\
|
||||
/* Get the new reference list */ \
|
||||
ipcom_memset(&tmp_ip_header,0,sizeof(tmp_ip_header)); \
|
||||
ipcom_list_init(&tmp_ip_header.ref_head); \
|
||||
IPROHC_GET_LIST_ET0(tmp_ip_header, proto, pointer, pkt, updated); \
|
||||
if (updated) \
|
||||
{ \
|
||||
/* Free the old reference list */ \
|
||||
IPROHC_FREE_REF_LIST(iprohc_header); \
|
||||
\
|
||||
/* Record the new one */ \
|
||||
IPROHC_COPY_REF_LIST(iprohc_header, (&tmp_ip_header)); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Free the new reference list */ \
|
||||
IPROHC_FREE_REF_LIST((&tmp_ip_header)); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_IPV4_STATIC
|
||||
*===========================================================================
|
||||
* Get an IPv4 static part in Static chain from a IR packet
|
||||
*
|
||||
* 5.7.7.4 IPv4 header static part format
|
||||
*
|
||||
* ---------------------------------
|
||||
* | version = 4 | 0 |
|
||||
* ---------------------------------
|
||||
* | Protocol |
|
||||
* ---------------------------------
|
||||
* / Source Address / 4 octets
|
||||
* ---------------------------------
|
||||
* / Destination Address / 4 octets
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_GET_IPV4_STATIC(iprohc_header, pointer, pkt) \
|
||||
{ \
|
||||
Ipcom_ip_header *ip4_header = &(iprohc_header->header.ip4); \
|
||||
\
|
||||
iprohc_header->packet_type = ROHC_PKT_IPV4; \
|
||||
/* version = 4, IHL = 5 */ \
|
||||
ip4_header->vers_len = 0x45; \
|
||||
ip4_header->protocol = pkt->data[pointer+1]; \
|
||||
\
|
||||
if (IPROHC_PROC_EXT(ip4_header->protocol)) \
|
||||
iprohc_header->has_exten = IP_TRUE; \
|
||||
else if (iprohc_header->has_exten) \
|
||||
{ \
|
||||
/* Free the old IP extension headers */ \
|
||||
IPROHC_FREE_REF_LIST(iprohc_header); \
|
||||
} \
|
||||
\
|
||||
/* Copy source and destination address */ \
|
||||
ipcom_memcpy(&ip4_header->src, &pkt->data[pointer+2], 4); \
|
||||
ipcom_memcpy(&ip4_header->dst, &pkt->data[pointer+6], 4); \
|
||||
\
|
||||
/* Move the pointer */ \
|
||||
pointer += 10; \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_GET_IPV4_STATIC(iprohc_header, pointer, pkt) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_IPV6_STATIC
|
||||
*===========================================================================
|
||||
* Get an IPv6 static part in Static chain from a IR packet
|
||||
*
|
||||
* 5.7.7.3 IPv6 header static part format
|
||||
*
|
||||
* ---------------------------------
|
||||
* | version = 6 |Flow Label (msb) | 1 octet
|
||||
* ---------------------------------
|
||||
* | Flow Label (lsb) | 2 octets
|
||||
* ---------------------------------
|
||||
* | Next Header | 1 octet
|
||||
* ---------------------------------
|
||||
* / Source Address / 16 octets
|
||||
* ---------------------------------
|
||||
* / Destination Address / 16 octets
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET6
|
||||
#define IPROHC_GET_IPV6_STATIC(iprohc_header, pointer, pkt) \
|
||||
{ \
|
||||
Ipcom_ip6_header *ip6_header = &(iprohc_header->header.ip6); \
|
||||
Ip_u32 flow = 0, ver_class_flow; \
|
||||
Ip_u16 flow_lsb; \
|
||||
\
|
||||
iprohc_header->packet_type = ROHC_PKT_IPV6; \
|
||||
/* Form the flow label */ \
|
||||
flow = (Ip_u32)(pkt->data[pointer] & 0x0F) << 16; \
|
||||
flow_lsb = ip_ntohs((Ip_u16)pkt->data[pointer+1]); \
|
||||
flow += flow_lsb; \
|
||||
\
|
||||
/* (version=6)+(class will be taken from dynamic part)+flow */ \
|
||||
/* stored in network order */ \
|
||||
ver_class_flow = (6<<28) + flow; \
|
||||
ip6_header->ver_class_flow = ip_htonl(ver_class_flow); \
|
||||
\
|
||||
/* next header */ \
|
||||
ip6_header->nxt = pkt->data[pointer+3]; \
|
||||
\
|
||||
if (IPROHC_PROC_EXT(ip6_header->nxt)) \
|
||||
iprohc_header->has_exten = IP_TRUE; \
|
||||
else if (iprohc_header->has_exten) \
|
||||
{ \
|
||||
/* Free the old IP extension headers */ \
|
||||
IPROHC_FREE_REF_LIST(iprohc_header); \
|
||||
} \
|
||||
\
|
||||
/* copy source and destination addresses */ \
|
||||
ipcom_memcpy(&ip6_header->src, &pkt->data[pointer+4], 16); \
|
||||
ipcom_memcpy(&ip6_header->dst, &pkt->data[pointer+20], 16); \
|
||||
\
|
||||
/* move pointer */ \
|
||||
pointer += 36; \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_GET_IPV6_STATIC(iprohc_header, pointer, pkt) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_IPV4_DYNAMIC
|
||||
*===========================================================================
|
||||
* Get an IPv4 dynamic part in Dynamic chain from a IR/IR-DYN packet
|
||||
*
|
||||
* 5.7.7.4 IPv4 header dynamic part format
|
||||
*
|
||||
* ---------------------------------
|
||||
* | Type of Service |
|
||||
* ---------------------------------
|
||||
* | Time to Live |
|
||||
* ---------------------------------
|
||||
* / Identification / 2 octets
|
||||
* ---------------------------------
|
||||
* | DF|RND|NBO|SID| 0 |
|
||||
* ---------------------------------
|
||||
* / Generic extension Header list / (not supported)
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET
|
||||
#define IPROHC_GET_IPV4_DYNAMIC(iprohc_header, pointer, pkt) \
|
||||
{ \
|
||||
Ipcom_ip_header *ip4_header = &(iprohc_header->header.ip4); \
|
||||
\
|
||||
ip4_header->tos = pkt->data[pointer]; \
|
||||
ip4_header->ttl = pkt->data[pointer+1]; \
|
||||
/* ID is in network order */ \
|
||||
ipcom_memcpy(&(ip4_header->id), &(pkt->data[pointer+2]), 2); \
|
||||
iprohc_header->rnd = (Ip_bool)((pkt->data[pointer+4] & 0x40) >> 6); \
|
||||
iprohc_header->nbo = (Ip_bool)((pkt->data[pointer+4] & 0x20) >> 5); \
|
||||
iprohc_header->sid = (Ip_bool)((pkt->data[pointer+4] & 0x10) >> 4); \
|
||||
if (pkt->data[pointer+4] & 0x80) ip4_header->frag |= IPCOM_IPFRAG_DF; \
|
||||
\
|
||||
/* Move the pointer */ \
|
||||
pointer += 5; \
|
||||
if (iprohc_header->has_exten) \
|
||||
IPROHC_UPD_LIST_ET0(iprohc_header, ip4_header->protocol, pointer, pkt); \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_GET_IPV4_DYNAMIC(iprohc_header, pointer, pkt) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_IPV6_DYNAMIC
|
||||
*===========================================================================
|
||||
* Get an IPv6 dynamic part in Dynamic chain from a IR/IR-DYN packet
|
||||
*
|
||||
* 5.7.7.3 IPv6 header dynamic part format
|
||||
*
|
||||
* ---------------------------------
|
||||
* | Traffic Class | 1 octet
|
||||
* ---------------------------------
|
||||
* | Hop Limit | 1 octet
|
||||
* ---------------------------------
|
||||
* / Generic extension Header list / (not supported)
|
||||
* ---------------------------------
|
||||
*
|
||||
*/
|
||||
#ifdef IPCOM_USE_INET6
|
||||
#define IPROHC_GET_IPV6_DYNAMIC(iprohc_header, pointer, pkt) \
|
||||
{ \
|
||||
Ipcom_ip6_header *ip6_header; \
|
||||
Ip_u32 ver_class_flow; \
|
||||
\
|
||||
ip6_header = (Ipcom_ip6_header *)&(iprohc_header->header.ip6); \
|
||||
ver_class_flow = ip_ntohl(ip6_header->ver_class_flow); \
|
||||
\
|
||||
/* Add traffic class (8 bits) to ver_class_flow */ \
|
||||
ver_class_flow += (Ip_u32)((pkt->data[pointer])<<20); \
|
||||
ip6_header->ver_class_flow = ip_htonl(ver_class_flow); \
|
||||
ip6_header->hlim = pkt->data[pointer+1]; \
|
||||
\
|
||||
/* Move pointer */ \
|
||||
pointer += 2; \
|
||||
if (iprohc_header->has_exten) \
|
||||
IPROHC_UPD_LIST_ET0(iprohc_header, ip6_header->nxt, pointer, pkt); \
|
||||
}
|
||||
#else
|
||||
#define IPROHC_GET_IPV6_DYNAMIC(iprohc_header, pointer, pkt) IP_NOOP
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_IP_STATIC
|
||||
*===========================================================================
|
||||
* Get Static chain in a IR packet
|
||||
*/
|
||||
#define IPROHC_GET_IP_STATIC(ip_context, pointer, pkt) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header_v; \
|
||||
Ip_u8 protocol; \
|
||||
\
|
||||
while (((pkt->data[pointer] >> 4) == 4) || \
|
||||
((pkt->data[pointer] >> 4) == 6)) \
|
||||
{ \
|
||||
ip_header_v = (Iprohc_ip_header *)ipcom_malloc(sizeof(Iprohc_ip_header)); \
|
||||
if (ip_header_v == IP_NULL) \
|
||||
{ \
|
||||
IPCOM_LOG0(ERR,"IPROHC_GET_IP_STATIC, out of memory(header)"); \
|
||||
goto errout; \
|
||||
} \
|
||||
\
|
||||
/* Pre-init the memory */ \
|
||||
ipcom_memset(ip_header_v, 0, sizeof(Iprohc_ip_header));\
|
||||
ipcom_list_init(&ip_header_v->ref_head); \
|
||||
\
|
||||
/* Add the header to the context list */ \
|
||||
ipcom_list_insert_last(&ip_context->ip_head, &ip_header_v->ip_list); \
|
||||
ip_context->ip_num++; \
|
||||
\
|
||||
if ((pkt->data[pointer] >> 4) == 4) \
|
||||
{ \
|
||||
protocol = pkt->data[pointer+1]; \
|
||||
\
|
||||
/* An IPv4 header */ \
|
||||
IPROHC_GET_IPV4_STATIC(ip_header_v, pointer, pkt); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
protocol = pkt->data[pointer+2]; \
|
||||
\
|
||||
/* An IPv6 header */ \
|
||||
IPROHC_GET_IPV6_STATIC(ip_header_v, pointer, pkt); \
|
||||
} \
|
||||
\
|
||||
if ((protocol != IP_IPPROTO_IPIP) && \
|
||||
(protocol != IP_IPPROTO_IPV6)) \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_IP_DYNAMIC
|
||||
*===========================================================================
|
||||
* Get Dynamic chain in a IR/IP-DYN packet
|
||||
*/
|
||||
#define IPROHC_GET_IP_DYNAMIC(ip_context, pointer, pkt) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header_v, *p_ip_header; \
|
||||
\
|
||||
for (ip_header_v = IPCOM_LIST_FIRST(&ip_context->ip_head); ip_header_v; \
|
||||
ip_header_v = p_ip_header) \
|
||||
{ \
|
||||
p_ip_header = IPCOM_LIST_NEXT(&ip_header_v->ip_list); \
|
||||
\
|
||||
if (ip_header_v->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
/* Get an IPv4 dynamic part */ \
|
||||
IPROHC_GET_IPV4_DYNAMIC(ip_header_v, pointer, pkt); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Get an IPv6 dynamic part */ \
|
||||
IPROHC_GET_IPV6_DYNAMIC(ip_header_v, pointer, pkt); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_IP_STATIC
|
||||
*===========================================================================
|
||||
* Update Static chains from a IR packet
|
||||
*/
|
||||
#define IPROHC_UPD_IP_STATIC(ip_context, pointer, pkt) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header, *p_ip_header; \
|
||||
\
|
||||
for (ip_header = IPCOM_LIST_FIRST(&ip_context->ip_head); ip_header; \
|
||||
ip_header = p_ip_header) \
|
||||
{ \
|
||||
p_ip_header = IPCOM_LIST_NEXT(&ip_header->ip_list); \
|
||||
\
|
||||
if (ip_header->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
/* Update an IPv4 static part */ \
|
||||
IPROHC_GET_IPV4_STATIC(ip_header, pointer, pkt); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Update an IPv6 static part */ \
|
||||
IPROHC_GET_IPV6_STATIC(ip_header, pointer, pkt); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_IP_DYNAMIC
|
||||
*===========================================================================
|
||||
* Update Dynamic chains from a IR/IR-DYN packet
|
||||
*/
|
||||
#define IPROHC_UPD_IP_DYNAMIC(ip_context, pointer, pkt) \
|
||||
IPROHC_GET_IP_DYNAMIC(ip_context, pointer, pkt)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_IP_ADDTIONAL_DYNAMIC
|
||||
*===========================================================================
|
||||
* Update additional Dynamic chains from a IP general compressed packet
|
||||
*/
|
||||
#define IPROHC_UPD_IP_ADDTIONAL_DYNAMIC(ip_context, pointer, pkt) \
|
||||
{ \
|
||||
Iprohc_ip_header *ip_header, *p_ip_header; \
|
||||
\
|
||||
/* Skip the first two headers */ \
|
||||
ip_header = IPCOM_LIST_FIRST(&ip_context->ip_head); \
|
||||
if(ip_header != IP_NULL) \
|
||||
ip_header = IPCOM_LIST_NEXT(&ip_header->ip_list); \
|
||||
if(ip_header != IP_NULL) /* Start for loop from the third IP header */ \
|
||||
for (ip_header = IPCOM_LIST_NEXT(&ip_header->ip_list); ip_header; \
|
||||
ip_header = p_ip_header) \
|
||||
{ \
|
||||
p_ip_header = IPCOM_LIST_NEXT(&ip_header->ip_list); \
|
||||
\
|
||||
if (ip_header->packet_type == ROHC_PKT_IPV4) \
|
||||
{ \
|
||||
/* Get an IPv4 dynamic part */ \
|
||||
IPROHC_GET_IPV4_DYNAMIC(ip_header, pointer, pkt); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Get an IPv6 dynamic part */ \
|
||||
IPROHC_GET_IPV6_DYNAMIC(ip_header, pointer, pkt); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* Public TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Received packet initial parsing functions */
|
||||
IP_PUBLIC Ip_u8 iprohc_parse_pkt_type(Ipcom_pkt *pkt,
|
||||
Ip_u16 *feedback_num,
|
||||
Ip_u8 **feedbacks,
|
||||
Ipcom_netif *netif);
|
||||
|
||||
/* Parse extension */
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_parse_extension(void *out_header, void *in_header,
|
||||
Ip_u8 *sn, int *mode,
|
||||
int *in_bno, int *in_rnd,
|
||||
int *out_bno, int *out_rnd,
|
||||
Ipcom_pkt *pkt, int *pointer);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* #ifndef IPROHC_PARSER_H */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,464 @@
|
||||
/* iprohc_udp_ip.h - ROHC UDP IP profile head file */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 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
|
||||
--------------------
|
||||
01b,12apr10,ggz Resolve 64bit compiler warnings
|
||||
01a,01dec09,ggz Created
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_UDP_IP_H
|
||||
#define IPROHC_UDP_IP_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_tags.h>
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_list.h>
|
||||
|
||||
|
||||
#include "iprohc_config.h"
|
||||
#include "iprohc_constant.h"
|
||||
#include "iprohc_ip.h"
|
||||
#include "iprohc_coding_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPROHC_ENABLE_REENTRANT
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_UDP_DYNAMIC
|
||||
*===========================================================================
|
||||
* Fomat dynamic chain in a IR/IR-DYN packet
|
||||
*
|
||||
*
|
||||
* UDP header dynamic part
|
||||
* +---+---+---+---+---+---+---+---+
|
||||
* / UDP checksum / 2 octets
|
||||
* +---+---+---+---+---+---+---+---+
|
||||
*/
|
||||
#define IPROHC_FMT_UDP_DYNAMC(udp_context, pointer, has_dynamic, pkt) \
|
||||
{ \
|
||||
pointer -= 2; \
|
||||
ipcom_memcpy(&pkt->data[pointer], &udp_context->checksum, 2); \
|
||||
/* UDP length field is eliminated */ \
|
||||
has_dynamic = IP_TRUE; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_FMT_UDP_STATIC
|
||||
*===========================================================================
|
||||
* Fomat dynamic chain in a IR/IR-DYN packet
|
||||
*
|
||||
* UDP header static part
|
||||
* +---+---+---+---+---+---+---+---+
|
||||
* / UDP source port / 2 octets
|
||||
* +---+---+---+---+---+---+---+---+
|
||||
* / UDP destination port / 2 octets
|
||||
* +---+---+---+---+---+---+---+---+
|
||||
*/
|
||||
#define IPROHC_FMT_UDP_STATIC(udp_context, pointer, pkt) \
|
||||
{ \
|
||||
pointer -= 2; \
|
||||
ipcom_memcpy(&pkt->data[pointer], &udp_context->dst_port, 2); \
|
||||
pointer -= 2; \
|
||||
ipcom_memcpy(&pkt->data[pointer], &udp_context->src_port, 2); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UDP_UPDATE_CONTEXT
|
||||
*===========================================================================
|
||||
* Update the UDP context
|
||||
*
|
||||
* Should hdr(UDP Checksum) be nonzero when context(UDP Checksum) is zero,
|
||||
* the header cannot be compressed. It must be sent uncompressed or the context
|
||||
* reinitialized using an IR packet.
|
||||
*/
|
||||
#define IPROHC_UDP_UPDATE_CONTEXT(c_context, udp_context, udp_header, pkt) \
|
||||
{ \
|
||||
Ip_u16 prev_checksum; \
|
||||
prev_checksum = udp_context->checksum; \
|
||||
udp_context->length = udp_header.length; \
|
||||
udp_context->checksum = udp_header.checksum; \
|
||||
udp_context->payload = pkt->tlstart + 8; \
|
||||
\
|
||||
/* Is there checksum usage switch */ \
|
||||
if (((prev_checksum == 0) && (udp_context->checksum != 0)) || \
|
||||
((prev_checksum != 0) && (udp_context->checksum == 0))) \
|
||||
{ \
|
||||
/* Update the state of the context to IR */ \
|
||||
c_context->state = ROHC_COMP_STATE_IR; \
|
||||
c_context->num_ir = 0; \
|
||||
c_context->pkt_type = ROHC_PKT_IR; \
|
||||
} \
|
||||
\
|
||||
if(udp_context->checksum != 0) \
|
||||
udp_context->use_checksum = IP_TRUE; \
|
||||
else \
|
||||
udp_context->use_checksum = IP_FALSE; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UDP_INIT_CONTEXT
|
||||
*===========================================================================
|
||||
* Set the UDP context
|
||||
*/
|
||||
#define IPROHC_UDP_INIT_CONTEXT(udp_context, udp_header, pkt) \
|
||||
{ \
|
||||
udp_context->src_port = udp_header.src_port; \
|
||||
udp_context->dst_port = udp_header.dst_port; \
|
||||
udp_context->length = udp_header.length; \
|
||||
udp_context->checksum = udp_header.checksum; \
|
||||
udp_context->payload = pkt->tlstart + 8; \
|
||||
\
|
||||
if(udp_context->checksum != 0) \
|
||||
udp_context->use_checksum = IP_TRUE; \
|
||||
else \
|
||||
udp_context->use_checksum = IP_FALSE; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_UDP_STATIC
|
||||
*===========================================================================
|
||||
* GET UDP static header part in a IR packet
|
||||
*/
|
||||
#define IPROHC_GET_UDP_STATIC(udp_context, pointer, pkt) \
|
||||
{ \
|
||||
ipcom_memcpy(&udp_context->src_port, &pkt->data[pointer], 2); \
|
||||
pointer += 2; \
|
||||
ipcom_memcpy(&udp_context->dst_port, &pkt->data[pointer], 2); \
|
||||
pointer += 2; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_UDP_DYNAMIC
|
||||
*===========================================================================
|
||||
* Get UDP dynamic chain in a IR/IP-DYN packet and set the checksum usage
|
||||
* control
|
||||
*/
|
||||
#define IPROHC_GET_UDP_DYNAMIC(udp_context, pointer, pkt) \
|
||||
{ \
|
||||
ipcom_memcpy(&udp_context->checksum, &pkt->data[pointer], 2); \
|
||||
pointer += 2; \
|
||||
if(udp_context->checksum != 0) \
|
||||
udp_context->use_checksum = IP_TRUE; \
|
||||
else \
|
||||
udp_context->use_checksum = IP_FALSE; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_UDP_DYNAMIC1
|
||||
*===========================================================================
|
||||
* Get UDP dynamic chain in a genral packet
|
||||
*
|
||||
* Checksum controll field can not be updated by general packets.
|
||||
* Only IR packets can update it. Used for general packets.
|
||||
*/
|
||||
#define IPROHC_UPD_UDP_DYNAMIC1(udp_context, pointer, pkt, udp_chksum) \
|
||||
{ \
|
||||
if (udp_context->use_checksum == IP_TRUE) \
|
||||
{ \
|
||||
ipcom_memcpy(&udp_context->checksum, &pkt->data[pointer], 2); \
|
||||
pointer += 2; \
|
||||
} \
|
||||
else udp_context->checksum = 0; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_UDP_STATIC
|
||||
*===========================================================================
|
||||
* Update UDP static header
|
||||
*/
|
||||
#define IPROHC_UPD_UDP_STATIC(udp_context, pointer, pkt) \
|
||||
{ \
|
||||
IPROHC_GET_UDP_STATIC(udp_context, pointer, pkt) \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_UPD_UDP_DYNAMIC
|
||||
*===========================================================================
|
||||
* Update UDP dynamic header
|
||||
*/
|
||||
#define IPROHC_UPD_UDP_DYNAMIC(udp_context, pointer, pkt) \
|
||||
{ \
|
||||
IPROHC_GET_UDP_DYNAMIC(udp_context, pointer, pkt) \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_GET_UDP_LENGTH
|
||||
*===========================================================================
|
||||
* Calculate UDP length. Used with IR, IR-DYN packets.
|
||||
*/
|
||||
#define IPROHC_GET_UDP_LENGTH(udp_context, pkt) \
|
||||
{ \
|
||||
udp_context->length = (Ip_u16)(pkt->end - udp_context->payload + 8); \
|
||||
udp_context->length = ipcom_htons(udp_context->length); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPROHC_RECONSTRUCT_UDP
|
||||
*===========================================================================
|
||||
* Reconstruct the packet from UDP context
|
||||
*/
|
||||
#define IPROHC_RECONSTRUCT_UDP(udp_context, pkt) \
|
||||
{ \
|
||||
Ip_u16 data_tmp = 0; \
|
||||
pkt->ipstart -= 2; \
|
||||
if(udp_context->use_checksum == IP_TRUE) \
|
||||
ipcom_memcpy(&pkt->data[pkt->ipstart], &udp_context->checksum, 2); \
|
||||
else \
|
||||
{ \
|
||||
ipcom_memcpy(&pkt->data[pkt->ipstart], &data_tmp, 2); \
|
||||
} \
|
||||
pkt->ipstart -= 2; \
|
||||
ipcom_memcpy(&pkt->data[pkt->ipstart], &udp_context->length, 2); \
|
||||
pkt->ipstart -= 2; \
|
||||
ipcom_memcpy(&pkt->data[pkt->ipstart], &udp_context->dst_port, 2); \
|
||||
pkt->ipstart -= 2; \
|
||||
ipcom_memcpy(&pkt->data[pkt->ipstart], &udp_context->src_port, 2); \
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* Public TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
typedef struct udp_header_struct
|
||||
{
|
||||
/* Source port */
|
||||
Ip_u16 src_port;
|
||||
|
||||
/* Destination port */
|
||||
Ip_u16 dst_port;
|
||||
|
||||
/* UDP length */
|
||||
Ip_u16 length;
|
||||
|
||||
/* UDP length */
|
||||
Ip_u16 checksum;
|
||||
}udp_header;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_c_udp_context_struct
|
||||
*===========================================================================
|
||||
* ROHC compression UDP profile specific context structure
|
||||
*/
|
||||
typedef struct Iprohc_c_udp_context_struct
|
||||
{
|
||||
/* Source port */
|
||||
Ip_u16 src_port;
|
||||
|
||||
/* Destination port */
|
||||
Ip_u16 dst_port;
|
||||
|
||||
/* UDP length */
|
||||
Ip_u16 length;
|
||||
|
||||
/* UDP checksum */
|
||||
Ip_u16 checksum;
|
||||
|
||||
/* TRUE if checksum is used */
|
||||
Ip_bool use_checksum;
|
||||
|
||||
/* Pointer to UDP payload */
|
||||
int payload;
|
||||
|
||||
/* Statistic information */
|
||||
Ip_u32 udp_pkt_count;
|
||||
}
|
||||
Iprohc_c_udp_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_d_udp_context_struct
|
||||
*===========================================================================
|
||||
* ROHC decompression UDP profile specific context structure
|
||||
*/
|
||||
typedef struct Iprohc_d_udp_context_struct
|
||||
{
|
||||
|
||||
/* Source port */
|
||||
Ip_u16 src_port;
|
||||
|
||||
/* Destination port */
|
||||
Ip_u16 dst_port;
|
||||
|
||||
/* UDP length */
|
||||
Ip_u16 length;
|
||||
|
||||
/* UDP checksum */
|
||||
Ip_u16 checksum;
|
||||
|
||||
/* TRUE if checksum is used */
|
||||
Ip_bool use_checksum;
|
||||
|
||||
/* Pointer to UDP payload */
|
||||
int payload;
|
||||
|
||||
/* Statistic information */
|
||||
Ip_u32 udp_pkt_count;
|
||||
}
|
||||
Iprohc_d_udp_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_c_udp_ip_context_struct
|
||||
*===========================================================================
|
||||
* ROHC compression UDP_IP profile specific context structure
|
||||
*/
|
||||
typedef struct Iprohc_c_udp_ip_context_struct
|
||||
{
|
||||
/* IPvX specific context */
|
||||
Iprohc_c_ip_context *ip_context;
|
||||
/* UDP sepecific context */
|
||||
Iprohc_c_udp_context *udp_context;
|
||||
}
|
||||
Iprohc_c_udp_ip_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Iprohc_d_udp_ip_context_struct
|
||||
*===========================================================================
|
||||
* ROHC decompression UDP_IP profile specific context structure
|
||||
*/
|
||||
|
||||
typedef struct Iprohc_d_udp_ip_context_struct
|
||||
{
|
||||
/* IPvX specific context */
|
||||
Iprohc_d_ip_context *ip_context;
|
||||
/* UDP sepecific context */
|
||||
Iprohc_d_udp_context *udp_context;
|
||||
}
|
||||
Iprohc_d_udp_ip_context;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Profile registration/deregistration functions */
|
||||
IP_PUBLIC Ip_err iprohc_profile_udp_ip_register(void);
|
||||
IP_PUBLIC Ip_err iprohc_udp_ip_deregister(void);
|
||||
|
||||
/* Profile specific compression functions */
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_udp_ip_c_find_context(Iprohc_compressor *comp, Ipcom_pkt *pkt,
|
||||
Iprohc_c_context **c_context);
|
||||
IP_PUBLIC Iprohc_c_context *
|
||||
iprohc_udp_ip_c_create_context(Iprohc_compressor *comp,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_err iprohc_udp_ip_c_del_context(Iprohc_c_context *context);
|
||||
IP_PUBLIC Ip_err iprohc_udp_ip_c_process_feedback(Iprohc_c_context *context,
|
||||
Ip_u8 *feedback, Ip_u8 size);
|
||||
IP_PUBLIC Ip_err iprohc_udp_ip_c_compress(Iprohc_c_context *context,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC void iprohc_udp_ip_c_print_context(Iprohc_c_context *context);
|
||||
|
||||
/* Profile specific decompression functions */
|
||||
IP_PUBLIC Iprohc_d_context *
|
||||
iprohc_udp_ip_d_find_context(Iprohc_decompressor *decomp, Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Iprohc_d_context *
|
||||
iprohc_udp_ip_d_create_context(Iprohc_decompressor *decomp,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_err iprohc_udp_ip_d_del_context(Iprohc_d_context *context);
|
||||
IP_PUBLIC void iprohc_udp_ip_d_print_context(Iprohc_d_context *context);
|
||||
IP_PUBLIC Ip_err iprohc_udp_ip_d_decompress(Iprohc_d_context *context,
|
||||
Ipcom_pkt *pkt);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* #ifndef IPROHC_UDP_IP_H */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
/* iprohc_uncompressed.h - ROHC uncompressed profile 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
|
||||
--------------------
|
||||
01d,08may08,tlu Add debug functions to print a context
|
||||
01c,07may08,tlu Modify function prototype of finding compression context
|
||||
01b,01apr08,ggz Implementation of uncompressed profile
|
||||
01a,28mar08,tlu Created.
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_UNCOMPRESSED_H
|
||||
#define IPROHC_UNCOMPRESSED_H
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_tags.h>
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_list.h>
|
||||
|
||||
#include "iprohc_config.h"
|
||||
#include "iprohc_constant.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPROHC_ENABLE_REENTRANT
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* Public TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
typedef struct Iprohc_c_uncompressed_context {
|
||||
int normal_pkt_count; /* Can be used to send refresh IR packets */
|
||||
int back_trans_count;
|
||||
|
||||
/* Stat information */
|
||||
int ir_pkt_count_stat;
|
||||
int normal_pkt_count_stat;
|
||||
|
||||
} Iprohc_c_uncompressed_context;
|
||||
|
||||
typedef struct Iprohc_d_uncompressed_context {
|
||||
/* Stat information */
|
||||
int ir_pkt_count_stat;
|
||||
int normal_pkt_count_stat;
|
||||
|
||||
} Iprohc_d_uncompressed_context;
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* Profile registration/de-registration functions */
|
||||
IP_PUBLIC Ip_err iprohc_profile_uncompressed_register(void);
|
||||
IP_PUBLIC Ip_err iprohc_uncompressed_deregister(void);
|
||||
|
||||
|
||||
/* Profile specific compression functions */
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_uncompressed_c_find_context(Iprohc_compressor *comp,
|
||||
Ipcom_pkt *pkt, Iprohc_c_context **context);
|
||||
IP_PUBLIC Iprohc_c_context *
|
||||
iprohc_uncompressed_c_create_context(Iprohc_compressor *comp,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_err iprohc_uncompressed_c_del_context(Iprohc_c_context *context);
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_uncompressed_c_process_feedback(Iprohc_c_context *context,
|
||||
Ip_u8 *feedback, Ip_u8 size);
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_uncompressed_c_compress(Iprohc_c_context *context,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC void
|
||||
iprohc_uncompressed_c_print_context(Iprohc_c_context *context);
|
||||
|
||||
|
||||
/* Profile specific decompression functions */
|
||||
IP_PUBLIC Iprohc_d_context *
|
||||
iprohc_uncompressed_d_find_context(Iprohc_decompressor *decomp,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Iprohc_d_context *
|
||||
iprohc_uncompressed_d_create_context(Iprohc_decompressor *decomp,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC Ip_err iprohc_uncompressed_d_del_context(Iprohc_d_context *context);
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_uncompressed_d_decompress(Iprohc_d_context *context,
|
||||
Ipcom_pkt *pkt);
|
||||
IP_PUBLIC void
|
||||
iprohc_uncompressed_d_print_context(Iprohc_d_context *context);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* #ifndef IPROHC_UNCOMPRESSED_H */
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,904 @@
|
||||
/* iprohc_cmd_rohc.c - ROHC shell commands */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013 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
|
||||
--------------------
|
||||
01j,06aug13,j_y Clean low impact code review defects
|
||||
01i,11mar11,ggz Add TCP profile
|
||||
01h,26jan11,ggz Enable rohc show command for non vxworks ports. Defect WIND00252743
|
||||
01g,12apr10,ggz Resolve 64bit compiler warnings
|
||||
01f,05feb09,tlu Remove interface number restriction in shell cmds
|
||||
01e,27feb09,tlu Replace ROHC cmds direct function calls by ioctl
|
||||
implementation
|
||||
01d,08jul08,tlu Fix help message format
|
||||
01c,18jun08,tlu Add command to modify next context ID
|
||||
01b,20may08,tlu Pre-init the memory blocks in Vars to 0
|
||||
01a,25feb08,tlu Created.
|
||||
*/
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
This library provides shell commands for robust header compression.
|
||||
|
||||
To use this feature, include the following component: INCLUDE_IPROHC_CMD
|
||||
|
||||
|
||||
INCLUDE FILES: iprohc.h
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iprohc_config.h"
|
||||
|
||||
#define IPCOM_SHELL_HISTORY_LENGTH 10
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_shell.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_getopt.h>
|
||||
#include <ipcom_strlib.h>
|
||||
#include <ipcom_sock.h>
|
||||
|
||||
#include "iprohc.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* buf & packet size. */
|
||||
#define IPROHC_BUF_SIZE 1000
|
||||
|
||||
/* command return codes. */
|
||||
#define IPROHC_CMD_EXIT -2
|
||||
#define IPROHC_CMD_HELP -3
|
||||
|
||||
|
||||
IP_EXTERN Iprohc_data iprohc;
|
||||
|
||||
|
||||
/* This is a compile flag, turning on it will build debug message into image */
|
||||
#undef ROHC_DEBUG
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Variables - Vars
|
||||
*===========================================================================
|
||||
* ROHC shell command variable handle.
|
||||
*/
|
||||
typedef struct Vars_struct
|
||||
{
|
||||
Ip_pid_t pid;
|
||||
|
||||
int argc;
|
||||
char **argv;
|
||||
Ipcom_getopt opt;
|
||||
Ipcom_getline *gl;
|
||||
|
||||
char *buf;
|
||||
char *pkt;
|
||||
Ip_u32 test;
|
||||
|
||||
Ip_fd fd;
|
||||
char ifname[IPROHC_IF_NAME_MAX];
|
||||
Ip_u8 ifnum;
|
||||
Ip_u8 profileid;
|
||||
Ip_u16 cid;
|
||||
Ip_bool have_ifname, have_ifnum, have_profileid, have_cid;
|
||||
}
|
||||
Vars;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Command
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Command_struct
|
||||
{
|
||||
char *name;
|
||||
int (*func)(Vars *vars);
|
||||
}
|
||||
Command;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
IP_PUBLIC int iprohc_cmd_rohc(int argc, char **argv);
|
||||
|
||||
IP_STATIC int iprohc_cmd_exit(Vars *vars);
|
||||
IP_STATIC int iprohc_cmd_help(Vars *vars);
|
||||
|
||||
IP_STATIC int iprohc_cmd_rohcshow(Vars *vars);
|
||||
IP_STATIC int iprohc_cmd_ifadd(Vars *vars);
|
||||
IP_STATIC int iprohc_cmd_ifdel(Vars *vars);
|
||||
IP_STATIC int iprohc_cmd_if_profileadd(Vars *vars);
|
||||
IP_STATIC int iprohc_cmd_if_profiledel(Vars *vars);
|
||||
IP_STATIC int iprohc_cmd_comp_cidmod(Vars *vars);
|
||||
IP_STATIC int iprohc_cmd_close(Vars *vars);
|
||||
IP_STATIC int iprohc_cmd_open(Vars *vars);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IPROHC_ENABLE_REENTRANT
|
||||
IP_STATIC int iprohc_num_running;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_run_command
|
||||
*===========================================================================
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_run_command(char *name, Vars *vars)
|
||||
{
|
||||
int i;
|
||||
static const Command commands[] =
|
||||
{
|
||||
/* name, function */
|
||||
{ "exit", iprohc_cmd_exit },
|
||||
{ "quit", iprohc_cmd_exit },
|
||||
{ "help", iprohc_cmd_help },
|
||||
{ "usage", iprohc_cmd_help },
|
||||
{ "?", iprohc_cmd_help },
|
||||
{ "rohcshow", iprohc_cmd_rohcshow },
|
||||
{ "ifadd", iprohc_cmd_ifadd },
|
||||
{ "ifdel", iprohc_cmd_ifdel },
|
||||
{ "ifprofileadd", iprohc_cmd_if_profileadd },
|
||||
{ "ifprofiledel", iprohc_cmd_if_profiledel },
|
||||
{ "compcidmod", iprohc_cmd_comp_cidmod },
|
||||
{ "close", iprohc_cmd_close },
|
||||
{ "open", iprohc_cmd_open },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
for (i = 0; commands[i].name; i++)
|
||||
if (ipcom_strcmp(name, commands[i].name) == 0)
|
||||
{
|
||||
return commands[i].func(vars);
|
||||
}
|
||||
|
||||
ipcom_printf("unknown command '%s':"IP_LF, name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_exit
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_exit(Vars *vars)
|
||||
{
|
||||
(void)vars;
|
||||
return IPROHC_CMD_EXIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_help
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_help(Vars *vars)
|
||||
{
|
||||
(void)vars;
|
||||
return IPROHC_CMD_HELP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_ifadd
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_ifadd(Vars *vars)
|
||||
{
|
||||
int length;
|
||||
Ip_err retval;
|
||||
struct Ip_rohcreq rohcreq;
|
||||
|
||||
|
||||
if (vars->have_ifname == IP_FALSE)
|
||||
{
|
||||
ipcom_printf("missing modifier '-ifname'\n");
|
||||
length = (int)ipcom_strlen(vars->ifname);
|
||||
if (length >= IPROHC_IF_NAME_MAX)
|
||||
ipcom_printf("iprohc_cmd_ifadd: interface name exceeds the max size\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_memset(&rohcreq, 0, sizeof(rohcreq));
|
||||
ipcom_strcpy(rohcreq.ifname, vars->ifname);
|
||||
rohcreq.have_ifnum = vars->have_ifnum;
|
||||
rohcreq.ifnum = vars->ifnum;
|
||||
|
||||
|
||||
/* Add a ROHC monitoring interface. */
|
||||
retval = ipcom_socketioctl(vars->fd, IP_SIOCROHCADDIF, &rohcreq);
|
||||
if (retval != IPCOM_SUCCESS)
|
||||
{
|
||||
ipcom_printf("Failed to add a ROHC monitoring interface\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_printf("Added a ROHC monitoring interface\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_ifdel
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_ifdel(Vars *vars)
|
||||
{
|
||||
int length;
|
||||
Ip_err retval;
|
||||
struct Ip_rohcreq rohcreq;
|
||||
|
||||
|
||||
if (vars->have_ifname == IP_FALSE)
|
||||
{
|
||||
ipcom_printf("missing modifier '-ifname'\n");
|
||||
length = (int)ipcom_strlen(vars->ifname);
|
||||
if (length >= IPROHC_IF_NAME_MAX)
|
||||
ipcom_printf("iprohc_cmd_ifdel: interface name exceeds the max size\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_memset(&rohcreq, 0, sizeof(rohcreq));
|
||||
ipcom_strcpy(rohcreq.ifname, vars->ifname);
|
||||
rohcreq.have_ifnum = vars->have_ifnum;
|
||||
rohcreq.ifnum = vars->ifnum;
|
||||
|
||||
/* Remove a ROHC monitoring interface. */
|
||||
retval = ipcom_socketioctl(vars->fd, IP_SIOCROHCDELIF, &rohcreq);
|
||||
if (retval != IPCOM_SUCCESS)
|
||||
{
|
||||
ipcom_printf("Failed to remove a ROHC monitoring interface\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_printf("Removed a ROHC monitoring interface\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_if_profileadd
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_if_profileadd(Vars *vars)
|
||||
{
|
||||
Ip_err retval;
|
||||
int length;
|
||||
struct Ip_rohcreq rohcreq;
|
||||
|
||||
|
||||
if (vars->have_ifname == IP_FALSE)
|
||||
{
|
||||
ipcom_printf("missing modifier '-ifname'\n");
|
||||
length = (int)ipcom_strlen(vars->ifname);
|
||||
if (length >= IPROHC_IF_NAME_MAX)
|
||||
ipcom_printf("interface name %s exceeds the max size %d\n",
|
||||
vars->ifname, IPROHC_IF_NAME_MAX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vars->have_profileid == IP_FALSE)
|
||||
{
|
||||
ipcom_printf("missing modifier '-profileid'\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_memset(&rohcreq, 0, sizeof(rohcreq));
|
||||
ipcom_strcpy(rohcreq.ifname, vars->ifname);
|
||||
rohcreq.profileid = vars->profileid;
|
||||
|
||||
retval = ipcom_socketioctl(vars->fd, IP_SIOCROHCADDIFPROFILE, &rohcreq);
|
||||
if (retval != IPCOM_SUCCESS)
|
||||
{
|
||||
ipcom_printf("Failed to add a ROHC profile %d to the interface %s\n",
|
||||
vars->profileid, vars->ifname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_printf("Added a ROHC profile to the interface\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_if_profiledel
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_if_profiledel(Vars *vars)
|
||||
{
|
||||
Ip_err retval;
|
||||
int length;
|
||||
struct Ip_rohcreq rohcreq;
|
||||
|
||||
|
||||
if (vars->have_ifname == IP_FALSE)
|
||||
{
|
||||
ipcom_printf("missing modifier '-ifname'\n");
|
||||
length = (int)ipcom_strlen(vars->ifname);
|
||||
if (length >= IPROHC_IF_NAME_MAX)
|
||||
ipcom_printf("interface name %s exceeds the max size %d\n",
|
||||
vars->ifname, IPROHC_IF_NAME_MAX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vars->have_profileid == IP_FALSE)
|
||||
{
|
||||
ipcom_printf("missing modifier '-profileid'\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_memset(&rohcreq, 0, sizeof(rohcreq));
|
||||
ipcom_strcpy(rohcreq.ifname, vars->ifname);
|
||||
rohcreq.profileid = vars->profileid;
|
||||
|
||||
retval = ipcom_socketioctl(vars->fd, IP_SIOCROHCDELIFPROFILE, &rohcreq);
|
||||
if (retval != IPCOM_SUCCESS)
|
||||
{
|
||||
ipcom_printf("Failed to remove a ROHC profile %d from the interface %s\n",
|
||||
vars->profileid, vars->ifname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_printf("Removed a ROHC profile from the interface\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_comp_cidmod
|
||||
*===========================================================================
|
||||
* Description: This modifies the next_to_be_used CID in a compressor
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_comp_cidmod(Vars *vars)
|
||||
{
|
||||
Ip_err retval;
|
||||
int length;
|
||||
struct Ip_rohcreq rohcreq;
|
||||
|
||||
|
||||
if (vars->have_ifname == IP_FALSE)
|
||||
{
|
||||
ipcom_printf("missing modifier '-ifname'\n");
|
||||
length = (int)ipcom_strlen(vars->ifname);
|
||||
if (length >= IPROHC_IF_NAME_MAX)
|
||||
ipcom_printf("interface name %s exceeds the max size %d\n",
|
||||
vars->ifname, IPROHC_IF_NAME_MAX);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vars->have_profileid == IP_FALSE)
|
||||
{
|
||||
ipcom_printf("missing modifier '-profileid'\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vars->have_cid == IP_FALSE)
|
||||
{
|
||||
ipcom_printf("missing modifier '-cid'\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_memset(&rohcreq, 0, sizeof(rohcreq));
|
||||
ipcom_strcpy(rohcreq.ifname, vars->ifname);
|
||||
rohcreq.profileid = vars->profileid;
|
||||
rohcreq.cid = vars->cid;
|
||||
|
||||
retval = ipcom_socketioctl(vars->fd, IP_SIOCSROHCCID, &rohcreq);
|
||||
if (retval != IPCOM_SUCCESS)
|
||||
{
|
||||
ipcom_printf("Failed to modify next-to-be-allocated CID %d",
|
||||
vars->cid);
|
||||
ipcom_printf(" for profile %d on the interface %s\n",
|
||||
vars->profileid, vars->ifname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ipcom_printf("Modifed the next to be allocated CID\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_rohcshow
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_rohcshow(Vars *vars)
|
||||
{
|
||||
(void)vars;
|
||||
|
||||
iprohc_show_config();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_close
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_close(Vars *vars)
|
||||
{
|
||||
Ip_err ret = IPCOM_SUCCESS;
|
||||
struct Ip_rohcreq rohcreq;
|
||||
(void)vars;
|
||||
|
||||
ipcom_memset(&rohcreq, 0, sizeof(rohcreq));
|
||||
rohcreq.opened = IP_FALSE;
|
||||
|
||||
|
||||
ret = ipcom_socketioctl(vars->fd, IP_SIOCSROHCSTATUS, &rohcreq);
|
||||
if (ret != IPCOM_SUCCESS)
|
||||
{
|
||||
ipcom_printf("Failed to close ROHC\n");
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
ipcom_printf("ROHC is closed\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cmd_open
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
iprohc_cmd_open(Vars *vars)
|
||||
{
|
||||
Ip_err ret = IPCOM_SUCCESS;
|
||||
struct Ip_rohcreq rohcreq;
|
||||
(void)vars;
|
||||
|
||||
ipcom_memset(&rohcreq, 0, sizeof(rohcreq));
|
||||
rohcreq.opened = IP_TRUE;
|
||||
|
||||
ret = ipcom_socketioctl(vars->fd, IP_SIOCSROHCSTATUS, &rohcreq);
|
||||
if (ret != IPCOM_SUCCESS)
|
||||
{
|
||||
ipcom_printf("Failed to open ROHC, ret %d\n", ret);
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
ipcom_printf("ROHC is opened\n");
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_setup
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*/
|
||||
IP_STATIC Ip_err
|
||||
iprohc_setup(Vars *vars)
|
||||
{
|
||||
#ifndef IPROHC_ENABLE_REENTRANT
|
||||
iprohc_num_running++;
|
||||
#endif
|
||||
|
||||
/* Set default config. */
|
||||
ipcom_memset(vars, 0, sizeof(Vars));
|
||||
vars->pid = ipcom_getpid();
|
||||
vars->fd = IP_INVALID_SOCKET;
|
||||
|
||||
vars->buf = ipcom_malloc(IPROHC_BUF_SIZE);
|
||||
if (vars->buf == IP_NULL)
|
||||
{
|
||||
ipcom_printf("out of buf memory.\n");
|
||||
goto badout;
|
||||
}
|
||||
ipcom_memset(vars->buf, 0, IPROHC_BUF_SIZE);
|
||||
|
||||
vars->pkt = ipcom_malloc(IPROHC_MAX_PKT_SIZE);
|
||||
if (vars->pkt == IP_NULL)
|
||||
{
|
||||
ipcom_printf("out of pkt memory.\n");
|
||||
goto badout;
|
||||
}
|
||||
ipcom_memset(vars->pkt, 0, IPROHC_MAX_PKT_SIZE);
|
||||
|
||||
vars->gl = ipcom_getline_init(IPCOM_SHELL_HISTORY_LENGTH);
|
||||
if (vars->gl == IP_NULL)
|
||||
{
|
||||
ipcom_printf("out of readline memory.\n");
|
||||
goto badout;
|
||||
}
|
||||
|
||||
#ifdef IPCOM_USE_INET
|
||||
vars->fd = ipcom_socket(IP_AF_INET, IP_SOCK_DGRAM, 0);
|
||||
#else
|
||||
vars->fd = ipcom_socket(IP_AF_INET6, IP_SOCK_DGRAM, 0);
|
||||
#endif
|
||||
if (vars->fd == IP_SOCKERR)
|
||||
{
|
||||
ipcom_printf("rohc: ipcom_socket() failed: %s"IP_LF, ipcom_strerror(ipcom_errno));
|
||||
goto badout;
|
||||
}
|
||||
|
||||
|
||||
return IPCOM_SUCCESS;
|
||||
|
||||
badout:
|
||||
return IPCOM_ERR_FAILED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_cleanup
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*/
|
||||
IP_STATIC void
|
||||
iprohc_cleanup(Vars *vars)
|
||||
{
|
||||
#ifndef IPROHC_ENABLE_REENTRANT
|
||||
iprohc_num_running--;
|
||||
#endif
|
||||
|
||||
if (vars->buf != IP_NULL)
|
||||
ipcom_free(vars->buf);
|
||||
if (vars->pkt != IP_NULL)
|
||||
ipcom_free(vars->pkt);
|
||||
if (vars->argv)
|
||||
ipcom_free(vars->argv);
|
||||
if (vars->gl)
|
||||
ipcom_getline_exit(vars->gl);
|
||||
if (vars->fd != IP_INVALID_SOCKET)
|
||||
(void)ipcom_socketclose(vars->fd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*******************************************************************
|
||||
*
|
||||
* iprohc_cmd_rohc - ROHC shell commands
|
||||
*
|
||||
* This routine provides shell commands for ROHC.
|
||||
*
|
||||
* Type "rohc" at IPCOM shell to get into ROHC shell.
|
||||
* The shell prompt will become "rohc> ". Type "help" at ROHC
|
||||
* shell to get the help information on how to use ROHC shell
|
||||
* commands.
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* \cs
|
||||
* -> cmd rohc
|
||||
* rohc> help
|
||||
* \ce
|
||||
*
|
||||
* Parameters: N/A
|
||||
*
|
||||
*
|
||||
* RETURNS: N/A
|
||||
*
|
||||
* ERRNO: N/A
|
||||
*
|
||||
*/
|
||||
|
||||
IP_PUBLIC int iprohc_cmd_rohc
|
||||
(
|
||||
int argc,
|
||||
char **argv
|
||||
)
|
||||
{
|
||||
Vars vars;
|
||||
int c;
|
||||
Ip_err retval;
|
||||
|
||||
static struct Ip_option long_options[] =
|
||||
{
|
||||
{"ifname", 1, 0, 0},
|
||||
{"ifnum", 1, 0, 0},
|
||||
{"profileid", 1, 0, 0},
|
||||
{"cid", 1, 0, 0},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
|
||||
#ifndef IPROHC_ENABLE_REENTRANT
|
||||
if (iprohc_num_running != 0)
|
||||
{
|
||||
ipcom_printf("IPROHC not compiled to be reentrant and shell command already in use.\n");
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Init vars structure. */
|
||||
if (iprohc_setup(&vars) != IPCOM_SUCCESS)
|
||||
goto leave;
|
||||
|
||||
/* Command loop. */
|
||||
for (;;)
|
||||
{
|
||||
vars.have_ifname = vars.have_ifnum = 0;
|
||||
vars.have_profileid = vars.have_cid = 0;
|
||||
|
||||
/* Print prompt. */
|
||||
(void)ipcom_fflush(ip_stdout);
|
||||
ipcom_printf("rohc> ");
|
||||
(void)ipcom_fflush(ip_stdout);
|
||||
|
||||
/* Get command line. */
|
||||
if (ipcom_getline(IP_INVALID_SOCKET, vars.buf, IPROHC_BUF_SIZE, IP_TRUE, vars.gl, 11 /* promptlen */) < 0)
|
||||
{
|
||||
ipcom_printf("end of line, aborting.\n");
|
||||
goto leave;
|
||||
}
|
||||
|
||||
if (!*vars.buf)
|
||||
continue;
|
||||
|
||||
retval = ipcom_parse_argstr(vars.buf, &vars.argc, &vars.argv);
|
||||
if (retval != IPCOM_SUCCESS)
|
||||
{
|
||||
ipcom_printf("argument error.\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Set default config. */
|
||||
|
||||
|
||||
/* ipcom_getopt() loop. */
|
||||
ipcom_getopt_clear_r(&vars.opt);
|
||||
vars.opt.long_only = 1;
|
||||
vars.opt.long_options = long_options;
|
||||
while((c = ipcom_getopt_r(vars.argc, vars.argv, "t", &vars.opt)) != -1)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 0:
|
||||
switch(vars.opt.long_index)
|
||||
{
|
||||
case 0: /* ifname */
|
||||
ipcom_strncpy(vars.ifname, vars.opt.optarg,IPROHC_IF_NAME_MAX);
|
||||
vars.ifname[IPROHC_IF_NAME_MAX-1] = '\0';
|
||||
vars.have_ifname = IP_TRUE;
|
||||
break;
|
||||
case 1: /* ifnum */
|
||||
vars.ifnum = (Ip_u8)ipcom_atoi(vars.opt.optarg);
|
||||
vars.have_ifnum = IP_TRUE;
|
||||
break;
|
||||
case 2: /* profileid */
|
||||
if (*vars.opt.optarg < '0' || *vars.opt.optarg > '6')
|
||||
{
|
||||
ipcom_printf("profile id must be a valid ID (0-6)."IP_LF);
|
||||
goto usage;
|
||||
}
|
||||
vars.profileid = (Ip_u8)ipcom_atoi(vars.opt.optarg);
|
||||
vars.have_profileid = IP_TRUE;
|
||||
break;
|
||||
case 3: /* CID */
|
||||
if (*vars.opt.optarg < '1' )
|
||||
{
|
||||
ipcom_printf("CID must be a valid ID"IP_LF);
|
||||
ipcom_printf(" For small CID: [1, 15]"IP_LF);
|
||||
ipcom_printf(" For large CID: [1, 16383]"IP_LF);
|
||||
goto usage;
|
||||
}
|
||||
vars.cid = (Ip_u16)ipcom_atoi(vars.opt.optarg);
|
||||
vars.have_cid = IP_TRUE;
|
||||
break;
|
||||
default:
|
||||
ipcom_printf ("unknown option %s", long_options[vars.opt.long_index].name);
|
||||
if (vars.opt.optarg)
|
||||
ipcom_printf(" with arg %s", vars.opt.optarg);
|
||||
ipcom_printf(IP_LF);
|
||||
goto usage;
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
vars.test = 1;
|
||||
ipcom_printf("using testmode"IP_LF);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****** Run the command. ******/
|
||||
/* c = -1 or 0 continue;
|
||||
c = <count> to receive stuff>
|
||||
*/
|
||||
c = iprohc_run_command(vars.argv[0], &vars);
|
||||
if (c == IPROHC_CMD_EXIT)
|
||||
goto leave;
|
||||
else if (c == IPROHC_CMD_HELP)
|
||||
goto usage;
|
||||
|
||||
/* Next command... */
|
||||
continue;
|
||||
|
||||
usage:
|
||||
ipcom_printf("IPROHC robust header compression command, version 1.0"IP_LF
|
||||
"Copyright (c) 2008, Wind River <www.windriver.com>"IP_LF
|
||||
"usage: <command> [modifier(s)...]"IP_LF
|
||||
"\tCommands:"IP_LF);
|
||||
ipcom_printf("\t exit\t\t\t exit ROHC command"IP_LF
|
||||
"\t help\t\t\t help usage"IP_LF
|
||||
"\t open\t\t\t open ROHC"IP_LF
|
||||
"\t close\t\t\t close ROHC"IP_LF
|
||||
"\t rohcshow\t\t show ROHC configuration"IP_LF
|
||||
"\t ifadd\t\t\t add a monitoring interface"IP_LF
|
||||
"\t ifdel\t\t\t remove a monitoring interface"IP_LF
|
||||
"\t ifprofileadd\t\t add a profile to an inteface"IP_LF
|
||||
"\t\t\t\t (full interface name with number, e.g. fei1)"IP_LF
|
||||
"\t ifprofiledel\t\t remove a profile from an interface"IP_LF
|
||||
"\t\t\t\t (full interface name with number, e.g. fei1)"IP_LF
|
||||
"\t compcidmod\t\t modify the next-to-be-used CID for"IP_LF
|
||||
"\t\t\t\t a profile on an inteface (full interface"IP_LF
|
||||
"\t\t\t\t name with number, e.g. fei1)"IP_LF
|
||||
"\t\t\t\t For small CID: [1, 15]"IP_LF
|
||||
"\t\t\t\t For large CID: [1, 16383]"IP_LF);
|
||||
ipcom_printf("\tPossible modifiers:"IP_LF
|
||||
"\t -ifname <name>\t\t interface name"IP_LF
|
||||
"\t -ifnum <num>\t\t interface number"IP_LF
|
||||
"\t -profileid <id>\t profile ID (0,4)"IP_LF
|
||||
"\t -cid <id>\t\t context ID"IP_LF);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
leave:
|
||||
(void)ipcom_fflush(ip_stdout);
|
||||
iprohc_cleanup(&vars);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,659 @@
|
||||
/* iprohc_decomp.c - ROHC decompressor utility routines */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2013 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
|
||||
--------------------
|
||||
01f,08aug13,j_y Clean low impact code review defects
|
||||
01e,10feb11,ggz Resolve a lock issue for non vxworks port. Defet WIND00254463
|
||||
01d,11aug08,tlu Add destination address to context show routine
|
||||
01c,22may08,tlu Free the decompression context at the deletion
|
||||
01b,12may08,tlu Add debugging utitilies
|
||||
01a,07mar08,tlu Created.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iprohc_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
|
||||
/* ipcom */
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_sysvar.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_list.h>
|
||||
#include <ipcom_time.h>
|
||||
#include <ipcom_inet.h>
|
||||
|
||||
|
||||
/* iprohc */
|
||||
#include "iprohc.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_EXTERN Iprohc_data iprohc;
|
||||
|
||||
/* This is a compile flag, turning on it will build debug message into image */
|
||||
#undef ROHC_DEBUG
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL Data
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_alloc_decompressor
|
||||
*===========================================================================
|
||||
* Description: Allocate a ROHC decompressor structure
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Iprohc_decompressor *
|
||||
iprohc_alloc_decompressor(struct Iprohc_interface *interface)
|
||||
{
|
||||
Iprohc_decompressor *decomp;
|
||||
|
||||
/* Allocate and pre-init decompressor structure */
|
||||
decomp = (Iprohc_decompressor *)ipcom_malloc(sizeof(Iprohc_decompressor));
|
||||
if(decomp == IP_NULL)
|
||||
return IP_NULL;
|
||||
ipcom_memset(decomp, 0, sizeof(Iprohc_decompressor));
|
||||
|
||||
decomp->interface = interface;
|
||||
|
||||
/* init list */
|
||||
ipcom_list_init(&(decomp->context_head));
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
(void)ipcom_mutex_create(&decomp->code_mutex);
|
||||
#endif
|
||||
|
||||
return decomp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_del_decompressor
|
||||
*===========================================================================
|
||||
* Description: Free a ROHC decompressor structure
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_del_decompressor(Iprohc_decompressor *decompressor)
|
||||
{
|
||||
Ip_err retval = IPCOM_SUCCESS;
|
||||
Iprohc_d_context *context, *ncontext;
|
||||
|
||||
|
||||
/* just return IPCOM_SUCCESS for a NULL de-compressor */
|
||||
if (decompressor == IP_NULL) return retval;
|
||||
|
||||
IPROHC_DECOMP_LOCK(decompressor);
|
||||
|
||||
for (context = IPCOM_LIST_FIRST(&decompressor->context_head);
|
||||
context != IP_NULL;
|
||||
context = ncontext)
|
||||
{
|
||||
ncontext = IPCOM_LIST_NEXT(&context->context_list);
|
||||
|
||||
decompressor->context_num--;
|
||||
|
||||
/* free the context */
|
||||
iprohc.profiles[context->profileid].d_del_context(context);
|
||||
}
|
||||
IPROHC_DECOMP_UNLOCK(decompressor);
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
(void)ipcom_mutex_delete(&decompressor->code_mutex);
|
||||
#endif
|
||||
|
||||
/* free the decompressor */
|
||||
ipcom_free(decompressor);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_d_del_profile_contexts
|
||||
*===========================================================================
|
||||
* Description: Free contexts associated with a profile
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_d_del_profile_contexts(Iprohc_decompressor *decompressor, Ip_u8 profileid)
|
||||
{
|
||||
Ip_err retval = IPCOM_SUCCESS;
|
||||
Iprohc_d_context *context, *ncontext;
|
||||
|
||||
|
||||
/* just return IPCOM_SUCCESS for a NULL de-compressor */
|
||||
if (decompressor == IP_NULL) return retval;
|
||||
|
||||
IPROHC_DECOMP_LOCK(decompressor);
|
||||
|
||||
for (context = IPCOM_LIST_FIRST(&decompressor->context_head);
|
||||
context != IP_NULL;
|
||||
context = ncontext)
|
||||
{
|
||||
ncontext = IPCOM_LIST_NEXT(&context->context_list);
|
||||
if (context->profileid != profileid) continue;
|
||||
decompressor->context_num--;
|
||||
|
||||
/* free the context */
|
||||
iprohc.profiles[context->profileid].d_del_context(context);
|
||||
}
|
||||
IPROHC_DECOMP_UNLOCK(decompressor);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_d_context_common_create
|
||||
*===========================================================================
|
||||
* Description: Allocate a ROHC decompression context common structure
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Iprohc_d_context *
|
||||
iprohc_d_context_common_create(Ip_u16 cid)
|
||||
{
|
||||
Iprohc_d_context *d_context;
|
||||
|
||||
/* Allocate and pre-init decompression context structure */
|
||||
d_context = (Iprohc_d_context *)ipcom_malloc(sizeof(Iprohc_d_context));
|
||||
if(d_context == IP_NULL)
|
||||
return IP_NULL;
|
||||
ipcom_memset(d_context, 0, sizeof(Iprohc_d_context));
|
||||
|
||||
/* Initialize the context fields */
|
||||
d_context->cid = cid;
|
||||
d_context->state = ROHC_DECOMP_STATE_NO;
|
||||
d_context->mode = ROHC_MODE_U;
|
||||
d_context->trans_mode = ROHC_MODE_U;
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
(void)ipcom_mutex_create(&d_context->code_mutex);
|
||||
#endif
|
||||
|
||||
return d_context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_d_print_a_context
|
||||
*===========================================================================
|
||||
* Description: For debugging -- print out a decompression context
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC void
|
||||
iprohc_d_print_a_context(Iprohc_d_context *context)
|
||||
{
|
||||
Ip_u8 profileid;
|
||||
char buf[48], dstbuf[48];
|
||||
|
||||
profileid = context->profileid;
|
||||
|
||||
ipcom_printf(" Decompression Context (%x):\n", context);
|
||||
ipcom_printf(" cid: %d\n", context->cid);
|
||||
ipcom_printf(" state: %s\n",
|
||||
iprohc_decomp_state(context->state));
|
||||
ipcom_printf(" mode: %s\n",
|
||||
iprohc_context_mode(context->mode));
|
||||
ipcom_printf(" trans: %s\n",
|
||||
iprohc_decomp_trans(context->trans));
|
||||
ipcom_printf(" trans_mode: %s\n",
|
||||
iprohc_context_mode(context->trans_mode));
|
||||
ipcom_printf(" first_ir: %d\n", context->first_ir);
|
||||
ipcom_printf(" num_decompressed: %d\n",
|
||||
context->num_decompressed);
|
||||
ipcom_printf(" num_failed: %d\n", context->num_failed);
|
||||
ipcom_printf(" crc: %d\n", context->crc);
|
||||
ipcom_printf(" stream type: %s\n",
|
||||
(context->stream_type==ROHC_PKT_IPV4)?"IPv4":"IPv6");
|
||||
|
||||
if (context->stream_type == ROHC_PKT_IPV4)
|
||||
#ifdef IPCOM_USE_INET
|
||||
{
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &context->src.addr4.addr32, buf,
|
||||
sizeof(buf));
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &context->dst.addr4.addr32, dstbuf,
|
||||
sizeof(dstbuf));
|
||||
}
|
||||
#ifdef IPCOM_USE_INET6
|
||||
else
|
||||
#endif
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
#ifdef IPCOM_USE_INET6
|
||||
{
|
||||
(void)ipcom_inet_ntop(IP_AF_INET6, &context->src.addr6, buf,
|
||||
sizeof(buf));
|
||||
(void)ipcom_inet_ntop(IP_AF_INET6, &context->dst.addr6, dstbuf,
|
||||
sizeof(dstbuf));
|
||||
}
|
||||
#endif /* #ifdef IPCOM_USE_INET6 */
|
||||
|
||||
ipcom_printf(" src address: %s\n", buf);
|
||||
ipcom_printf(" dst address: %s\n", dstbuf);
|
||||
|
||||
|
||||
/* Print profile specific compression context */
|
||||
iprohc.profiles[profileid].d_print_context(context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_d_print_context
|
||||
*===========================================================================
|
||||
* Description: Print out all the contexts in the decompressor
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_d_print_context(Iprohc_decompressor *decompressor, Ip_u8 profile)
|
||||
{
|
||||
Ip_err retval = IPCOM_SUCCESS;
|
||||
Iprohc_d_context *context, *ncontext;
|
||||
|
||||
if (decompressor == IP_NULL)
|
||||
return retval;
|
||||
|
||||
if (decompressor->context_num == 0)
|
||||
{
|
||||
ipcom_printf(" Decompression Context: None\n");
|
||||
return retval;
|
||||
}
|
||||
|
||||
for (context = IPCOM_LIST_FIRST(&decompressor->context_head);
|
||||
context != IP_NULL;
|
||||
context = ncontext)
|
||||
{
|
||||
ncontext = IPCOM_LIST_NEXT(&context->context_list);
|
||||
if (context->profileid != profile) continue;
|
||||
iprohc_d_print_a_context(context);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_d_context_common_del
|
||||
*===========================================================================
|
||||
* Description: Free a ROHC decompression context common structure
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_d_context_common_del(Iprohc_d_context *d_context)
|
||||
{
|
||||
|
||||
#ifdef IPROHC_ENABLE_REENTRANT
|
||||
(void)ipcom_mutex_delete(&d_context->code_mutex);
|
||||
#endif
|
||||
|
||||
ipcom_free(d_context);
|
||||
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_decomp_state
|
||||
*===========================================================================
|
||||
* Description: Debugging utility to print a decompression context state
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC char * iprohc_decomp_state(Iprohc_decomp_state state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case ROHC_DECOMP_STATE_NO:
|
||||
ipcom_strcpy(iprohc.buf, "No Context");
|
||||
break;
|
||||
case ROHC_DECOMP_STATE_STATIC:
|
||||
ipcom_strcpy(iprohc.buf, "Static Context");
|
||||
break;
|
||||
case ROHC_DECOMP_STATE_FULL:
|
||||
ipcom_strcpy(iprohc.buf, "Full Context");
|
||||
break;
|
||||
default:
|
||||
ipcom_strcpy(iprohc.buf, "Illegal");
|
||||
break;
|
||||
}
|
||||
|
||||
return iprohc.buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_decomp_trans
|
||||
*===========================================================================
|
||||
* Description: Debugging utility to print a decompression context mode
|
||||
* transition state
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC char * iprohc_decomp_trans(Iprohc_decomp_trans trans)
|
||||
{
|
||||
switch (trans)
|
||||
{
|
||||
case ROHC_DECOMP_TRANS_DONE:
|
||||
ipcom_strcpy(iprohc.buf, "Done");
|
||||
break;
|
||||
case ROHC_DECOMP_TRANS_INITIATED:
|
||||
ipcom_strcpy(iprohc.buf, "Initiated");
|
||||
break;
|
||||
case ROHC_DECOMP_TRANS_PENDING:
|
||||
ipcom_strcpy(iprohc.buf, "Pending");
|
||||
break;
|
||||
default:
|
||||
ipcom_strcpy(iprohc.buf, "Illegal");
|
||||
break;
|
||||
}
|
||||
|
||||
return iprohc.buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef IP_PORT_VXWORKS /* for Linux recursive semaphore */
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_decomp_lck
|
||||
*===========================================================================
|
||||
* Description: This function provides a recursive semaphore lock to an ROHC
|
||||
* decompressor.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
|
||||
IP_PUBLIC void
|
||||
iprohc_decomp_lck(Iprohc_decompressor *decomp)
|
||||
{
|
||||
Ip_pid_t cpid = ipcom_getpid();
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Calling iprohc_decomp_lck: pid %d, counter %d, cpid %d\n",
|
||||
decomp->pid, decomp->s_counter, cpid);
|
||||
#endif
|
||||
|
||||
if (decomp->pid == 0)
|
||||
{
|
||||
/* No one has semaphore, take it */
|
||||
decomp->pid = cpid;
|
||||
decomp->s_counter = 1;
|
||||
ipcom_mutex_lock(decomp->code_mutex);
|
||||
}
|
||||
else if (decomp->pid != cpid)
|
||||
{
|
||||
/* block a different process/task */
|
||||
ipcom_mutex_lock(decomp->code_mutex);
|
||||
decomp->pid = cpid;
|
||||
decomp->s_counter++;
|
||||
}
|
||||
else
|
||||
/* the semaphore is taken by the same process, increase the counter */
|
||||
decomp->s_counter ++;
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_decomp_lck: pid %d, counter %d, cpid %d\n",
|
||||
decomp->pid, decomp->s_counter, cpid);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_decomp_unlck
|
||||
*===========================================================================
|
||||
* Description: This function provides a recursive semaphore unlock to an
|
||||
* ROHC decompressor.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC void
|
||||
iprohc_decomp_unlck(Iprohc_decompressor *decomp)
|
||||
{
|
||||
Ip_pid_t cpid = ipcom_getpid();
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Calling iprohc_decomp_unlck: pid %d, counter %d, cpid %d\n",
|
||||
decomp->pid, decomp->s_counter, cpid);
|
||||
#endif
|
||||
|
||||
if (decomp->pid != cpid)
|
||||
{
|
||||
IPCOM_LOG0(ERR, "iprohc_decomp_unlck: released by a different process");
|
||||
return;
|
||||
}
|
||||
|
||||
/* decrease the counter */
|
||||
decomp->s_counter --;
|
||||
|
||||
if (decomp->s_counter == 0)
|
||||
{
|
||||
/* clear the semaphore PID */
|
||||
decomp->pid = 0;
|
||||
|
||||
/* release the semaphore */
|
||||
ipcom_mutex_unlock(decomp->code_mutex);
|
||||
}
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_decomp_unlck: pid %d, counter %d, cpid %d\n",
|
||||
decomp->pid, decomp->s_counter, cpid);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_d_context_lck
|
||||
*===========================================================================
|
||||
* Description: This function provides a recursive semaphore lock to an ROHC
|
||||
* decompression context.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
|
||||
IP_PUBLIC void
|
||||
iprohc_d_context_lck(Iprohc_d_context *context)
|
||||
{
|
||||
Ip_pid_t cpid = ipcom_getpid();
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Calling iprohc_d_context_lck: pid %d, counter %d, cpid %d\n",
|
||||
context->pid, context->s_counter, cpid);
|
||||
#endif
|
||||
|
||||
if (context->pid == 0)
|
||||
{
|
||||
/* No one has semaphore, take it */
|
||||
context->pid = cpid;
|
||||
context->s_counter = 1;
|
||||
ipcom_mutex_lock(context->code_mutex);
|
||||
}
|
||||
else if (context->pid != cpid)
|
||||
{
|
||||
/* block a different process/task */
|
||||
ipcom_mutex_lock(context->code_mutex);
|
||||
context->pid = cpid;
|
||||
context->s_counter++;
|
||||
}
|
||||
else
|
||||
/* the semaphore is taken by the same process, increase the counter */
|
||||
context->s_counter ++;
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_d_context_lck: pid %d, counter %d, cpid %d\n",
|
||||
context->pid, context->s_counter, cpid);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_d_context_unlck
|
||||
*===========================================================================
|
||||
* Description: This function provides a recursive semaphore unlock to an
|
||||
* ROHC decompression context.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC void
|
||||
iprohc_d_context_unlck(Iprohc_d_context *context)
|
||||
{
|
||||
Ip_pid_t cpid = ipcom_getpid();
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_d_context_unlck: pid %d, counter %d, cpid %d\n",
|
||||
context->pid, context->s_counter, cpid);
|
||||
#endif
|
||||
|
||||
if (context->pid != cpid)
|
||||
{
|
||||
IPCOM_LOG0(ERR,"iprohc_d_context_unlck: released by different process");
|
||||
return;
|
||||
}
|
||||
|
||||
/* decrease the counter */
|
||||
context->s_counter --;
|
||||
|
||||
if (context->s_counter == 0)
|
||||
{
|
||||
/* clear the semaphore PID */
|
||||
context->pid = 0;
|
||||
|
||||
/* release the semaphore */
|
||||
ipcom_mutex_unlock(context->code_mutex);
|
||||
}
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_d_context_unlck: pid %d, counter %d, cpid %d\n",
|
||||
context->pid, context->s_counter, cpid);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* !IP_PORT_VXWORKS */
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,742 @@
|
||||
/* iprohc_feedback.c - ROHC feedback handling 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
|
||||
--------------------
|
||||
01f,16oct12,ggz Fix warnings. Defect WIND00382425
|
||||
01e,20oct11,ggz Fix for defect WIND00312450
|
||||
01d,08dec10,ggz Add 64 bit support
|
||||
01c,12aug08,tlu Add source address to feedback handling
|
||||
01b,14may08,tlu Add the pkt type and destination address to feedback
|
||||
creation and preappend functions
|
||||
01a,13mar08,tlu Created.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iprohc_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
|
||||
/* ipcom */
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_sysvar.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_list.h>
|
||||
#include <ipcom_time.h>
|
||||
#include <ipcom_inet.h>
|
||||
|
||||
|
||||
/* iprohc */
|
||||
#include "iprohc.h"
|
||||
#include "iprohc_parser.h"
|
||||
#include "iprohc_format.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_EXTERN Iprohc_data iprohc;
|
||||
|
||||
/* This is a compile flag, turning on it will build debug message into image */
|
||||
#undef ROHC_DEBUG
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* 5.2.2. ROHC feedback format
|
||||
*
|
||||
* Feedback consists of one or more concatenated feedback elements,
|
||||
* where each feedback element has the following format:
|
||||
*
|
||||
* ---------------------------
|
||||
* | 1 1 1 1 0 | Code | feedback type octet
|
||||
* ---------------------------
|
||||
* : Size : if Code = 0
|
||||
* ---------------------------
|
||||
* / feedback data / variable length
|
||||
* ---------------------------
|
||||
*
|
||||
* The feedback data has the following structure:
|
||||
*
|
||||
* ---------------------------
|
||||
* : Add-CID octet : if for small CIDs and (CID != 0)
|
||||
* ---------------------------
|
||||
* : :
|
||||
* / large CID / 1 - 2 octects for large CIDs
|
||||
* : (4.5.6 encoding) :
|
||||
* ---------------------------
|
||||
* / feedback /
|
||||
* ---------------------------
|
||||
*
|
||||
* The feedback field can have either of the following two formats:
|
||||
*
|
||||
* FEEDBACK-1
|
||||
*
|
||||
* ----------------------------
|
||||
* | profile specific info | 1 octet
|
||||
* ----------------------------
|
||||
*
|
||||
* FEEDBACK-2
|
||||
*
|
||||
* ----------------------------
|
||||
* |Acktype| |
|
||||
* --------- profile specific / at least 2 octets
|
||||
* / info |
|
||||
* ----------------------------
|
||||
*
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC Iprohc_feedback * iprohc_create_feedback(Iprohc_d_context *d_context);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL Data
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_create_feedback
|
||||
*===========================================================================
|
||||
* Description: Generate a feedback element without feedback field for the
|
||||
* specified interface and profile.
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
|
||||
IP_STATIC Iprohc_feedback *
|
||||
iprohc_create_feedback(Iprohc_d_context *d_context)
|
||||
{
|
||||
Iprohc_feedback *feedback = IP_NULL;
|
||||
Ip_u8 cid_size = 0;
|
||||
Ip_u16 cid = 0;
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_create_feedback\n");
|
||||
#endif /* ROHC_DEBUG */
|
||||
|
||||
feedback = (Iprohc_feedback *)ipcom_malloc(sizeof(Iprohc_feedback));
|
||||
|
||||
if (feedback == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(ERR, "iprohc_create_feedback: out of memory (%d bytes)",
|
||||
sizeof(Iprohc_feedback));
|
||||
return feedback;
|
||||
}
|
||||
|
||||
/* Pre-init feedback data */
|
||||
ipcom_memset(feedback, 0, sizeof(Iprohc_feedback));
|
||||
|
||||
/* Get CID from the context */
|
||||
cid = d_context->cid;
|
||||
|
||||
/* Init packet type and dst adress in feedback structure from d_context */
|
||||
feedback->packet_type = d_context->stream_type;
|
||||
#ifdef IPCOM_USE_INET
|
||||
if (feedback->packet_type == ROHC_PKT_IPV4)
|
||||
{
|
||||
feedback->dst.addr4 = d_context->src.addr4;
|
||||
feedback->src.addr4 = d_context->dst.addr4;
|
||||
}
|
||||
#ifdef IPCOM_USE_INET6
|
||||
else
|
||||
#endif
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
#ifdef IPCOM_USE_INET6
|
||||
if (feedback->packet_type == ROHC_PKT_IPV6)
|
||||
{
|
||||
feedback->dst.addr6 = d_context->src.addr6;
|
||||
feedback->src.addr6 = d_context->dst.addr6;
|
||||
}
|
||||
#endif /* #ifdef IPCOM_USE_INET6 */
|
||||
|
||||
/* Format the feedback type octet with Code = 0: 11110 Code */
|
||||
feedback->data[0] = 0xF0;
|
||||
|
||||
/* Format the feedback data: CID portion */
|
||||
if (iprohc.large_cid)
|
||||
{
|
||||
int pointer = 1;
|
||||
|
||||
/*
|
||||
* Encode according to RFC 3095, section 4.5.6.
|
||||
* RFC 3095, section 5.2.2: If the first bit is 0, the CID uses
|
||||
* one octet. If the first bit is 1, the CID uses two octets.
|
||||
*/
|
||||
IPROHC_ENCODE_LARGE_CID(feedback->data, pointer, cid, cid_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Small CID: format Add-CID octet: 1110 CID */
|
||||
if (cid != 0)
|
||||
{
|
||||
feedback->data[1] = (Ip_u8)(feedback->data[1] | (cid & 0x0F));
|
||||
feedback->data[1] |= 0xE0;
|
||||
cid_size = 1;
|
||||
}
|
||||
else
|
||||
cid_size = 0;
|
||||
}
|
||||
|
||||
/* Set Code = cid_size */
|
||||
feedback->data[0] |= cid_size;
|
||||
|
||||
/* Set the size value in feedback structure */
|
||||
feedback->size = (Ip_u16)(1 + cid_size);
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_create_feedback, feedback->size %d\n",
|
||||
feedback->size);
|
||||
#endif /* ROHC_DEBUG */
|
||||
|
||||
return feedback;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_create_feedback_1
|
||||
*===========================================================================
|
||||
* Description: Generate a feedback element for the specified interface and
|
||||
* profile, with FEEDBACK-1 format for the feedback field.
|
||||
*
|
||||
* The FEEDBACK-1 format in feedback field:
|
||||
*
|
||||
* FEEDBACK-1
|
||||
*
|
||||
* ----------------------------
|
||||
* | profile specific info | 1 octet
|
||||
* ----------------------------
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Iprohc_feedback *
|
||||
iprohc_create_feedback_1(Iprohc_d_context *d_context,
|
||||
Ip_u16 sn)
|
||||
{
|
||||
Ip_u8 code, profileid;
|
||||
Iprohc_feedback *feedback = IP_NULL;
|
||||
Iprohc_interface *interface;
|
||||
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_create_feedback_1\n");
|
||||
#endif /* ROHC_DEBUG */
|
||||
|
||||
feedback = iprohc_create_feedback(d_context);
|
||||
|
||||
if (feedback == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(ERR, "iprohc_create_feedback_1: out of memory (%d bytes)",
|
||||
sizeof(Iprohc_feedback));
|
||||
return IP_NULL;
|
||||
}
|
||||
|
||||
/* Get Code from the feedback packet */
|
||||
code = (Ip_u8)(feedback->data[0] & 0x07);
|
||||
|
||||
/* Format the feedback: SN portion */
|
||||
feedback->data[feedback->size] = (Ip_u8)(sn & 0xFF);
|
||||
|
||||
/* Increment Code by 1 */
|
||||
code ++;
|
||||
feedback->data[0] = 0xF0; /* clear Code field */
|
||||
feedback->data[0] |= code;
|
||||
|
||||
/* Set the size value in feedback structure */
|
||||
feedback->size ++;
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
iprohc_print_feedback(feedback);
|
||||
#endif /* ROHC_DEBUG */
|
||||
|
||||
/* Increment feedback counter and add the feedback to interface */
|
||||
profileid = d_context->profileid;
|
||||
interface = (Iprohc_interface *)((Iprohc_compressor *)d_context->decompressor)->interface;
|
||||
|
||||
IPROHC_IF_LOCK(interface);
|
||||
ipcom_list_insert_last(&interface->feedback_head[profileid],
|
||||
&feedback->feedback_list);
|
||||
interface->feedback_num[profileid]++;
|
||||
IPROHC_IF_UNLOCK(interface);
|
||||
|
||||
return feedback;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_create_feedback_2
|
||||
*===========================================================================
|
||||
* Description: Generate a feedback element for the specified interface and
|
||||
* profile, with FEEDBACK-2 format for the feedback field.
|
||||
*
|
||||
* 5.7.6.1 The FEEDBACK-2 format in feedback field:
|
||||
*
|
||||
* ----------------------------
|
||||
* |Acktype| |
|
||||
* --------- profile specific / at least 2 octets
|
||||
* / info |
|
||||
* ----------------------------
|
||||
*
|
||||
* More specifically:
|
||||
*
|
||||
* ----------------------------
|
||||
* |Acktype| Mode | SN(4 bit) |
|
||||
* ----------------------------
|
||||
* | SN LSB |
|
||||
* ----------------------------
|
||||
* / Feedback options /
|
||||
* ----------------------------
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Iprohc_feedback *
|
||||
iprohc_create_feedback_2(Iprohc_d_context *d_context,
|
||||
Iprohc_feedback_acktype acktype,
|
||||
Ip_u16 sn)
|
||||
{
|
||||
Ip_u8 code, profileid;
|
||||
Iprohc_feedback *feedback = IP_NULL;
|
||||
Iprohc_interface *interface;
|
||||
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_create_feedback_2, acktype %d\n", acktype);
|
||||
iprohc_d_print_a_context(d_context);
|
||||
#endif /* ROHC_DEBUG */
|
||||
|
||||
feedback = iprohc_create_feedback(d_context);
|
||||
|
||||
if (feedback == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(ERR, "iprohc_create_feedback_2: out of memory (%d bytes)",
|
||||
sizeof(Iprohc_feedback));
|
||||
return IP_NULL;
|
||||
}
|
||||
|
||||
/* Get Code from the feedback packet */
|
||||
code = (Ip_u8)(feedback->data[0] & 0x07);
|
||||
|
||||
/* Format the feedback: Acktype(2 bits) Mode(2 bits) SN-MSB(4 bits) */
|
||||
feedback->data[feedback->size] |= (Ip_u8)(acktype << 6);
|
||||
feedback->data[feedback->size] |= (Ip_u8)(d_context->trans_mode << 4);
|
||||
feedback->data[feedback->size] |= (Ip_u8)((sn & 0x0F00) >> 8);
|
||||
|
||||
/* Format the feedback: SN-LSB */
|
||||
feedback->size ++;
|
||||
feedback->data[feedback->size] |= (Ip_u8)(sn & 0xFF);
|
||||
|
||||
/* Re-set Code */
|
||||
code = (Ip_u8)(code + 2);
|
||||
feedback->data[0] = 0xF0; /* clear Code field */
|
||||
feedback->data[0] |= code;
|
||||
|
||||
/* Increase the size value in feedback structure */
|
||||
feedback->size ++;
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
iprohc_print_feedback(feedback);
|
||||
#endif /* ROHC_DEBUG */
|
||||
|
||||
/* Increment feedback counter and add the feedback to interface */
|
||||
profileid = d_context->profileid;
|
||||
interface = (Iprohc_interface *)
|
||||
((Iprohc_compressor *)d_context->decompressor)->interface;
|
||||
|
||||
IPROHC_IF_LOCK(interface);
|
||||
ipcom_list_insert_last(&interface->feedback_head[profileid],
|
||||
&feedback->feedback_list);
|
||||
interface->feedback_num[profileid]++;
|
||||
IPROHC_IF_UNLOCK(interface);
|
||||
|
||||
return feedback;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_feedback_add_option
|
||||
*===========================================================================
|
||||
* Description: Add an option to a feedback element.
|
||||
* Refer to RFC 3095, section 5.7.6.2 for feedback options
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
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_u8 code, size, i, pointer, crc = 0;
|
||||
Ip_err retval = IPCOM_SUCCESS;
|
||||
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_feedback_add_option, type %d, len %d, data %d\n",
|
||||
opt_type, opt_len, opt_data);
|
||||
#endif
|
||||
|
||||
/* Get Code from the feedback element */
|
||||
code = size = (Ip_u8)(feedback->data[0] & 0x07);
|
||||
|
||||
if (code == 0)
|
||||
size = feedback->data[1];
|
||||
|
||||
/* Validate the length */
|
||||
if ((size+opt_len) > (IPROHC_MAX_FEEDBCK_BUF-2))
|
||||
return IPCOM_ERR_REACHED_MAX;
|
||||
|
||||
/* Set pointer to point to next data item to be filled */
|
||||
pointer = (Ip_u8)feedback->size;
|
||||
|
||||
/* Check whether need to add Size octet */
|
||||
if ((code != 0) && (size + opt_len + 1 > 7))
|
||||
{
|
||||
/* Shift feedback data back by 1 octet */
|
||||
for (i = (Ip_u8)(feedback->size - 1); i > 0; i--)
|
||||
feedback->data[i+1] = feedback->data[i];
|
||||
|
||||
/* Clear Code field */
|
||||
feedback->data[0] = 0xF0;
|
||||
|
||||
/* Increment the pointer */
|
||||
pointer++;
|
||||
}
|
||||
|
||||
/* Append the feedback option */
|
||||
feedback->data[pointer] |= (Ip_u8)(opt_type << 4);
|
||||
feedback->data[pointer] |= opt_len;
|
||||
|
||||
if (opt_len != 0)
|
||||
feedback->data[pointer+1] = opt_data;
|
||||
|
||||
/* Increment size counter */
|
||||
feedback->size = (Ip_u16)(feedback->size + opt_len + 1);
|
||||
size = (Ip_u8)(size + opt_len + 1);
|
||||
|
||||
if ((feedback->data[0] & 0x07) != 0)
|
||||
{
|
||||
/* Set Code field */
|
||||
feedback->data[0] = 0xF0;
|
||||
feedback->data[0] |= size;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set Size octet */
|
||||
feedback->data[1] = size;
|
||||
}
|
||||
|
||||
/* RFC 3095, 5.7.6.3: */
|
||||
/* If a CRC option, calculate the 8-bit CRC over the entire feedback */
|
||||
/* payload, without the packet type and code octet, but including any */
|
||||
/* CID fields */
|
||||
if (opt_type == ROHC_FEEDBACK_OPT_CRC)
|
||||
{
|
||||
/* Calculate the 8-bit CRC */
|
||||
if ((feedback->data[0] & 0x07) != 0)
|
||||
/* Has Code, no Size octet */
|
||||
crc = iprohc_crc8((Ip_u8 *)&(feedback->data[1]), size);
|
||||
else
|
||||
/* Has Size octet */
|
||||
crc = iprohc_crc8((Ip_u8 *)&(feedback->data[2]), size);
|
||||
|
||||
/* Fill in CRC */
|
||||
feedback->data[pointer+1] = crc;
|
||||
}
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
iprohc_print_feedback(feedback);
|
||||
#endif /* ROHC_DEBUG */
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_preappend_feedback
|
||||
*===========================================================================
|
||||
* Description: Pre-append the feedbacks for the specified interface and
|
||||
* profile to the outgoing packet.
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_preappend_feedback(Iprohc_interface *interface,
|
||||
Ip_u8 profileid, Iprohc_c_context *context,
|
||||
Ipcom_pkt *pkt)
|
||||
{
|
||||
Ip_err retval = IPCOM_SUCCESS;
|
||||
Ip_u8 pkt_type;
|
||||
#ifdef IPCOM_USE_INET
|
||||
Ipa_union pkt_dst4, pkt_src4;
|
||||
#endif
|
||||
#ifdef IPCOM_USE_INET6
|
||||
struct Ip_in6_addr pkt_dst6, pkt_src6;
|
||||
#endif
|
||||
Iprohc_feedback *feedback, *nfeedback;
|
||||
Ip_u16 total_fb_size = 0;
|
||||
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_preappend_feedback\n");
|
||||
#endif
|
||||
|
||||
IPROHC_IF_LOCK(interface);
|
||||
|
||||
/* Get destination address and pkt type of the packet from the context */
|
||||
pkt_type = context->stream_type;
|
||||
#ifdef IPCOM_USE_INET
|
||||
if (pkt_type == ROHC_PKT_IPV4)
|
||||
{
|
||||
/* An IPv4 packet */
|
||||
pkt_dst4 = context->dst.addr4;
|
||||
pkt_src4 = context->src.addr4;
|
||||
}
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
/*
|
||||
{
|
||||
char buf[48];
|
||||
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &pkt_dst4.addr32, buf, sizeof(buf));
|
||||
ipcom_printf("iprohc_preappend_feedback: pkt IPv4 dst addr %s\n", buf);
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &pkt_src4.addr32, buf, sizeof(buf));
|
||||
ipcom_printf("iprohc_preappend_feedback: pktIPv4 src addr %s\n", buf);
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
if (pkt_type == ROHC_PKT_IPV6)
|
||||
{
|
||||
/* An IPv6 packet */
|
||||
pkt_dst6 = context->dst.addr6;
|
||||
pkt_src6 = context->src.addr6;
|
||||
}
|
||||
#ifdef ROHC_DEBUG
|
||||
{
|
||||
char buf[48];
|
||||
|
||||
(void)ipcom_inet_ntop(IP_AF_INET6, &pkt_dst6, buf, sizeof(buf));
|
||||
ipcom_printf("iprohc_preappend_feedback: pkt IPv6 dst addr %s\n", buf);
|
||||
(void)ipcom_inet_ntop(IP_AF_INET6, &pkt_src6, buf, sizeof(buf));
|
||||
ipcom_printf("iprohc_preappend_feedback: pkt IPv6 src addr %s\n", buf);
|
||||
}
|
||||
#endif
|
||||
#endif /* #ifdef IPCOM_USE_INET6 */
|
||||
|
||||
|
||||
/* Walk through the feedback list to determine whether to transmit a */
|
||||
/* feedback and calulate the total size of feedbacks to be transmitted */
|
||||
for (profileid = 0; (profileid < IPROHC_MAX_PROFILE_IDS); profileid++)
|
||||
{
|
||||
if (interface->profiles[profileid] != IP_TRUE) continue;
|
||||
|
||||
for (feedback = IPCOM_LIST_FIRST(&interface->feedback_head[profileid]);
|
||||
feedback != IP_NULL;
|
||||
feedback = nfeedback)
|
||||
{
|
||||
nfeedback = IPCOM_LIST_NEXT(&feedback->feedback_list);
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
/*
|
||||
{
|
||||
char buf[48];
|
||||
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &feedback->dst.addr4.addr32, buf, sizeof(buf));
|
||||
ipcom_printf("iprohc_preappend_feedback: dst IPv4 dst addr %s\n", buf);
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &feedback->src.addr4.addr32, buf, sizeof(buf));
|
||||
ipcom_printf("iprohc_preappend_feedback: dst IPv4 src addr %s\n", buf);
|
||||
ipcom_printf("iprohc_preappend_feedback: pkt_type %d, fb pkt_type %d\n",
|
||||
pkt_type, feedback->packet_type);
|
||||
}
|
||||
{
|
||||
char buf[48];
|
||||
(void)ipcom_inet_ntop(IP_AF_INET6, &feedback->dst.addr6, buf, sizeof(buf));
|
||||
ipcom_printf("iprohc_preappend_feedback: feedback IPv6 dst addr %s\n", buf);
|
||||
(void)ipcom_inet_ntop(IP_AF_INET6, &feedback->src.addr6, buf, sizeof(buf));
|
||||
ipcom_printf("iprohc_preappend_feedback: feedback IPv6 src addr %s\n", buf);
|
||||
ipcom_printf("iprohc_preappend_feedback: pkt_type %d, fb pkt_type %d\n",
|
||||
pkt_type, feedback->packet_type);
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* Transmit the packet if matching the type and destination address */
|
||||
#ifdef IPCOM_USE_INET
|
||||
if ((pkt_type == feedback->packet_type) &&
|
||||
(pkt_type == ROHC_PKT_IPV4) &&
|
||||
(pkt_src4.addr32 == feedback->src.addr4.addr32) &&
|
||||
(pkt_dst4.addr32 == feedback->dst.addr4.addr32))
|
||||
{
|
||||
/* Set to_be_transmitted flag and add the size */
|
||||
feedback->to_be_transmitted = IP_TRUE;
|
||||
total_fb_size = (Ip_u16)(total_fb_size + feedback->size);
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("fd pkt to be transmitted, total_fb_size %d, feedback->size %d\n",
|
||||
total_fb_size, feedback->size);
|
||||
#endif
|
||||
}
|
||||
#ifdef IPCOM_USE_INET6
|
||||
else
|
||||
#endif /* #ifdef IPCOM_USE_INET6 */
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
#ifdef IPCOM_USE_INET6
|
||||
if ((pkt_type == feedback->packet_type) &&
|
||||
(pkt_type == ROHC_PKT_IPV6) &&
|
||||
(ipcom_memcmp(&pkt_src6, &feedback->src.addr6,
|
||||
sizeof(struct Ip_in6_addr)) == 0) &&
|
||||
(ipcom_memcmp(&pkt_dst6, &feedback->dst.addr6,
|
||||
sizeof(struct Ip_in6_addr)) == 0))
|
||||
{
|
||||
/* Set to_be_transmitted flag and add the size */
|
||||
feedback->to_be_transmitted = IP_TRUE;
|
||||
total_fb_size = (Ip_u16)(total_fb_size + feedback->size);
|
||||
}
|
||||
#endif /* #ifdef IPCOM_USE_INET6 */
|
||||
}
|
||||
}
|
||||
|
||||
/* Check whether the packet has enough space to add feedbacks */
|
||||
if (pkt->maxlen - pkt->start < total_fb_size)
|
||||
{
|
||||
/* not enough space, need to increase header space */
|
||||
/* Tong: to call ipnet_increase_hdr_space() */
|
||||
}
|
||||
|
||||
/* Pre-append the to-be-transmitted feedbacks to the packet */
|
||||
for (profileid = 0; (profileid < IPROHC_MAX_PROFILE_IDS); profileid++)
|
||||
{
|
||||
if (interface->profiles[profileid] != IP_TRUE) continue;
|
||||
|
||||
for (feedback = IPCOM_LIST_FIRST(&interface->feedback_head[profileid]);
|
||||
feedback != IP_NULL;
|
||||
feedback = nfeedback)
|
||||
{
|
||||
nfeedback = IPCOM_LIST_NEXT(&feedback->feedback_list);
|
||||
|
||||
if (feedback->to_be_transmitted)
|
||||
{
|
||||
/* Move back the pkt->ipstart and pkt->start pointer */
|
||||
pkt->ipstart -= feedback->size;
|
||||
pkt->start = pkt->ipstart;
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("fd pkt to preappend, feedback->size %d\n", feedback->size);
|
||||
#endif
|
||||
|
||||
/* Pre-append the feedback */
|
||||
ipcom_memcpy(&(pkt->data[pkt->start]), feedback->data,
|
||||
feedback->size);
|
||||
|
||||
/* remove and free the feedback structure */
|
||||
ip_assert(interface->feedback_num[profileid] > 0);
|
||||
interface->feedback_num[profileid]--;
|
||||
ipcom_list_remove(&feedback->feedback_list);
|
||||
ipcom_free(feedback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IPROHC_IF_UNLOCK(interface);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,618 @@
|
||||
/* iprohc_format.c - ROHC compressed packet generic format routines */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013 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,30jul13,j_y Clean medium impact code review defects
|
||||
01e,08dec10,ggz Add 64 bit support
|
||||
01d,20apr09,tlu Fix Linux build warnings for mips64 gcc (cav_ebt5800)
|
||||
01c,21may08,tlu Add debug messages
|
||||
01b,16may08,tlu Use encoded SN to format base header
|
||||
01a,26mar08,tlu Created.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iprohc_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
|
||||
/* ipcom */
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_sysvar.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_list.h>
|
||||
|
||||
|
||||
/* iprohc */
|
||||
#include "iprohc.h"
|
||||
#include "iprohc_format.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* This is a compile flag, turning on it will build debug message into image */
|
||||
#undef ROHC_DEBUG
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC void iprohc_fmt_ext3_hd_fields(Ipcom_pkt *pkt,
|
||||
int *pointer,
|
||||
Ip_u8 flags,
|
||||
void *header,
|
||||
Ip_u8 version);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL Data
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_fmt_ext3_hd_fields
|
||||
*===========================================================================
|
||||
* Description: Add common hader fields to an extension 3 header field.
|
||||
*
|
||||
* RFC 3095, 5.7.5 Extension Formats
|
||||
*
|
||||
* Common header fields format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | TOS/Traffic Class | if TOS = 1
|
||||
* -----------------------------
|
||||
* | TTL/Hop Limit | if TTL = 1
|
||||
* -----------------------------
|
||||
* | Protocol/Next Header | if PR = 1
|
||||
* -----------------------------
|
||||
* | IP extension headers | variable, if IPX = 1 (not supported)
|
||||
* -----------------------------
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
|
||||
IP_STATIC void
|
||||
iprohc_fmt_ext3_hd_fields(Ipcom_pkt *pkt,
|
||||
int *pointer,
|
||||
Ip_u8 flags,
|
||||
void *header,
|
||||
Ip_u8 version)
|
||||
{
|
||||
Ip_u8 protocol = 0, ttl = 0, tos = 0;
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_fmt_ext3_hd_fields, flags %x, version %x\n",
|
||||
flags, version);
|
||||
#endif
|
||||
|
||||
if ((version >> ROHC_PKT_IP_SHIFT) == ROHC_PKT_IPV4)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
protocol = ((Ipcom_ip_header *)header)->protocol;
|
||||
ttl = ((Ipcom_ip_header *)header)->ttl;
|
||||
tos = ((Ipcom_ip_header *)header)->tos;
|
||||
#endif /* IPCOM_USE_INET */
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef IPCOM_USE_INET6
|
||||
Ipcom_ip6_header *header6 = (Ipcom_ip6_header *)header;
|
||||
|
||||
protocol = ((Ipcom_ip6_header *)header)->nxt;
|
||||
ttl = ((Ipcom_ip6_header *)header)->hlim;
|
||||
tos = (Ip_u8)(IP_GET_NTOHL(&header6->ver_class_flow)>>20) & 0xff;
|
||||
#endif /* IPCOM_USE_INET */
|
||||
}
|
||||
|
||||
/* Add Protocol/Next Header */
|
||||
if (flags & 0x10)
|
||||
{
|
||||
(*pointer)--;
|
||||
pkt->data[*pointer] = protocol;
|
||||
}
|
||||
|
||||
/* Add Time to Live/Hop Limit */
|
||||
if (flags & 0x40)
|
||||
{
|
||||
(*pointer)--;
|
||||
pkt->data[*pointer] = ttl;
|
||||
}
|
||||
|
||||
/* Add Type of Service/Traffic Class */
|
||||
if (flags & 0x80)
|
||||
{
|
||||
(*pointer)--;
|
||||
pkt->data[*pointer] = tos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_fmt_extension
|
||||
*===========================================================================
|
||||
* Description: Format an extension for IP/UDP/ESP profile.
|
||||
*
|
||||
* RFC 3095, 5.11.4 Extensions
|
||||
*
|
||||
* Extension 0 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 0 0 | SN(3 bits) | IP-ID |
|
||||
* -----------------------------
|
||||
*
|
||||
* Extension 1 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 0 1 | SN(3 bits) | IP-ID |
|
||||
* -----------------------------
|
||||
* | IP-ID |
|
||||
* -----------------------------
|
||||
*
|
||||
* Extension 2 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 1 0 | SN(3 bits) | IP-ID |
|
||||
* -----------------------------
|
||||
* | IP-ID |
|
||||
* -----------------------------
|
||||
* | IP-ID2 |
|
||||
* -----------------------------
|
||||
*
|
||||
* IP-ID2: For inner IP-ID field
|
||||
*
|
||||
* Extension 3 format:
|
||||
* Note: - Inner IP header (ip2) corresponds to the inner IP header
|
||||
* if there are two, and the single IP header otherwise.
|
||||
* - Outer IP header (ip) indicates presence of Outer IP header.
|
||||
* Unless context contains two IP headers, ip is always zero.
|
||||
*
|
||||
* -----------------------------
|
||||
* | 1 1 | S|Mode(2)| I|ip2|ip|
|
||||
* -----------------------------
|
||||
* | Inner IP header flags | if ip2 = 1
|
||||
* -----------------------------
|
||||
* | Outer IP header flags | if ip = 1
|
||||
* -----------------------------
|
||||
* | SN | if S = 1
|
||||
* -----------------------------
|
||||
* | |
|
||||
* / Inner IP header fields / variable,
|
||||
* | | if ip2 = 1
|
||||
* -----------------------------
|
||||
* | IP-ID | 2 octets, if I = 1
|
||||
* -----------------------------
|
||||
* | |
|
||||
* / Outer IP header fields / variable,
|
||||
* | | if ip = 1
|
||||
* -----------------------------
|
||||
*
|
||||
* RFC 3095, 5.7.5 Extension Formats
|
||||
*
|
||||
* Inner IP header flags:
|
||||
*
|
||||
* ---------------------------------------------
|
||||
* | TOS2| TTL2| DF2| PR2| IPX2| BNR2| RND2| 0 | if ip2 = 1
|
||||
* ---------------------------------------------
|
||||
*
|
||||
* Outer IP header flags:
|
||||
*
|
||||
* ---------------------------------------------
|
||||
* | TOS | TTL | DF | PR | IPX | BNR | RND | I | if ip = 1
|
||||
* ---------------------------------------------
|
||||
*
|
||||
* Inner IP header fields:
|
||||
*
|
||||
* -----------------------------
|
||||
* | TOS/Traffic Class | if TOS = 1
|
||||
* -----------------------------
|
||||
* | TTL/Hop Limit | if TTL = 1
|
||||
* -----------------------------
|
||||
* | Protocol/Next Header | if PR = 1
|
||||
* -----------------------------
|
||||
* | IP extension headers | variable, if IPX = 1 (not supported)
|
||||
* -----------------------------
|
||||
*
|
||||
* Outer IP header fields:
|
||||
*
|
||||
* -----------------------------
|
||||
* | TOS/Traffic Class | if TOS2 = 1
|
||||
* -----------------------------
|
||||
* | TTL/Hop Limit | if TTL2 = 1
|
||||
* -----------------------------
|
||||
* | Protocol/Next Header | if PR2 = 1
|
||||
* -----------------------------
|
||||
* | IP extension headers | variable, if IPX2 = 1 (not supported)
|
||||
* -----------------------------
|
||||
* | IP-ID | 2 octets, if I2 = 1
|
||||
* -----------------------------
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_fmt_extension(Ipcom_pkt *pkt, int *pointer,
|
||||
Iprohc_extension ext_type,
|
||||
void *ip_header1, void *ip_header2,
|
||||
Ip_u16 sn, Iprohc_mode mode,
|
||||
Ip_u8 flags1, Ip_u8 flags2)
|
||||
{
|
||||
Ip_err retval = IPCOM_SUCCESS;
|
||||
Ip_u16 ip_id1 = 0, ip_id2 = 0;
|
||||
Ip_u16 sn_n = ip_htons(sn);
|
||||
Ip_u8 version1 = 0, version2 = 0;
|
||||
Ip_u8 ext3_flags = 0xE0;
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_fmt_extension, ip_header1 %x, ip_header2 %x\n",
|
||||
ip_header1, ip_header2);
|
||||
ipcom_printf("iprohc_fmt_extension, flags1(o) %x, flags2(i) %x\n",
|
||||
flags1, flags2);
|
||||
#endif
|
||||
|
||||
/* Get versions of headers */
|
||||
if (ip_header1) version1 = *(Ip_u8 *)ip_header1;
|
||||
if (ip_header2) version2 = *(Ip_u8 *)ip_header2;
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_fmt_extension, version1(o) %x, version2(i) %x\n",
|
||||
version1, version2);
|
||||
#endif
|
||||
|
||||
if ((version1 >> ROHC_PKT_IP_SHIFT) == ROHC_PKT_IPV4)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
ip_id1 = ((Ipcom_ip_header *)ip_header1)->id;
|
||||
#endif /* IPCOM_USE_INET */
|
||||
}
|
||||
|
||||
if ((version2 >> ROHC_PKT_IP_SHIFT) == ROHC_PKT_IPV4)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
ip_id2 = ((Ipcom_ip_header *)ip_header2)->id;
|
||||
#endif /* IPCOM_USE_INET */
|
||||
}
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_fmt_extension, ip_id1 %x, ip_id2 %x, pointer %x\n",
|
||||
ip_id1, ip_id2, *pointer);
|
||||
#endif
|
||||
|
||||
switch (ext_type)
|
||||
{
|
||||
case ROHC_EXT_NO_EXT:
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_fmt_extension, no ext\n");
|
||||
#endif
|
||||
break;
|
||||
case ROHC_EXT_0:
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_fmt_extension, ext 0\n");
|
||||
#endif
|
||||
(*pointer)--;
|
||||
pkt->data[*pointer] = (Ip_u8)((sn_n & 0x07) << 3);
|
||||
pkt->data[*pointer] = (Ip_u8)(pkt->data[*pointer] | (ip_id1 & 0x07));
|
||||
break;
|
||||
case ROHC_EXT_1:
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_fmt_extension, ext 1\n");
|
||||
#endif
|
||||
(*pointer) -= 2;
|
||||
pkt->data[*pointer] = 0x40;
|
||||
pkt->data[*pointer] |= (Ip_u8)((sn_n & 0x07) << 3);
|
||||
pkt->data[*pointer] = (Ip_u8)(pkt->data[*pointer] | (ip_id1 & 0x0700) >> 8) ;
|
||||
pkt->data[*pointer+1] = (Ip_u8)(ip_id1 & 0xFF);
|
||||
break;
|
||||
case ROHC_EXT_2:
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_fmt_extension, ext 2\n");
|
||||
#endif
|
||||
(*pointer) -= 3;
|
||||
pkt->data[*pointer] = 0x80;
|
||||
pkt->data[*pointer] |= (Ip_u8)((sn_n & 0x07) << 3);
|
||||
pkt->data[*pointer] |= (Ip_u8)((ip_id1 & 0x0700) >> 8);
|
||||
pkt->data[*pointer+1] = (Ip_u8)((ip_id1 & 0xFF));
|
||||
pkt->data[*pointer+1] = (Ip_u8)((ip_id2 & 0xFF));
|
||||
break;
|
||||
case ROHC_EXT_3:
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_fmt_extension, ext 3\n");
|
||||
#endif
|
||||
/* Add outer IP header fields */
|
||||
if (flags1 != 0)
|
||||
{
|
||||
if(ip_header1 == IP_NULL)
|
||||
return IPCOM_ERR_INVALID_ARG;
|
||||
|
||||
ext3_flags |= 0x01;
|
||||
|
||||
if (flags1 & 0x02)
|
||||
{
|
||||
/* Add outer IP header IP-ID */
|
||||
(*pointer) -= 2;
|
||||
ipcom_memcpy(&pkt->data[*pointer], &ip_id1, 2);
|
||||
flags1 |= 0x01;
|
||||
}
|
||||
else
|
||||
flags1 = (Ip_u8)( flags1 & 0xFE);
|
||||
|
||||
iprohc_fmt_ext3_hd_fields(pkt,
|
||||
pointer,
|
||||
flags1,
|
||||
ip_header1,
|
||||
version1);
|
||||
}
|
||||
|
||||
/* Add inner IP header fields and IP-ID */
|
||||
if (flags2 != 0)
|
||||
{
|
||||
if(ip_header2 == IP_NULL)
|
||||
return IPCOM_ERR_INVALID_ARG;
|
||||
|
||||
ext3_flags |= 0x02;
|
||||
flags2 = (Ip_u8)(flags2 & 0xFE);
|
||||
|
||||
if (flags2 & 0x02)
|
||||
{
|
||||
/* Add inner IP header IP-ID */
|
||||
(*pointer) -= 2;
|
||||
ipcom_memcpy(&pkt->data[*pointer], &ip_id2, 2);
|
||||
ext3_flags |= 0x04;
|
||||
}
|
||||
|
||||
iprohc_fmt_ext3_hd_fields(pkt,
|
||||
pointer,
|
||||
flags2,
|
||||
ip_header2,
|
||||
version2);
|
||||
}
|
||||
|
||||
/* Add SN */
|
||||
(*pointer)--;
|
||||
pkt->data[*pointer] = (Ip_u8)(sn_n & 0xFF);
|
||||
|
||||
/* Add outer IP header flags */
|
||||
if (ext3_flags & 0x01)
|
||||
{
|
||||
(*pointer)--;
|
||||
pkt->data[*pointer] = flags1;
|
||||
}
|
||||
|
||||
/* Add inner IP header flags */
|
||||
if (ext3_flags & 0x02)
|
||||
{
|
||||
(*pointer)--;
|
||||
pkt->data[*pointer] = flags2;
|
||||
}
|
||||
|
||||
/* Add extension 3 initial flag */
|
||||
ext3_flags = (Ip_u8)(ext3_flags | (mode << 3));
|
||||
(*pointer)--;
|
||||
pkt->data[*pointer] = ext3_flags;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_fmt_base_header
|
||||
*===========================================================================
|
||||
* Description: Format a type0/type1/type2 base header for IP/UDP/ESP profile.
|
||||
*
|
||||
* Depending on the context mode, a type 0 packet could be R-0-CRC, or UO-0.
|
||||
*
|
||||
* RFC 3095, 5.7.1 Packet type 0
|
||||
*
|
||||
* R-0-CRC format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 0 1 | SN |
|
||||
* -----------------------------
|
||||
* |SN| CRC |
|
||||
* -----------------------------
|
||||
*
|
||||
* UO-0 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 0 | SN(4 bits) | CRC (3) |
|
||||
* -----------------------------
|
||||
*
|
||||
* Depending on the context mode, a type 1 packet could be R-1, or UO-1.
|
||||
*
|
||||
* RFC 3095, 5.11.3 Packet types
|
||||
*
|
||||
* R-1 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 1 0 | SN |
|
||||
* -----------------------------
|
||||
* | X | IP-ID |
|
||||
* -----------------------------
|
||||
*
|
||||
* UO-1 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 1 0 | IP-ID |
|
||||
* -----------------------------
|
||||
* | SN (5 bits) | CRC |
|
||||
* -----------------------------
|
||||
*
|
||||
* A type 2 packet has only one format for all modes.
|
||||
*
|
||||
* RFC 3095, 5.11.3 Packet types
|
||||
*
|
||||
* UOR-2 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 1 1 0 | SN |
|
||||
* -----------------------------
|
||||
* | X | CRC |
|
||||
* -----------------------------
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_u8 iprohc_fmt_base_header(Ip_u8 *base_header,
|
||||
Iprohc_c_context *context,
|
||||
void *header,
|
||||
Ip_u8 sn, Ip_u8 crc)
|
||||
{
|
||||
Ip_u8 size = 2;
|
||||
Ip_u8 ip_id = 0;
|
||||
Ip_u8 version = *(Ip_u8 *)header;
|
||||
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_fmt_base_header, sn %d\n", sn);
|
||||
#endif
|
||||
|
||||
if ((version >> ROHC_PKT_IP_SHIFT) == ROHC_PKT_IPV4)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
ip_id = (Ip_u8)((Ipcom_ip_header *)header)->id;
|
||||
#endif /* IPCOM_USE_INET */
|
||||
}
|
||||
|
||||
switch (context->pkt_type)
|
||||
{
|
||||
case ROHC_PKT_TYPE_0:
|
||||
if (context->mode == ROHC_MODE_R)
|
||||
{
|
||||
/* Use R-0-CRC format */
|
||||
base_header[0] = 0x40;
|
||||
/* Most significant bits fill first octet of base header */
|
||||
base_header[0] = (Ip_u8) (base_header[0] | ((sn >> 1) & 0x3F));
|
||||
/* LSB in second octet of base header */
|
||||
base_header[1] = (Ip_u8)((sn & 0x01) << 7);
|
||||
base_header[1] = (Ip_u8)(base_header[1] + crc);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use UO-0 format */
|
||||
base_header[0] = (Ip_u8)((sn & 0x0F) << 3);
|
||||
base_header[0] = (Ip_u8)(base_header[0] + crc);
|
||||
size = 1;
|
||||
}
|
||||
break;
|
||||
case ROHC_PKT_TYPE_1:
|
||||
base_header[0] = 0x80;
|
||||
if (context->mode == ROHC_MODE_R)
|
||||
{
|
||||
base_header[0] = (Ip_u8)(base_header[0] | (sn & 0x3F));
|
||||
|
||||
if (context->ext_type == ROHC_EXT_NO_EXT)
|
||||
base_header[1] = 0;
|
||||
else
|
||||
base_header[1] = 0x80;
|
||||
|
||||
base_header[1] = (Ip_u8)(base_header[1] | (ip_id & 0x7F));
|
||||
}
|
||||
else
|
||||
{
|
||||
base_header[0] = (Ip_u8)(base_header[0] | (ip_id & 0x3F));
|
||||
base_header[1] = (Ip_u8)((sn & 0x1F) << 3);
|
||||
base_header[1] = (Ip_u8)(base_header[1] + crc);
|
||||
}
|
||||
break;
|
||||
case ROHC_PKT_TYPE_2:
|
||||
base_header[0] = 0xC0;
|
||||
base_header[0] = (Ip_u8)(base_header[0] | (sn & 0x1F));
|
||||
|
||||
if (context->ext_type == ROHC_EXT_NO_EXT)
|
||||
base_header[1] = 0;
|
||||
else
|
||||
base_header[1] = 0x80;
|
||||
|
||||
base_header[1] = (Ip_u8)(base_header[1] + crc);
|
||||
break;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,595 @@
|
||||
/* iprohc_parser.c - ROHC received packet parsing routines */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2013 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
|
||||
--------------------
|
||||
01f,08aug13,j_y Clean low impact code review defects
|
||||
01e,26sep11,ggz Fix for defect WIND00260061
|
||||
01d,15dec10,ggz Fix for defect WIND00254509
|
||||
01c,08dec10,ggz Add 64 bit support
|
||||
01b,22may08,tlu Add debug messages
|
||||
01a,06mar08,tlu Created.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "iprohc_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
|
||||
/* ipcom */
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_sysvar.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_list.h>
|
||||
#include <ipcom_time.h>
|
||||
|
||||
|
||||
/* iprohc */
|
||||
#include "iprohc.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/* This is a compile flag, turning on it will build debug message into image */
|
||||
#undef ROHC_DEBUG
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC void iprohc_parse_ext3_hd_fields(void *ip_header, Ip_u8 header_flags,
|
||||
Ipcom_pkt *pkt, int *pointer);
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL Data
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_parse_ext3_hd_fields
|
||||
*===========================================================================
|
||||
* Description: Parse an extension 3 header field with IP-ID.
|
||||
*
|
||||
* RFC 3095, 5.7.5 Extension Formats
|
||||
*
|
||||
* IP header flags:
|
||||
*
|
||||
* ---------------------------------------------
|
||||
* | TOS | TTL | DF | PR | IPX | BNO | RND | I |
|
||||
* ---------------------------------------------
|
||||
*
|
||||
* Header fields plus IP-ID format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | TOS/Traffic Class | if TOS = 1
|
||||
* -----------------------------
|
||||
* | TTL/Hop Limit | if TTL = 1
|
||||
* -----------------------------
|
||||
* | Protocol/Next Header | if PR = 1
|
||||
* -----------------------------
|
||||
* | IP extension headers | variable, if IPX = 1 (not supported)
|
||||
* -----------------------------
|
||||
* | IP-ID | 2 octets, if I = 1
|
||||
* -----------------------------
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
iprohc_parse_ext3_hd_fields(void *ip_header, Ip_u8 header_flags,
|
||||
Ipcom_pkt *pkt, int *pointer)
|
||||
{
|
||||
Ip_u8 data = *(Ip_u8 *)ip_header;
|
||||
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_parse_ext3_hd_fields\n");
|
||||
#endif
|
||||
|
||||
if (((data & 0xF0) >> 4) == ROHC_PKT_IPV4)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET
|
||||
Ipcom_ip_header *ip4 = (Ipcom_ip_header *)ip_header;
|
||||
|
||||
if (header_flags & 0x80)
|
||||
{
|
||||
/* Get TOS */
|
||||
ip4->tos = pkt->data[*pointer];
|
||||
(*pointer)++;
|
||||
}
|
||||
|
||||
if (header_flags & 0x40)
|
||||
{
|
||||
/* Get TTL */
|
||||
ip4->ttl = pkt->data[*pointer];
|
||||
(*pointer)++;
|
||||
}
|
||||
|
||||
if (header_flags & 0x10)
|
||||
{
|
||||
/* Get Protocol */
|
||||
ip4->protocol = pkt->data[*pointer];
|
||||
(*pointer)++;
|
||||
}
|
||||
|
||||
if (header_flags & 0x01)
|
||||
{
|
||||
/* Get IP-ID */
|
||||
ip4->id = (Ip_u16)pkt->data[*pointer];
|
||||
(*pointer) += 2;
|
||||
}
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
}
|
||||
else if (((data & 0xF0) >> 4) == ROHC_PKT_IPV6)
|
||||
{
|
||||
#ifdef IPCOM_USE_INET6
|
||||
Ipcom_ip6_header *ip6 = (Ipcom_ip6_header *)ip_header;
|
||||
Ip_u32 flow, ver_class_flow;
|
||||
Ip_u8 class;
|
||||
|
||||
if (header_flags & 0x80)
|
||||
{
|
||||
/* Reformat ver_class_flow field in Ipcom_ip6_header structure */
|
||||
|
||||
/* Get flow from the current ver_class_flow */
|
||||
flow = IP_GET_NTOHL(&ip6->ver_class_flow) & 0xfffff;
|
||||
|
||||
/* Get Traffic Class */
|
||||
class = pkt->data[*pointer];
|
||||
(*pointer)++;
|
||||
|
||||
/* Format ver_class_flow with version = 6 */
|
||||
/* version (4 bits) + class(8 bits) + flow (20 bits) */
|
||||
ver_class_flow = flow + (Ip_u32)((6 << 28) + (class << 20));
|
||||
ip6->ver_class_flow = ip_htonl(ver_class_flow);
|
||||
}
|
||||
|
||||
if (header_flags & 0x40)
|
||||
{
|
||||
/* Get Hop Limit */
|
||||
ip6->hlim = pkt->data[*pointer];
|
||||
(*pointer)++;
|
||||
}
|
||||
|
||||
if (header_flags & 0x10)
|
||||
{
|
||||
/* Get Next Header */
|
||||
ip6->nxt = pkt->data[*pointer];
|
||||
(*pointer)++;
|
||||
}
|
||||
#endif /* #ifdef IPCOM_USE_INET6 */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_parser_pkt_type
|
||||
*===========================================================================
|
||||
* Description: Parse the received parket to determine its packet type.
|
||||
*
|
||||
* 5.2 A ROHC packet has the following general format (in the diagram,
|
||||
* colons ":" indicate that the part is optional):
|
||||
*
|
||||
* --------------------------
|
||||
* : Padding : variable length
|
||||
* --------------------------
|
||||
* : Feedback : 0 or more feedback elements
|
||||
* --------------------------
|
||||
* : Header : variable, with CID information
|
||||
* --------------------------
|
||||
* : Payload :
|
||||
* --------------------------
|
||||
*
|
||||
* Padding is any number (zero or more) of padding octets. Either of
|
||||
* Feedback or Header must be present.
|
||||
*
|
||||
* Feedback elements always start with a packet type indication.
|
||||
* Feedback elements carry internal CID information.
|
||||
*
|
||||
* Header is either a profile-specific header or an IR or IR-DYN header.
|
||||
*
|
||||
* Parameters:
|
||||
* Returns: packet type
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_u8
|
||||
iprohc_parse_pkt_type(Ipcom_pkt *pkt, Ip_u16 *feedback_num, Ip_u8 **feedbacks, Ipcom_netif *netif)
|
||||
{
|
||||
Ip_u32 pointer = (Ip_u32)pkt->ipstart, b_pointer;
|
||||
Ip_u16 feedback_size, total_feedback_size;
|
||||
|
||||
|
||||
if (netif->type != IP_IFT_PPPOE)
|
||||
{
|
||||
/* Check whether the packet is a normal IPv4 or IPv6 packet */
|
||||
#ifdef IPCOM_USE_INET
|
||||
if ((pkt->data[pointer] >> ROHC_PKT_IP_SHIFT) == ROHC_PKT_IPV4)
|
||||
/* A normal IPv4 packet */
|
||||
return ROHC_PKT_NORMAL;
|
||||
#endif /* #ifdef IPCOM_USE_INET */
|
||||
|
||||
#ifdef IPCOM_USE_INET6
|
||||
if ((pkt->data[pointer] >> ROHC_PKT_IP_SHIFT) == ROHC_PKT_IPV6)
|
||||
/* A normal IPv6 packet */
|
||||
return ROHC_PKT_NORMAL;
|
||||
#endif /* #ifdef IPCOM_USE_INET6 */
|
||||
} else if (netif->type == IP_IFT_PPPOE){
|
||||
/* For ESP over PPPoE, rohc input hook can be invoked twice. If esp packet is
|
||||
already decrypted then return. Packets are already decompressed */
|
||||
if (IP_BIT_ISTRUE(pkt->flags, IPCOM_PKT_FLAG_IPSEC_DONE))
|
||||
return ROHC_PKT_NORMAL;
|
||||
}
|
||||
/* A compressed packet */
|
||||
|
||||
/* Skip the PADDING octets */
|
||||
while (pkt->data[pointer] == ROHC_PKT_PAD)
|
||||
pointer++;
|
||||
|
||||
b_pointer = pointer;
|
||||
|
||||
/* Count all feedback elements if there is any */
|
||||
*feedback_num = 0;
|
||||
total_feedback_size = 0;
|
||||
|
||||
while ((pkt->data[b_pointer] >> ROHC_PKT_FEEDBACK_SHIFT) ==
|
||||
ROHC_PKT_FEEDBACK)
|
||||
{
|
||||
/* Count the feedback elements */
|
||||
(*feedback_num)++;
|
||||
|
||||
/* Check the Code to get feedback size */
|
||||
if ((pkt->data[b_pointer] & 0x07) == 0)
|
||||
/* Count Size octet */
|
||||
feedback_size =(Ip_u16)(1 + pkt->data[b_pointer+1]);
|
||||
else
|
||||
feedback_size = (Ip_u16)(pkt->data[b_pointer] & 0x07);
|
||||
|
||||
/* Increment the pointer by (1 + the size of feedback data field) */
|
||||
b_pointer += (Ip_u32)(1 + feedback_size);
|
||||
total_feedback_size = (Ip_u16)(total_feedback_size + 1 + feedback_size);
|
||||
}
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_parse_pkt_type: total_feedback_size %d\n",
|
||||
total_feedback_size);
|
||||
#endif
|
||||
|
||||
if (*feedback_num > 0)
|
||||
{
|
||||
Ip_u8 *fb_pointer;
|
||||
|
||||
/* copy the feedback elements to memory pointed by feedbacks */
|
||||
*feedbacks = ipcom_malloc(total_feedback_size);
|
||||
if(*feedbacks == IP_NULL)
|
||||
return (Ip_u8)-1;
|
||||
ipcom_memset(*feedbacks, 0, total_feedback_size);
|
||||
|
||||
fb_pointer = *feedbacks;
|
||||
|
||||
while ((pkt->data[pointer] >> ROHC_PKT_FEEDBACK_SHIFT) ==
|
||||
ROHC_PKT_FEEDBACK)
|
||||
{
|
||||
/* Check the Code to get feedback size */
|
||||
if ((pkt->data[pointer] & 0x07) == 0)
|
||||
/* count the Size octet */
|
||||
feedback_size = (Ip_u16)(1 + pkt->data[pointer+1]);
|
||||
else
|
||||
feedback_size = (Ip_u16)(pkt->data[pointer] & 0x07);
|
||||
|
||||
/* Copy the feedback element, including feedback type octet */
|
||||
ipcom_memcpy(fb_pointer, &(pkt->data[pointer]), (Ip_size_t)(1+feedback_size));
|
||||
|
||||
/* increment the pointers */
|
||||
pointer += (Ip_u32)(1 + feedback_size);
|
||||
fb_pointer += 1 + feedback_size;
|
||||
}
|
||||
}
|
||||
|
||||
if ((int)pointer >= pkt->end)
|
||||
/* Feedback only packet */
|
||||
return ROHC_PKT_FEEDBACK;
|
||||
else
|
||||
{
|
||||
/* Skip Padding and Feedback elements, move the ipstart pointer */
|
||||
/* to point to Header */
|
||||
pkt->ipstart = (int)pointer;
|
||||
|
||||
/* Check if it is segment/IR compressed packet type */
|
||||
|
||||
/* Skip CID if there is an ADD-CID octet */
|
||||
if ((pkt->data[pointer] >> ROHC_PKT_ADD_CID_SHIFT) == ROHC_PKT_ADD_CID)
|
||||
pointer ++;
|
||||
|
||||
if ((pkt->data[pointer] >> ROHC_PKT_IR_SHIFT) == ROHC_PKT_IR)
|
||||
return ROHC_PKT_IR;
|
||||
else if ((pkt->data[pointer]>>ROHC_PKT_SEGMENT_SHIFT)==ROHC_PKT_SEGMENT)
|
||||
return ROHC_PKT_SEGMENT;
|
||||
}
|
||||
|
||||
return ROHC_PKT_COMPRESSED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* iprohc_parse_extension
|
||||
*===========================================================================
|
||||
* Description: Parse an extension for IP/UDP/ESP profile.
|
||||
*
|
||||
* RFC 3095, 5.11.4 Extensions
|
||||
*
|
||||
* Extension 0 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 0 0 | SN(3 bits) | IP-ID |
|
||||
* -----------------------------
|
||||
*
|
||||
* Extension 1 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 0 1 | SN(3 bits) | IP-ID |
|
||||
* -----------------------------
|
||||
* | IP-ID |
|
||||
* -----------------------------
|
||||
*
|
||||
* Extension 2 format:
|
||||
*
|
||||
* -----------------------------
|
||||
* | 1 0 | SN(3 bits) | IP-ID |
|
||||
* -----------------------------
|
||||
* | IP-ID |
|
||||
* -----------------------------
|
||||
* | IP-ID2 |
|
||||
* -----------------------------
|
||||
*
|
||||
* IP-ID2: For inner IP-ID field
|
||||
*
|
||||
* Extension 3 format:
|
||||
* Note: - Inner IP header (ip2) corresponds to the inner IP header
|
||||
* if there are two, and the single IP header otherwise.
|
||||
* - Outer IP header (ip) indicates presence of Outer IP header.
|
||||
* Unless context contains two IP headers, ip is always zero.
|
||||
*
|
||||
* -----------------------------
|
||||
* | 1 1 | S|Mode(2)| I|ip2|ip|
|
||||
* -----------------------------
|
||||
* | Inner IP header flags | if ip2 = 1
|
||||
* -----------------------------
|
||||
* | Outer IP header flags | if ip = 1
|
||||
* -----------------------------
|
||||
* | SN | if S = 1
|
||||
* -----------------------------
|
||||
* | |
|
||||
* / Inner IP header fields / variable,
|
||||
* | | if ip2 = 1
|
||||
* -----------------------------
|
||||
* | IP-ID | 2 octets, if I = 1
|
||||
* -----------------------------
|
||||
* | |
|
||||
* / Outer IP header fields / variable,
|
||||
* | | if ip = 1
|
||||
* -----------------------------
|
||||
*
|
||||
* RFC 3095, 5.7.5 Extension Formats
|
||||
*
|
||||
* Inner IP header flags:
|
||||
*
|
||||
* ---------------------------------------------
|
||||
* | TOS2| TTL2| DF2| PR2| IPX2| BNO2| RND2| 0 | if ip2 = 1
|
||||
* ---------------------------------------------
|
||||
*
|
||||
* Outer IP header flags:
|
||||
*
|
||||
* ---------------------------------------------
|
||||
* | TOS | TTL | DF | PR | IPX | BNO | RND | I | if ip = 1
|
||||
* ---------------------------------------------
|
||||
*
|
||||
* Inner IP header fields:
|
||||
*
|
||||
* -----------------------------
|
||||
* | TOS/Traffic Class | if TOS = 1
|
||||
* -----------------------------
|
||||
* | TTL/Hop Limit | if TTL = 1
|
||||
* -----------------------------
|
||||
* | Protocol/Next Header | if PR = 1
|
||||
* -----------------------------
|
||||
* | IP extension headers | variable, if IPX = 1 (not supported)
|
||||
* -----------------------------
|
||||
*
|
||||
* Outer IP header fields:
|
||||
*
|
||||
* -----------------------------
|
||||
* | TOS/Traffic Class | if TOS2 = 1
|
||||
* -----------------------------
|
||||
* | TTL/Hop Limit | if TTL2 = 1
|
||||
* -----------------------------
|
||||
* | Protocol/Next Header | if PR2 = 1
|
||||
* -----------------------------
|
||||
* | IP extension headers | variable, if IPX2 = 1 (not supported)
|
||||
* -----------------------------
|
||||
* | IP-ID | 2 octets, if I2 = 1
|
||||
* -----------------------------
|
||||
*
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
iprohc_parse_extension(void *out_header, void *in_header,
|
||||
Ip_u8 *sn, int *mode,
|
||||
int *in_bno, int *in_rnd,
|
||||
int *out_bno, int *out_rnd,
|
||||
Ipcom_pkt *pkt, int *pointer)
|
||||
{
|
||||
Ip_err retval = IPCOM_SUCCESS;
|
||||
Ip_u8 init_flag, in_flags = 0, out_flags = 0;
|
||||
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("Enter iprohc_parse_extension\n");
|
||||
#endif
|
||||
|
||||
init_flag = pkt->data[*pointer];
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_parse_extension, init_flag %x\n", init_flag);
|
||||
#endif
|
||||
|
||||
switch ((init_flag & 0xC0) >> 6)
|
||||
{
|
||||
case 0: /* extension 0 */
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_parse_extension, ext 0\n");
|
||||
#endif
|
||||
*sn = (Ip_u8)((init_flag & 0x38) >> 3);
|
||||
(*pointer)++;
|
||||
break;
|
||||
case 1: /* extension 1 */
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_parse_extension, ext 1\n");
|
||||
#endif
|
||||
*sn = (Ip_u8)((init_flag & 0x38) >> 3);
|
||||
(*pointer) += 2;
|
||||
break;
|
||||
case 2: /* extension 2 */
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_parse_extension, ext 2\n");
|
||||
#endif
|
||||
*sn = (Ip_u8)((init_flag & 0x38) >> 3);
|
||||
(*pointer) += 3;
|
||||
break;
|
||||
case 3: /* extension 3 */
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_parse_extension, ext 3\n");
|
||||
#endif
|
||||
*mode = (init_flag & 0x18) >> 3;
|
||||
(*pointer)++;
|
||||
|
||||
/* Get inner IP header flags, and set the last bit as I bit */
|
||||
if (init_flag & 0x02)
|
||||
{
|
||||
in_flags = pkt->data[*pointer];
|
||||
in_flags = (Ip_u8)(in_flags | ((init_flag & 0x04) >> 2));
|
||||
|
||||
/* Update in_bno and in_rnd */
|
||||
*in_bno = (in_flags&0x04)>>2;
|
||||
*in_rnd = (in_flags&0x02)>>1;
|
||||
(*pointer)++;
|
||||
}
|
||||
|
||||
/* Get outer IP header flags */
|
||||
if (init_flag & 0x01)
|
||||
{
|
||||
out_flags = pkt->data[*pointer];
|
||||
|
||||
/* Update out_bno and out_rnd */
|
||||
*out_bno = (out_flags&0x04)>>2;
|
||||
*out_rnd = (out_flags&0x02)>>1;
|
||||
(*pointer)++;
|
||||
}
|
||||
|
||||
/* Get SN */
|
||||
if (init_flag & 0x20)
|
||||
{
|
||||
*sn = pkt->data[*pointer];
|
||||
(*pointer)++;
|
||||
}
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_parse_extension, in_flags %x\n", in_flags);
|
||||
#endif
|
||||
|
||||
/* Get inner IP header fields and IP-ID */
|
||||
iprohc_parse_ext3_hd_fields(in_header, in_flags, pkt, pointer);
|
||||
|
||||
#ifdef ROHC_DEBUG
|
||||
ipcom_printf("iprohc_parse_extension, out_flags %x\n", out_flags);
|
||||
#endif
|
||||
|
||||
/* Get outer IP header fields */
|
||||
if (out_header)
|
||||
iprohc_parse_ext3_hd_fields(out_header, out_flags, pkt, pointer);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user