1/* 2 * Utilites for XDR encode and decode of data 3 * 4 * Copyright (C) 2015, Broadcom Corporation 5 * All Rights Reserved. 6 * 7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation; 8 * the contents of this file may not be disclosed to third parties, copied 9 * or duplicated in any form, in whole or in part, without the prior 10 * written permission of Broadcom Corporation. 11 * 12 * $Id: bcm_xdr.h 419467 2013-08-21 09:19:48Z $ 13 */ 14 15#ifndef _BCM_XDR_H 16#define _BCM_XDR_H 17 18#define XDR_PACK_OPAQUE_VAR_SZ(len) (sizeof(uint32) + ROUNDUP(len, sizeof(uint32))) 19 20/* 21 * bcm_xdr_buf_t 22 * Structure used for bookkeeping of a buffer being packed or unpacked. 23 * Keeps a current read/write pointer and size as well as 24 * the original buffer pointer and size. 25 * 26 */ 27typedef struct { 28 uint8 *buf; /* pointer to current position in origbuf */ 29 uint size; /* current (residual) size in bytes */ 30 uint8 *origbuf; /* unmodified pointer to orignal buffer */ 31 uint origsize; /* unmodified orignal buffer size in bytes */ 32} bcm_xdr_buf_t; 33 34 35void bcm_xdr_buf_init(bcm_xdr_buf_t *b, void *buf, size_t len); 36 37int bcm_xdr_pack_uint32(bcm_xdr_buf_t *b, uint32 val); 38int bcm_xdr_unpack_uint32(bcm_xdr_buf_t *b, uint32 *pval); 39int bcm_xdr_pack_int32(bcm_xdr_buf_t *b, int32 val); 40int bcm_xdr_unpack_int32(bcm_xdr_buf_t *b, int32 *pval); 41int bcm_xdr_pack_int8(bcm_xdr_buf_t *b, int8 val); 42int bcm_xdr_unpack_int8(bcm_xdr_buf_t *b, int8 *pval); 43int bcm_xdr_pack_opaque(bcm_xdr_buf_t *b, uint len, const void *data); 44int bcm_xdr_unpack_opaque(bcm_xdr_buf_t *b, uint len, void **pdata); 45int bcm_xdr_unpack_opaque_cpy(bcm_xdr_buf_t *b, uint len, void *data); 46int bcm_xdr_pack_opaque_varlen(bcm_xdr_buf_t *b, uint len, const void *data); 47int bcm_xdr_unpack_opaque_varlen(bcm_xdr_buf_t *b, uint *plen, void **pdata); 48int bcm_xdr_pack_string(bcm_xdr_buf_t *b, char *str); 49int bcm_xdr_unpack_string(bcm_xdr_buf_t *b, uint *plen, char **pstr); 50 51int bcm_xdr_pack_uint8_vec(bcm_xdr_buf_t *, uint8 *vec, uint32 elems); 52int bcm_xdr_unpack_uint8_vec(bcm_xdr_buf_t *, uint8 *vec, uint32 elems); 53int bcm_xdr_pack_uint16_vec(bcm_xdr_buf_t *b, uint len, void *vec); 54int bcm_xdr_unpack_uint16_vec(bcm_xdr_buf_t *b, uint len, void *vec); 55int bcm_xdr_pack_uint32_vec(bcm_xdr_buf_t *b, uint len, void *vec); 56int bcm_xdr_unpack_uint32_vec(bcm_xdr_buf_t *b, uint len, void *vec); 57 58int bcm_xdr_pack_opaque_raw(bcm_xdr_buf_t *b, uint len, void *data); 59int bcm_xdr_pack_opaque_pad(bcm_xdr_buf_t *b); 60 61int bcm_xdr_opaque_resrv(bcm_xdr_buf_t *b, uint len, void **pdata); 62int bcm_xdr_opaque_resrv_varlen(bcm_xdr_buf_t *b, uint len, void **pdata); 63 64#endif /* _BCM_XDR_H */ 65