Root/drivers/staging/csr/csr_serialize_primitive_types.c

1/*****************************************************************************
2
3            (c) Cambridge Silicon Radio Limited 2010
4            All rights reserved and confidential information of CSR
5
6            Refer to LICENSE.txt included with this source for details
7            on the license terms.
8
9*****************************************************************************/
10
11#include <linux/module.h>
12#include <linux/slab.h>
13#include "csr_prim_defs.h"
14#include "csr_msgconv.h"
15#include "csr_macro.h"
16#include "csr_lib.h"
17
18void CsrUint8Des(u8 *value, u8 *buffer, size_t *offset)
19{
20    *value = buffer[*offset];
21    *offset += sizeof(*value);
22}
23EXPORT_SYMBOL_GPL(CsrUint8Des);
24
25void CsrUint16Des(u16 *value, u8 *buffer, size_t *offset)
26{
27    *value = (buffer[*offset + 0] << 0) |
28             (buffer[*offset + 1] << 8);
29    *offset += sizeof(*value);
30}
31EXPORT_SYMBOL_GPL(CsrUint16Des);
32
33void CsrUint32Des(u32 *value, u8 *buffer, size_t *offset)
34{
35    *value = (buffer[*offset + 0] << 0) |
36             (buffer[*offset + 1] << 8) |
37             (buffer[*offset + 2] << 16) |
38             (buffer[*offset + 3] << 24);
39    *offset += sizeof(*value);
40}
41EXPORT_SYMBOL_GPL(CsrUint32Des);
42
43void CsrMemCpyDes(void *value, u8 *buffer, size_t *offset, size_t length)
44{
45    memcpy(value, &buffer[*offset], length);
46    *offset += length;
47}
48EXPORT_SYMBOL_GPL(CsrMemCpyDes);
49
50void CsrCharStringDes(char **value, u8 *buffer, size_t *offset)
51{
52    *value = kstrdup((char *) &buffer[*offset], GFP_KERNEL);
53    *offset += strlen(*value) + 1;
54}
55EXPORT_SYMBOL_GPL(CsrCharStringDes);
56
57void CsrUint8Ser(u8 *buffer, size_t *offset, u8 value)
58{
59    buffer[*offset] = value;
60    *offset += sizeof(value);
61}
62EXPORT_SYMBOL_GPL(CsrUint8Ser);
63
64void CsrUint16Ser(u8 *buffer, size_t *offset, u16 value)
65{
66    buffer[*offset + 0] = (u8) ((value >> 0) & 0xFF);
67    buffer[*offset + 1] = (u8) ((value >> 8) & 0xFF);
68    *offset += sizeof(value);
69}
70EXPORT_SYMBOL_GPL(CsrUint16Ser);
71
72void CsrUint32Ser(u8 *buffer, size_t *offset, u32 value)
73{
74    buffer[*offset + 0] = (u8) ((value >> 0) & 0xFF);
75    buffer[*offset + 1] = (u8) ((value >> 8) & 0xFF);
76    buffer[*offset + 2] = (u8) ((value >> 16) & 0xFF);
77    buffer[*offset + 3] = (u8) ((value >> 24) & 0xFF);
78    *offset += sizeof(value);
79}
80EXPORT_SYMBOL_GPL(CsrUint32Ser);
81
82void CsrMemCpySer(u8 *buffer, size_t *offset, const void *value, size_t length)
83{
84    memcpy(&buffer[*offset], value, length);
85    *offset += length;
86}
87EXPORT_SYMBOL_GPL(CsrMemCpySer);
88
89void CsrCharStringSer(u8 *buffer, size_t *offset, const char *value)
90{
91    if (value)
92    {
93        strcpy(((char *) &buffer[*offset]), value);
94        *offset += strlen(value) + 1;
95    }
96    else
97    {
98        CsrUint8Ser(buffer, offset, 0);
99    }
100}
101EXPORT_SYMBOL_GPL(CsrCharStringSer);
102

Archive Download this file



interactive