Files
m241Neelima/components/ip_net2-6.9/ipike/src/ipike2_payload_eap.c
T
2026-07-30 11:19:44 +05:30

252 lines
7.6 KiB
C

/*
******************************************************************************
* SOURCE FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipike2_payload_eap.c,v $ $Revision: 1.7.16.1 $
* $Source: /home/interpeak/CVSRoot/ipike/src/ipike2_payload_eap.c,v $
* $Author: edahlber $ $Date: 2011-12-22 09:29:34 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
******************************************************************************
*/
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/* EAP payload (IKE version 2) */
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
#include "ipike_config.h"
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#ifdef IPIKE_USE_VERSION2
#include "ipike_h.h"
#include "ipike_attributes.h"
#include "ipike2_payload_eap.h"
/*
****************************************************************************
* 4 EXTERN PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 5 DEFINES
****************************************************************************
*/
/*
****************************************************************************
* 6 TYPES
****************************************************************************
*/
/*
****************************************************************************
* 7 LOCAL PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 8 DATA
****************************************************************************
*/
/*
****************************************************************************
* 9 LOCAL FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* ipike_payload_eap_data
*===========================================================================
* Description: Returns a pointer to the eap data in the payload.
* Parameters: eap - a eap payload.
* Returns: A pointer to the eap data.
*/
IP_STATIC Ip_u8*
ipike_payload_eap_data(Ipike2_eap_payload* eap)
{
return (Ip_u8*)eap + IPIKE_EAP_HEADER_LENGTH;
}
/*
*===========================================================================
* ipike_payload_eap_data_length
*===========================================================================
* Description: Returns the length of the eap data.
* Parameters: eap - eap payload.
* Returns: The length of the eap data (in bytes).
*/
IP_STATIC Ip_u16
ipike_payload_eap_data_length(Ipike2_eap_payload* eap)
{
return IPIKE_PAYLOAD_DATA_LENGTH(eap->header.length, IPIKE_EAP_HEADER_LENGTH);
}
/*
*===========================================================================
* ipike_attribute_eap_code_to_string
*===========================================================================
* Description: Returns the length of the eap data.
* Parameters: code - eap code.
* Returns: A string representation of the code.
*/
IP_STATIC const char*
ipike_attribute_eap_code_to_string(Ip_u8 code)
{
const char* s;
if ((ipike_map_string(ipike.eap_code_map, code, &s)))
return "Invalid EAP code";
return s;
}
/*
****************************************************************************
* 10 PUBLIC FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* ipike_payload_eap_create
*===========================================================================
*/
IP_GLOBAL Ipike_error
ipike_payload_eap_create(
Ipike_value* eap,
Ipike2_eap_payload** payload)
{
Ipike2_eap_payload* eap_payload;
Ip_u8* buf;
Ip_u16 size;
if ((eap->value == IP_NULL) || (eap->len == 0))
{
*payload = IP_NULL;
}
else
{
size = sizeof((*payload)->header);
if (IP_NULL == (buf = ipcom_calloc(1, size + eap->len)))
{
IP_PANIC();
return IPIKE_OUT_OF_MEMORY;
}
ipcom_memcpy(buf+size, eap->value, eap->len);
eap_payload = (Ipike2_eap_payload*)buf;
eap_payload->header.next_payload = IPIKE2_PAYLOAD_EAP;
eap_payload->header.length = ip_htons((Ip_u16)(size + eap->len));
*payload = eap_payload;
/* Clear eap buffer, so we never reuse it */
ipcom_free(eap->value);
eap->value = IP_NULL;
eap->len = 0;
}
return IPIKE_SUCCESS;
}
/*
*===========================================================================
* ipike_payload_eap_check
*===========================================================================
*/
IP_GLOBAL Ipike_error
ipike_payload_eap_check(Ipike2_eap_payload* eap)
{
if ((ip_ntohs(eap->length) + sizeof(eap->header)) != ip_ntohs(eap->header.length))
{
IPCOM_LOG0(CRIT, "ipike_payload_eap_check: bad payload length");
return IPIKE_ISAKMP_PAYLOAD_LENGTH_ERROR;
}
return IPIKE_SUCCESS;
}
/*
*===========================================================================
* ipike_payload_eap_extract
*===========================================================================
*/
IP_GLOBAL Ipike_error
ipike_payload_eap_extract(
Ipike2_eap_payload* payload,
Ipike_value* eap)
{
eap->len = ip_htons(payload->header.length) - IPIKE_PAYLOAD_HEADER_LENGTH;
ipcom_free(eap->value);
if (IP_NULL == (eap->value = ipcom_malloc(eap->len)))
{
IP_PANIC();
return IPIKE_OUT_OF_MEMORY;
}
ipcom_memcpy(eap->value,
(Ip_u8*)payload + IPIKE_PAYLOAD_HEADER_LENGTH,
eap->len);
return IPIKE_SUCCESS;
}
/*
*===========================================================================
* ipike_payload_eap_print
*===========================================================================
*/
IP_GLOBAL void
ipike_payload_eap_print(Ipike2_eap_payload* eap)
{
const char* type = IP_NULL;
/* lint */
(void)type;
type = ipike_attribute_eap_code_to_string(eap->code);
IPCOM_LOG1(DEBUG2, " code: '%s'", type);
IPCOM_LOG1(DEBUG2, " id: %d", eap->id);
IPCOM_LOG1(DEBUG2, " length: %d", ip_htons(eap->length));
if (ipike_payload_eap_data_length(eap) > 0)
{
(void)ipike_print_memory(IPCOM_LOG_DEBUG2, " data:\n",
ipike_payload_eap_data(eap),
ipike_payload_eap_data_length(eap));
}
return;
}
#else
int ipike_payload_eap_empty_file = 0;
#endif /* IPIKE_USE_VERSION2 */
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/