Root/drivers/staging/csr/csr_wifi_serialize_primitive_types.c

1/*****************************************************************************
2
3            (c) Cambridge Silicon Radio Limited 2011
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_macro.h"
14#include "csr_msgconv.h"
15#include "csr_wifi_msgconv.h"
16#include "csr_wifi_lib.h"
17
18void CsrUint24Des(u32 *v, u8 *buffer, size_t *offset)
19{
20    u32 val;
21
22    val = ((buffer[(*offset) + 2] << 16) |
23           (buffer[(*offset) + 1] << 8) |
24           (buffer[(*offset)]));
25
26    *offset += 3;
27    *v = val;
28}
29
30
31/* Big endian :e.g WSC, TCLAS */
32void CsrUint16DesBigEndian(u16 *v, u8 *buffer, size_t *offset)
33{
34    u16 val;
35
36    val = (buffer[(*offset)] << 8) | (buffer[(*offset) + 1]);
37    *offset += 2;
38
39    *v = val;
40}
41
42
43void CsrUint24DesBigEndian(u32 *v, u8 *buffer, size_t *offset)
44{
45    u32 val;
46
47    val = ((buffer[(*offset)] << 16) |
48           (buffer[(*offset) + 1] << 8) |
49           (buffer[(*offset) + 2]));
50
51    *offset += 3;
52    *v = val;
53}
54
55
56void CsrUint32DesBigEndian(u32 *v, u8 *buffer, size_t *offset)
57{
58    u32 val;
59
60    val = ((buffer[(*offset)] << 24) |
61           (buffer[(*offset) + 1] << 16) |
62           (buffer[(*offset) + 2] << 8) |
63           (buffer[(*offset) + 3]));
64
65    *offset += 4;
66    *v = val;
67}
68
69
70void CsrUint24Ser(u8 *ptr, size_t *len, u32 v)
71{
72    ptr[(*len) + 2] = (u8)((v & 0x00ff0000) >> 16);
73    ptr[(*len) + 1] = (u8)((v & 0x0000ff00) >> 8);
74    ptr[(*len)] = (u8)((v & 0x000000ff));
75
76    *len += 3;
77}
78
79
80/* Big endian :e.g WSC, TCLAS */
81void CsrUint16SerBigEndian(u8 *ptr, size_t *len, u16 v)
82{
83    ptr[(*len)] = (u8)((v & 0xff00) >> 8);
84    ptr[(*len) + 1] = (u8)((v & 0x00ff));
85
86    *len += 2;
87}
88
89
90void CsrUint32SerBigEndian(u8 *ptr, size_t *len, u32 v)
91{
92    ptr[(*len)] = (u8)((v & 0xff000000) >> 24);
93    ptr[(*len) + 1] = (u8)((v & 0x00ff0000) >> 16);
94    ptr[(*len) + 2] = (u8)((v & 0x0000ff00) >> 8);
95    ptr[(*len) + 3] = (u8)((v & 0x000000ff));
96
97    *len += 4;
98}
99
100
101void CsrUint24SerBigEndian(u8 *ptr, size_t *len, u32 v)
102{
103    ptr[(*len)] = (u8)((v & 0x00ff0000) >> 16);
104    ptr[(*len) + 1] = (u8)((v & 0x0000ff00) >> 8);
105    ptr[(*len) + 2] = (u8)((v & 0x000000ff));
106
107    *len += 3;
108}
109
110
111size_t CsrWifiEventSizeof(void *msg)
112{
113    return 2;
114}
115EXPORT_SYMBOL_GPL(CsrWifiEventSizeof);
116
117u8* CsrWifiEventSer(u8 *ptr, size_t *len, void *msg)
118{
119    CsrWifiFsmEvent *primitive = (CsrWifiFsmEvent *)msg;
120    *len = 0;
121    CsrUint16Ser(ptr, len, primitive->type);
122    return(ptr);
123}
124EXPORT_SYMBOL_GPL(CsrWifiEventSer);
125
126void* CsrWifiEventDes(u8 *buffer, size_t length)
127{
128    CsrWifiFsmEvent *primitive = kmalloc(sizeof(CsrWifiFsmEvent), GFP_KERNEL);
129    size_t offset = 0;
130    CsrUint16Des(&primitive->type, buffer, &offset);
131
132    return primitive;
133}
134EXPORT_SYMBOL_GPL(CsrWifiEventDes);
135
136size_t CsrWifiEventCsrUint8Sizeof(void *msg)
137{
138    return 3;
139}
140EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint8Sizeof);
141
142u8* CsrWifiEventCsrUint8Ser(u8 *ptr, size_t *len, void *msg)
143{
144    CsrWifiEventCsrUint8 *primitive = (CsrWifiEventCsrUint8 *)msg;
145    *len = 0;
146    CsrUint16Ser(ptr, len, primitive->common.type);
147    CsrUint8Ser(ptr, len, primitive->value);
148    return(ptr);
149}
150EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint8Ser);
151
152
153void* CsrWifiEventCsrUint8Des(u8 *buffer, size_t length)
154{
155    CsrWifiEventCsrUint8 *primitive = kmalloc(sizeof(CsrWifiEventCsrUint8), GFP_KERNEL);
156
157    size_t offset = 0;
158    CsrUint16Des(&primitive->common.type, buffer, &offset);
159    CsrUint8Des(&primitive->value, buffer, &offset);
160
161    return primitive;
162}
163EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint8Des);
164
165
166size_t CsrWifiEventCsrUint16Sizeof(void *msg)
167{
168    return 4;
169}
170EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16Sizeof);
171
172
173u8* CsrWifiEventCsrUint16Ser(u8 *ptr, size_t *len, void *msg)
174{
175    CsrWifiEventCsrUint16 *primitive = (CsrWifiEventCsrUint16 *)msg;
176    *len = 0;
177    CsrUint16Ser(ptr, len, primitive->common.type);
178    CsrUint16Ser(ptr, len, primitive->value);
179    return(ptr);
180}
181EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16Ser);
182
183void* CsrWifiEventCsrUint16Des(u8 *buffer, size_t length)
184{
185    CsrWifiEventCsrUint16 *primitive = kmalloc(sizeof(CsrWifiEventCsrUint16), GFP_KERNEL);
186
187    size_t offset = 0;
188    CsrUint16Des(&primitive->common.type, buffer, &offset);
189    CsrUint16Des(&primitive->value, buffer, &offset);
190
191    return primitive;
192}
193EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16Des);
194
195
196size_t CsrWifiEventCsrUint32Sizeof(void *msg)
197{
198    return 6;
199}
200EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint32Sizeof);
201
202u8* CsrWifiEventCsrUint32Ser(u8 *ptr, size_t *len, void *msg)
203{
204    CsrWifiEventCsrUint32 *primitive = (CsrWifiEventCsrUint32 *)msg;
205    *len = 0;
206    CsrUint16Ser(ptr, len, primitive->common.type);
207    CsrUint32Ser(ptr, len, primitive->value);
208    return(ptr);
209}
210EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint32Ser);
211
212
213void* CsrWifiEventCsrUint32Des(u8 *buffer, size_t length)
214{
215    CsrWifiEventCsrUint32 *primitive = kmalloc(sizeof(CsrWifiEventCsrUint32), GFP_KERNEL);
216
217    size_t offset = 0;
218    CsrUint16Des(&primitive->common.type, buffer, &offset);
219    CsrUint32Des(&primitive->value, buffer, &offset);
220
221    return primitive;
222}
223EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint32Des);
224
225size_t CsrWifiEventCsrUint16CsrUint8Sizeof(void *msg)
226{
227    return 5;
228}
229EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16CsrUint8Sizeof);
230
231u8* CsrWifiEventCsrUint16CsrUint8Ser(u8 *ptr, size_t *len, void *msg)
232{
233    CsrWifiEventCsrUint16CsrUint8 *primitive = (CsrWifiEventCsrUint16CsrUint8 *)msg;
234    *len = 0;
235    CsrUint16Ser(ptr, len, primitive->common.type);
236    CsrUint16Ser(ptr, len, primitive->value16);
237    CsrUint8Ser(ptr, len, primitive->value8);
238    return(ptr);
239}
240EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16CsrUint8Ser);
241
242
243void* CsrWifiEventCsrUint16CsrUint8Des(u8 *buffer, size_t length)
244{
245    CsrWifiEventCsrUint16CsrUint8 *primitive = kmalloc(sizeof(CsrWifiEventCsrUint16CsrUint8), GFP_KERNEL);
246
247    size_t offset = 0;
248    CsrUint16Des(&primitive->common.type, buffer, &offset);
249    CsrUint16Des(&primitive->value16, buffer, &offset);
250    CsrUint8Des(&primitive->value8, buffer, &offset);
251
252    return primitive;
253}
254EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16CsrUint8Des);
255
256
257

Archive Download this file



interactive