Commit | Line | Data |
---|---|---|
635d2b00 GKH |
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> | |
786eeeb3 | 12 | #include <linux/slab.h> |
d63123fc | 13 | #include "csr_macro.h" |
635d2b00 GKH |
14 | #include "csr_msgconv.h" |
15 | #include "csr_wifi_msgconv.h" | |
16 | #include "csr_wifi_lib.h" | |
17 | ||
d4fda8db | 18 | void CsrUint24Des(u32 *v, u8 *buffer, size_t *offset) |
635d2b00 | 19 | { |
26a6b2e1 | 20 | u32 val; |
635d2b00 GKH |
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 */ | |
d4fda8db | 32 | void CsrUint16DesBigEndian(u16 *v, u8 *buffer, size_t *offset) |
635d2b00 | 33 | { |
8c87f69a | 34 | u16 val; |
635d2b00 GKH |
35 | |
36 | val = (buffer[(*offset)] << 8) | (buffer[(*offset) + 1]); | |
37 | *offset += 2; | |
38 | ||
39 | *v = val; | |
40 | } | |
41 | ||
42 | ||
d4fda8db | 43 | void CsrUint24DesBigEndian(u32 *v, u8 *buffer, size_t *offset) |
635d2b00 | 44 | { |
26a6b2e1 | 45 | u32 val; |
635d2b00 GKH |
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 | ||
d4fda8db | 56 | void CsrUint32DesBigEndian(u32 *v, u8 *buffer, size_t *offset) |
635d2b00 | 57 | { |
26a6b2e1 | 58 | u32 val; |
635d2b00 GKH |
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 | ||
d4fda8db | 70 | void CsrUint24Ser(u8 *ptr, size_t *len, u32 v) |
635d2b00 | 71 | { |
7e6f5794 GKH |
72 | ptr[(*len) + 2] = (u8)((v & 0x00ff0000) >> 16); |
73 | ptr[(*len) + 1] = (u8)((v & 0x0000ff00) >> 8); | |
74 | ptr[(*len)] = (u8)((v & 0x000000ff)); | |
635d2b00 GKH |
75 | |
76 | *len += 3; | |
77 | } | |
78 | ||
79 | ||
80 | /* Big endian :e.g WSC, TCLAS */ | |
d4fda8db | 81 | void CsrUint16SerBigEndian(u8 *ptr, size_t *len, u16 v) |
635d2b00 | 82 | { |
7e6f5794 GKH |
83 | ptr[(*len)] = (u8)((v & 0xff00) >> 8); |
84 | ptr[(*len) + 1] = (u8)((v & 0x00ff)); | |
635d2b00 GKH |
85 | |
86 | *len += 2; | |
87 | } | |
88 | ||
89 | ||
d4fda8db | 90 | void CsrUint32SerBigEndian(u8 *ptr, size_t *len, u32 v) |
635d2b00 | 91 | { |
7e6f5794 GKH |
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)); | |
635d2b00 GKH |
96 | |
97 | *len += 4; | |
98 | } | |
99 | ||
100 | ||
d4fda8db | 101 | void CsrUint24SerBigEndian(u8 *ptr, size_t *len, u32 v) |
635d2b00 | 102 | { |
7e6f5794 GKH |
103 | ptr[(*len)] = (u8)((v & 0x00ff0000) >> 16); |
104 | ptr[(*len) + 1] = (u8)((v & 0x0000ff00) >> 8); | |
105 | ptr[(*len) + 2] = (u8)((v & 0x000000ff)); | |
635d2b00 GKH |
106 | |
107 | *len += 3; | |
108 | } | |
109 | ||
110 | ||
d4fda8db | 111 | size_t CsrWifiEventSizeof(void *msg) |
635d2b00 GKH |
112 | { |
113 | return 2; | |
114 | } | |
115 | EXPORT_SYMBOL_GPL(CsrWifiEventSizeof); | |
116 | ||
d4fda8db | 117 | u8* CsrWifiEventSer(u8 *ptr, size_t *len, void *msg) |
635d2b00 GKH |
118 | { |
119 | CsrWifiFsmEvent *primitive = (CsrWifiFsmEvent *)msg; | |
120 | *len = 0; | |
121 | CsrUint16Ser(ptr, len, primitive->type); | |
122 | return(ptr); | |
123 | } | |
124 | EXPORT_SYMBOL_GPL(CsrWifiEventSer); | |
125 | ||
d4fda8db | 126 | void* CsrWifiEventDes(u8 *buffer, size_t length) |
635d2b00 | 127 | { |
786eeeb3 | 128 | CsrWifiFsmEvent *primitive = kmalloc(sizeof(CsrWifiFsmEvent), GFP_KERNEL); |
d4fda8db | 129 | size_t offset = 0; |
635d2b00 GKH |
130 | CsrUint16Des(&primitive->type, buffer, &offset); |
131 | ||
132 | return primitive; | |
133 | } | |
134 | EXPORT_SYMBOL_GPL(CsrWifiEventDes); | |
135 | ||
d4fda8db | 136 | size_t CsrWifiEventCsrUint8Sizeof(void *msg) |
635d2b00 GKH |
137 | { |
138 | return 3; | |
139 | } | |
140 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint8Sizeof); | |
141 | ||
d4fda8db | 142 | u8* CsrWifiEventCsrUint8Ser(u8 *ptr, size_t *len, void *msg) |
635d2b00 GKH |
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 | } | |
150 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint8Ser); | |
151 | ||
152 | ||
d4fda8db | 153 | void* CsrWifiEventCsrUint8Des(u8 *buffer, size_t length) |
635d2b00 | 154 | { |
786eeeb3 | 155 | CsrWifiEventCsrUint8 *primitive = kmalloc(sizeof(CsrWifiEventCsrUint8), GFP_KERNEL); |
635d2b00 | 156 | |
d4fda8db | 157 | size_t offset = 0; |
635d2b00 GKH |
158 | CsrUint16Des(&primitive->common.type, buffer, &offset); |
159 | CsrUint8Des(&primitive->value, buffer, &offset); | |
160 | ||
161 | return primitive; | |
162 | } | |
163 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint8Des); | |
164 | ||
165 | ||
d4fda8db | 166 | size_t CsrWifiEventCsrUint16Sizeof(void *msg) |
635d2b00 GKH |
167 | { |
168 | return 4; | |
169 | } | |
170 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16Sizeof); | |
171 | ||
172 | ||
d4fda8db | 173 | u8* CsrWifiEventCsrUint16Ser(u8 *ptr, size_t *len, void *msg) |
635d2b00 GKH |
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 | } | |
181 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16Ser); | |
182 | ||
d4fda8db | 183 | void* CsrWifiEventCsrUint16Des(u8 *buffer, size_t length) |
635d2b00 | 184 | { |
786eeeb3 | 185 | CsrWifiEventCsrUint16 *primitive = kmalloc(sizeof(CsrWifiEventCsrUint16), GFP_KERNEL); |
635d2b00 | 186 | |
d4fda8db | 187 | size_t offset = 0; |
635d2b00 GKH |
188 | CsrUint16Des(&primitive->common.type, buffer, &offset); |
189 | CsrUint16Des(&primitive->value, buffer, &offset); | |
190 | ||
191 | return primitive; | |
192 | } | |
193 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16Des); | |
194 | ||
195 | ||
d4fda8db | 196 | size_t CsrWifiEventCsrUint32Sizeof(void *msg) |
635d2b00 GKH |
197 | { |
198 | return 6; | |
199 | } | |
200 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint32Sizeof); | |
201 | ||
d4fda8db | 202 | u8* CsrWifiEventCsrUint32Ser(u8 *ptr, size_t *len, void *msg) |
635d2b00 GKH |
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 | } | |
210 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint32Ser); | |
211 | ||
212 | ||
d4fda8db | 213 | void* CsrWifiEventCsrUint32Des(u8 *buffer, size_t length) |
635d2b00 | 214 | { |
786eeeb3 | 215 | CsrWifiEventCsrUint32 *primitive = kmalloc(sizeof(CsrWifiEventCsrUint32), GFP_KERNEL); |
635d2b00 | 216 | |
d4fda8db | 217 | size_t offset = 0; |
635d2b00 GKH |
218 | CsrUint16Des(&primitive->common.type, buffer, &offset); |
219 | CsrUint32Des(&primitive->value, buffer, &offset); | |
220 | ||
221 | return primitive; | |
222 | } | |
223 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint32Des); | |
224 | ||
d4fda8db | 225 | size_t CsrWifiEventCsrUint16CsrUint8Sizeof(void *msg) |
635d2b00 GKH |
226 | { |
227 | return 5; | |
228 | } | |
229 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16CsrUint8Sizeof); | |
230 | ||
d4fda8db | 231 | u8* CsrWifiEventCsrUint16CsrUint8Ser(u8 *ptr, size_t *len, void *msg) |
635d2b00 GKH |
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 | } | |
240 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16CsrUint8Ser); | |
241 | ||
242 | ||
d4fda8db | 243 | void* CsrWifiEventCsrUint16CsrUint8Des(u8 *buffer, size_t length) |
635d2b00 | 244 | { |
786eeeb3 | 245 | CsrWifiEventCsrUint16CsrUint8 *primitive = kmalloc(sizeof(CsrWifiEventCsrUint16CsrUint8), GFP_KERNEL); |
635d2b00 | 246 | |
d4fda8db | 247 | size_t offset = 0; |
635d2b00 GKH |
248 | CsrUint16Des(&primitive->common.type, buffer, &offset); |
249 | CsrUint16Des(&primitive->value16, buffer, &offset); | |
250 | CsrUint8Des(&primitive->value8, buffer, &offset); | |
251 | ||
252 | return primitive; | |
253 | } | |
254 | EXPORT_SYMBOL_GPL(CsrWifiEventCsrUint16CsrUint8Des); | |
255 | ||
256 |