|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
|
|
Packit |
13e616 |
* Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
|
|
Packit |
13e616 |
* Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* This software is available to you under a choice of one of two
|
|
Packit |
13e616 |
* licenses. You may choose to be licensed under the terms of the GNU
|
|
Packit |
13e616 |
* General Public License (GPL) Version 2, available from the file
|
|
Packit |
13e616 |
* COPYING in the main directory of this source tree, or the
|
|
Packit |
13e616 |
* OpenIB.org BSD license below:
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Redistribution and use in source and binary forms, with or
|
|
Packit |
13e616 |
* without modification, are permitted provided that the following
|
|
Packit |
13e616 |
* conditions are met:
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* - Redistributions of source code must retain the above
|
|
Packit |
13e616 |
* copyright notice, this list of conditions and the following
|
|
Packit |
13e616 |
* disclaimer.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* - Redistributions in binary form must reproduce the above
|
|
Packit |
13e616 |
* copyright notice, this list of conditions and the following
|
|
Packit |
13e616 |
* disclaimer in the documentation and/or other materials
|
|
Packit |
13e616 |
* provided with the distribution.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
Packit |
13e616 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
Packit |
13e616 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
Packit |
13e616 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
Packit |
13e616 |
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
Packit |
13e616 |
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
Packit |
13e616 |
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
Packit |
13e616 |
* SOFTWARE.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* Abstract:
|
|
Packit |
13e616 |
* provides byteswapping utilities. Basic functions are obtained from
|
|
Packit |
13e616 |
* platform specific implementations from byteswap_osd.h.
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
#ifndef _CL_BYTESWAP_H_
|
|
Packit |
13e616 |
#define _CL_BYTESWAP_H_
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
#include <string.h>
|
|
Packit |
13e616 |
#include <complib/cl_byteswap_osd.h>
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
#ifdef __cplusplus
|
|
Packit |
13e616 |
# define BEGIN_C_DECLS extern "C" {
|
|
Packit |
13e616 |
# define END_C_DECLS }
|
|
Packit |
13e616 |
#else /* !__cplusplus */
|
|
Packit |
13e616 |
# define BEGIN_C_DECLS
|
|
Packit |
13e616 |
# define END_C_DECLS
|
|
Packit |
13e616 |
#endif /* __cplusplus */
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
BEGIN_C_DECLS
|
|
Packit |
13e616 |
/****h* Component Library/Byte Swapping
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* Byte Swapping
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The byte swapping functions and macros allow swapping bytes from network
|
|
Packit |
13e616 |
* byte order to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* All data transmitted between systems should be in network byte order.
|
|
Packit |
13e616 |
* In order to utilize such data, it must be converted to host byte order
|
|
Packit |
13e616 |
* before use.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Functions:
|
|
Packit |
13e616 |
* cl_ntoh16, cl_hton16, cl_ntoh32, cl_hton32, cl_ntoh64, cl_hton64,
|
|
Packit |
13e616 |
* cl_ntoh
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* Macros:
|
|
Packit |
13e616 |
* CL_NTOH16, CL_HTON16, CL_NTOH32, CL_HTON32, CL_NTOH64, CL_HTON64
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* The byteswap_osd.h provides the following macros.
|
|
Packit |
13e616 |
* __LITTLE_ENDIAN
|
|
Packit |
13e616 |
* __BIG_ENDIAN
|
|
Packit |
13e616 |
* __BYTE_ORDER
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* If the platform provides byte swapping functions, byteswap_osd.h also
|
|
Packit |
13e616 |
* provides the following macros.
|
|
Packit |
13e616 |
* ntoh16, hton16
|
|
Packit |
13e616 |
* ntoh32, hton32
|
|
Packit |
13e616 |
* ntoh64, hton64
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
#ifndef __BYTE_ORDER
|
|
Packit |
13e616 |
#error "__BYTE_ORDER macro undefined. Missing in endian.h?"
|
|
Packit |
13e616 |
#endif
|
|
Packit |
13e616 |
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
Packit |
13e616 |
#define CPU_LE 1
|
|
Packit |
13e616 |
#define CPU_BE 0
|
|
Packit |
13e616 |
#else
|
|
Packit |
13e616 |
#define CPU_LE 0
|
|
Packit |
13e616 |
#define CPU_BE 1
|
|
Packit |
13e616 |
#endif
|
|
Packit |
13e616 |
/****d* Component Library: Byte Swapping/CL_NTOH16
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* CL_NTOH16
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The CL_NTOH16 macro converts a 16-bit value from network byte order to
|
|
Packit |
13e616 |
* host byte order. The CL_NTOH16 macro will cause constant values to be
|
|
Packit |
13e616 |
* swapped by the pre-processor. For variables, CL_NTOH16 is less efficient
|
|
Packit |
13e616 |
* than the cl_ntoh16 function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* CL_NTOH16( val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] 16-bit value to swap from network byte order to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RESULT
|
|
Packit |
13e616 |
* Value of val converted to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This macro is analogous to CL_HTON16.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, CL_HTON16, CL_NTOH32, CL_NTOH64,
|
|
Packit |
13e616 |
* cl_ntoh16, cl_ntoh32, cl_ntoh64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
/****d* Component Library: Byte Swapping/CL_HTON16
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* CL_HTON16
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The CL_HTON16 macro converts a 16-bit value from host byte order to
|
|
Packit |
13e616 |
* network byte order. The CL_HTON16 macro will cause constant values to be
|
|
Packit |
13e616 |
* swapped by the pre-processor. For variables, CL_HTON16 is less efficient
|
|
Packit |
13e616 |
* than the cl_hton16 function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* CL_HTON16( val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] 16-bit value to swap from host byte order to network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RESULT
|
|
Packit |
13e616 |
* Value of val converted to network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This macro is analogous to CL_NTOH16.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, CL_NTOH16, CL_HTON32, CL_HTON64,
|
|
Packit |
13e616 |
* cl_hton16, cl_hton32, cl_hton64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
#if CPU_LE
|
|
Packit |
13e616 |
#define CL_NTOH16( x ) (uint16_t)( \
|
|
Packit |
13e616 |
(((uint16_t)(x) & 0x00FF) << 8) | \
|
|
Packit |
13e616 |
(((uint16_t)(x) & 0xFF00) >> 8) )
|
|
Packit |
13e616 |
#else
|
|
Packit |
13e616 |
#define CL_NTOH16( x ) (x)
|
|
Packit |
13e616 |
#endif
|
|
Packit |
13e616 |
#define CL_HTON16 CL_NTOH16
|
|
Packit |
13e616 |
/****f* Component Library: Byte Swapping/cl_ntoh16
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_ntoh16
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_ntoh16 function converts a 16-bit value from network byte order to
|
|
Packit |
13e616 |
* host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* uint16_t
|
|
Packit |
13e616 |
* cl_ntoh16(
|
|
Packit |
13e616 |
* IN const uint16_t val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] Value to swap from network byte order to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* Value of val converted to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This function is analogous to cl_hton16.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, cl_hton16, cl_ntoh32, cl_ntoh64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
/****f* Component Library: Byte Swapping/cl_hton16
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_hton16
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_hton16 function converts a 16-bit value from host byte order to
|
|
Packit |
13e616 |
* network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* uint16_t
|
|
Packit |
13e616 |
* cl_hton16(
|
|
Packit |
13e616 |
* IN const uint16_t val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] Value to swap from host byte order to network byte order .
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* Value of val converted to network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This function is analogous to cl_ntoh16.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, cl_ntoh16, cl_hton32, cl_hton64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
#ifndef cl_ntoh16
|
|
Packit |
13e616 |
#define cl_ntoh16 CL_NTOH16
|
|
Packit |
13e616 |
#define cl_hton16 CL_HTON16
|
|
Packit |
13e616 |
#endif
|
|
Packit |
13e616 |
/****d* Component Library: Byte Swapping/CL_NTOH32
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* CL_NTOH32
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The CL_NTOH32 macro converts a 32-bit value from network byte order to
|
|
Packit |
13e616 |
* host byte order. The CL_NTOH32 macro will cause constant values to be
|
|
Packit |
13e616 |
* swapped by the pre-processor. For variables, CL_NTOH32 is less efficient
|
|
Packit |
13e616 |
* than the cl_ntoh32 function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* CL_NTOH32( val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] 32-bit value to swap from network byte order to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RESULT
|
|
Packit |
13e616 |
* Value of val converted to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This macro is analogous to CL_HTON32.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, CL_HTON32, CL_NTOH16, CL_NTOH64,
|
|
Packit |
13e616 |
* cl_ntoh16, cl_ntoh32, cl_ntoh64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
/****d* Component Library: Byte Swapping/CL_HTON32
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* CL_HTON32
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The CL_HTON32 macro converts a 32-bit value from host byte order to
|
|
Packit |
13e616 |
* network byte order. The CL_HTON32 macro will cause constant values to be
|
|
Packit |
13e616 |
* swapped by the pre-processor. For variables, CL_HTON32 is less efficient
|
|
Packit |
13e616 |
* than the cl_hton32 function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* CL_HTON32( val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] 32-bit value to swap from host byte order to network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RESULT
|
|
Packit |
13e616 |
* Value of val converted to network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This macro is analogous to CL_NTOH32.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, CL_NTOH32, CL_HTON16, CL_HTON64,
|
|
Packit |
13e616 |
* cl_hton16, cl_hton32, cl_hton64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
#if CPU_LE
|
|
Packit |
13e616 |
#define CL_NTOH32( x ) (uint32_t)( \
|
|
Packit |
13e616 |
(((uint32_t)(x) & 0x000000FF) << 24) | \
|
|
Packit |
13e616 |
(((uint32_t)(x) & 0x0000FF00) << 8) | \
|
|
Packit |
13e616 |
(((uint32_t)(x) & 0x00FF0000) >> 8) | \
|
|
Packit |
13e616 |
(((uint32_t)(x) & 0xFF000000) >> 24) )
|
|
Packit |
13e616 |
#else
|
|
Packit |
13e616 |
#define CL_NTOH32( x ) (x)
|
|
Packit |
13e616 |
#endif
|
|
Packit |
13e616 |
#define CL_HTON32 CL_NTOH32
|
|
Packit |
13e616 |
/****f* Component Library: Byte Swapping/cl_ntoh32
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_ntoh32
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_ntoh32 function converts a 32-bit value from network byte order to
|
|
Packit |
13e616 |
* host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* uint32_t
|
|
Packit |
13e616 |
* cl_ntoh32(
|
|
Packit |
13e616 |
* IN const uint32_t val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] Value to swap from network byte order to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* Value of val converted in host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This function is analogous to cl_hton32.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, cl_hton32, cl_ntoh16, cl_ntoh64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
/****f* Component Library: Byte Swapping/cl_hton32
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_hton32
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_hton32 function converts a 32-bit value from host byte order to
|
|
Packit |
13e616 |
* network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* uint32_t
|
|
Packit |
13e616 |
* cl_hton32(
|
|
Packit |
13e616 |
* IN const uint32_t val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] Value to swap from host byte order to network byte order .
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* Value of val converted to network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This function is analogous to cl_ntoh32.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, cl_ntoh32, cl_hton16, cl_hton64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
#ifndef cl_ntoh32
|
|
Packit |
13e616 |
#define cl_ntoh32 CL_NTOH32
|
|
Packit |
13e616 |
#define cl_hton32 CL_HTON32
|
|
Packit |
13e616 |
#endif
|
|
Packit |
13e616 |
/****d* Component Library: Byte Swapping/CL_NTOH64
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* CL_NTOH64
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The CL_NTOH64 macro converts a 64-bit value from network byte order to
|
|
Packit |
13e616 |
* host byte order. The CL_NTOH64 macro will cause constant values to be
|
|
Packit |
13e616 |
* swapped by the pre-processor. For variables, CL_NTOH64 is less efficient
|
|
Packit |
13e616 |
* than the cl_ntoh64 function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* CL_NTOH64( val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] 64-bit value to swap from network byte order to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RESULT
|
|
Packit |
13e616 |
* Value of val converted to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This macro is analogous to CL_HTON64.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, CL_HTON64, CL_NTOH16, CL_NTOH32,
|
|
Packit |
13e616 |
* cl_ntoh16, cl_ntoh32, cl_ntoh64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
/****d* Component Library: Byte Swapping/CL_HTON64
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* CL_HTON64
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The CL_HTON64 macro converts a 64-bit value from host byte order to
|
|
Packit |
13e616 |
* network byte order. The CL_HTON64 macro will cause constant values to be
|
|
Packit |
13e616 |
* swapped by the pre-processor. For variables, CL_HTON64 is less efficient
|
|
Packit |
13e616 |
* than the cl_hton64 function.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* CL_HTON64( val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] 64-bit value to swap from host byte order to network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RESULT
|
|
Packit |
13e616 |
* Value of val converted to network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This macro is analogous to CL_NTOH64.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, CL_NTOH64, CL_HTON16, CL_HTON32,
|
|
Packit |
13e616 |
* cl_hton16, cl_hton32, cl_hton64, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
#if CPU_LE
|
|
Packit |
13e616 |
#define CL_NTOH64( x ) (uint64_t)( \
|
|
Packit |
13e616 |
(((uint64_t)(x) & 0x00000000000000FFULL) << 56) | \
|
|
Packit |
13e616 |
(((uint64_t)(x) & 0x000000000000FF00ULL) << 40) | \
|
|
Packit |
13e616 |
(((uint64_t)(x) & 0x0000000000FF0000ULL) << 24) | \
|
|
Packit |
13e616 |
(((uint64_t)(x) & 0x00000000FF000000ULL) << 8 ) | \
|
|
Packit |
13e616 |
(((uint64_t)(x) & 0x000000FF00000000ULL) >> 8 ) | \
|
|
Packit |
13e616 |
(((uint64_t)(x) & 0x0000FF0000000000ULL) >> 24) | \
|
|
Packit |
13e616 |
(((uint64_t)(x) & 0x00FF000000000000ULL) >> 40) | \
|
|
Packit |
13e616 |
(((uint64_t)(x) & 0xFF00000000000000ULL) >> 56) )
|
|
Packit |
13e616 |
#else
|
|
Packit |
13e616 |
#define CL_NTOH64( x ) (x)
|
|
Packit |
13e616 |
#endif
|
|
Packit |
13e616 |
#define CL_HTON64 CL_NTOH64
|
|
Packit |
13e616 |
/****f* Component Library: Byte Swapping/cl_ntoh64
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_ntoh64
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_ntoh64 function converts a 64-bit value from network byte order to
|
|
Packit |
13e616 |
* host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* uint64_t
|
|
Packit |
13e616 |
* cl_ntoh64(
|
|
Packit |
13e616 |
* IN const uint64_t val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] Value to swap from network byte order to host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* Value of val converted in host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This function is analogous to cl_hton64.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, cl_hton64, cl_ntoh16, cl_ntoh32, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
/****f* Component Library: Byte Swapping/cl_hton64
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_hton64
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_hton64 function converts a 64-bit value from host byte order to
|
|
Packit |
13e616 |
* network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
* uint64_t
|
|
Packit |
13e616 |
* cl_hton64(
|
|
Packit |
13e616 |
* IN const uint64_t val );
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* val
|
|
Packit |
13e616 |
* [in] Value to swap from host byte order to network byte order .
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* Value of val converted to network byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* This function is analogous to cl_ntoh64.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, cl_ntoh64, cl_hton16, cl_hton32, cl_ntoh
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
#ifndef cl_ntoh64
|
|
Packit |
13e616 |
#define cl_ntoh64 CL_NTOH64
|
|
Packit |
13e616 |
#define cl_hton64 CL_HTON64
|
|
Packit |
13e616 |
#endif
|
|
Packit |
13e616 |
/****f* Component Library: Byte Swapping/cl_ntoh
|
|
Packit |
13e616 |
* NAME
|
|
Packit |
13e616 |
* cl_ntoh
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* DESCRIPTION
|
|
Packit |
13e616 |
* The cl_ntoh function converts a value from network byte order to
|
|
Packit |
13e616 |
* host byte order.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SYNOPSIS
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
static inline void
|
|
Packit |
13e616 |
cl_ntoh(OUT char *const p_dest,
|
|
Packit |
13e616 |
IN const char *const p_src, IN const uint8_t size)
|
|
Packit |
13e616 |
{
|
|
Packit |
13e616 |
#if CPU_LE
|
|
Packit |
13e616 |
uint8_t i;
|
|
Packit |
13e616 |
char temp;
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
if (p_src == p_dest) {
|
|
Packit |
13e616 |
/* Swap in place if source and destination are the same. */
|
|
Packit |
13e616 |
for (i = 0; i < size / 2; i++) {
|
|
Packit |
13e616 |
temp = p_dest[i];
|
|
Packit |
13e616 |
p_dest[i] = p_src[size - 1 - i];
|
|
Packit |
13e616 |
p_dest[size - 1 - i] = temp;
|
|
Packit |
13e616 |
}
|
|
Packit |
13e616 |
} else {
|
|
Packit |
13e616 |
for (i = 0; i < size; i++)
|
|
Packit |
13e616 |
p_dest[i] = p_src[size - 1 - i];
|
|
Packit |
13e616 |
}
|
|
Packit |
13e616 |
#else
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* If the source and destination are not the same, copy the source to
|
|
Packit |
13e616 |
* the destination.
|
|
Packit |
13e616 |
*/
|
|
Packit |
13e616 |
if (p_src != p_dest)
|
|
Packit |
13e616 |
memcpy(p_dest, p_src, size);
|
|
Packit |
13e616 |
#endif
|
|
Packit |
13e616 |
}
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
/*
|
|
Packit |
13e616 |
* PARAMETERS
|
|
Packit |
13e616 |
* p_dest
|
|
Packit |
13e616 |
* [in] Pointer to a byte array to contain the converted value of p_src.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* p_src
|
|
Packit |
13e616 |
* [in] Pointer to a byte array to be converted from network byte
|
|
Packit |
13e616 |
* ordering.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* size
|
|
Packit |
13e616 |
* [in] Number of bytes to swap.p_dest
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* RETURN VALUE
|
|
Packit |
13e616 |
* This function does not return a value.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* NOTES
|
|
Packit |
13e616 |
* cl_ntoh can perform in place swapping if both p_src and p_dest point to
|
|
Packit |
13e616 |
* the same buffer.
|
|
Packit |
13e616 |
*
|
|
Packit |
13e616 |
* SEE ALSO
|
|
Packit |
13e616 |
* Byte Swapping, cl_ntoh16, cl_ntoh32, cl_ntoh64
|
|
Packit |
13e616 |
*********/
|
|
Packit |
13e616 |
|
|
Packit |
13e616 |
END_C_DECLS
|
|
Packit |
13e616 |
#endif /* _CL_BYTESWAP_H_ */
|