1 #ifndef CSR_MSGCONV_H__ 2 #define CSR_MSGCONV_H__ 3 4 /***************************************************************************** 5 6 (c) Cambridge Silicon Radio Limited 2010 7 All rights reserved and confidential information of CSR 8 9 Refer to LICENSE.txt included with this source for details 10 on the license terms. 11 12 *****************************************************************************/ 13 14 #include <linux/types.h> 15 #include "csr_prim_defs.h" 16 #include "csr_sched.h" 17 18 typedef size_t (CsrMsgSizeofFunc)(void *msg); 19 typedef u8 *(CsrMsgSerializeFunc)(u8 *buffer, size_t *length, void *msg); 20 typedef void (CsrMsgFreeFunc)(void *msg); 21 typedef void *(CsrMsgDeserializeFunc)(u8 *buffer, size_t length); 22 23 /* Converter entry for one message type */ 24 typedef struct CsrMsgConvMsgEntry 25 { 26 u16 msgType; 27 CsrMsgSizeofFunc *sizeofFunc; 28 CsrMsgSerializeFunc *serFunc; 29 CsrMsgDeserializeFunc *deserFunc; 30 CsrMsgFreeFunc *freeFunc; 31 } CsrMsgConvMsgEntry; 32 33 /* Optional lookup function */ 34 typedef CsrMsgConvMsgEntry *(CsrMsgCustomLookupFunc)(CsrMsgConvMsgEntry *ce, u16 msgType); 35 36 /* All converter entries for one specific primitive */ 37 typedef struct CsrMsgConvPrimEntry 38 { 39 u16 primType; 40 const CsrMsgConvMsgEntry *conv; 41 CsrMsgCustomLookupFunc *lookupFunc; 42 struct CsrMsgConvPrimEntry *next; 43 } CsrMsgConvPrimEntry; 44 45 typedef struct 46 { 47 CsrMsgConvPrimEntry *profile_converters; 48 void *(*deserialize_data)(u16 primType, size_t length, u8 * data); 49 u8 (*free_message)(u16 primType, u8 *data); 50 size_t (*sizeof_message)(u16 primType, void *msg); 51 u8 *(*serialize_message)(u16 primType, void *msg, 52 size_t * length, 53 u8 * buffer); 54 } CsrMsgConvEntry; 55 56 size_t CsrMsgConvSizeof(u16 primType, void *msg); 57 u8 *CsrMsgConvSerialize(u8 *buffer, size_t maxBufferOffset, size_t *offset, u16 primType, void *msg); 58 void CsrMsgConvCustomLookupRegister(u16 primType, CsrMsgCustomLookupFunc *lookupFunc); 59 void CsrMsgConvInsert(u16 primType, const CsrMsgConvMsgEntry *ce); 60 CsrMsgConvPrimEntry *CsrMsgConvFind(u16 primType); 61 CsrMsgConvMsgEntry *CsrMsgConvFindEntry(u16 primType, u16 msgType); 62 CsrMsgConvMsgEntry *CsrMsgConvFindEntryByMsg(u16 primType, const void *msg); 63 CsrMsgConvEntry *CsrMsgConvInit(void); 64 65 /* Prototypes for primitive type serializers */ 66 void CsrUint8Ser(u8 *buffer, size_t *offset, u8 value); 67 void CsrUint16Ser(u8 *buffer, size_t *offset, u16 value); 68 void CsrUint32Ser(u8 *buffer, size_t *offset, u32 value); 69 void CsrMemCpySer(u8 *buffer, size_t *offset, const void *value, size_t length); 70 void CsrCharStringSer(u8 *buffer, size_t *offset, const char *value); 71 72 void CsrUint8Des(u8 *value, u8 *buffer, size_t *offset); 73 void CsrUint16Des(u16 *value, u8 *buffer, size_t *offset); 74 void CsrUint32Des(u32 *value, u8 *buffer, size_t *offset); 75 void CsrMemCpyDes(void *value, u8 *buffer, size_t *offset, size_t length); 76 void CsrCharStringDes(char **value, u8 *buffer, size_t *offset); 77 78 #endif 79