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

471 lines
14 KiB
C

/* 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
****************************************************************************
*/