blob: 2d84f7e674534dfe60c2539b552bb886d15c9228 [file] [log] [blame]
Ivan Kluchnikov487a1412011-12-21 13:17:53 +03001/* csn1.h
2 * Declarations and types for CSN1 dissection in wireshark.
3 * By Vincent Helfre, based on original code by Jari Sassi
4 * with the gracious authorization of STE
5 * Copyright (c) 2011 ST-Ericsson
6 *
7 * $Id: packet-csn1.h 36306 2011-03-24 09:20:14Z etxrab $
8 *
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 */
27
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +040028#include <bitvector.h>
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030029#include <iostream>
30#include <cstdlib>
31#ifndef _PACKET_CSN1_H_
32#define _PACKET_CSN1_H_
33
34
35#define MIN(a,b) (((a)<(b))?(a):(b))
36//#define max(a,b) (((a)>(b))?(a):(b))
37
38/* Error codes */
39#define CSN_OK 0
40#define CSN_ERROR_GENERAL -1
41#define CSN_ERROR_DATA_NOT_VALID -2
42#define CSN_ERROR_IN_SCRIPT -3
43#define CSN_ERROR_INVALID_UNION_INDEX -4
44#define CSN_ERROR_NEED_MORE_BITS_TO_UNPACK -5
45#define CSN_ERROR_ILLEGAL_BIT_VALUE -6
46#define CSN_ERROR_INTERNAL -7
47#define CSN_ERROR_STREAM_NOT_SUPPORTED -8
48#define CSN_ERROR_MESSAGE_TOO_LONG -9
49#define CSN_ERROR_ -10
50
51#define FALSE (0)
52typedef signed int gint32;
53typedef signed short gint16;
54typedef int gint;
55typedef gint gboolean;
56typedef unsigned char guint8;
57typedef unsigned short guint16;
58typedef unsigned int guint32;
59typedef unsigned long guint64;
60/* CallBack return status */
61typedef gint16 CSN_CallBackStatus_t;
62
63#define CSNCBS_OK 0
64#define CSNCBS_NOT_OK -10
65#define CSNCBS_NOT_TO_US -11
66#define CSNCBS_NOT_COMPLETE -12
67
68#define CSNCBS_REVISION_LIMIT_STOP -20 /* Stop packing/unpacking - revision limit */
69#define CSNCBS_NOT_SUPPORTED_IE -21 /* Handling of the unpacked IE is not supported by MS-software */
70
71
72
73#ifndef ElementsOf
74#define ElementsOf(array) (sizeof(array) / sizeof(array[0]))
75#endif
76
77/* Context holding CSN1 parameters */
78typedef struct
79{
80 gint remaining_bits_len; /* IN to an csn stream operation */
81 gint bit_offset; /* IN/OUT to an csn stream operation */
82 gint direction; /* 0 - decode; 1 - encode */
83} csnStream_t;
84
Ivan Kluchnikov9b06ff02012-06-15 10:13:30 +040085typedef gint16 (*StreamSerializeFcn_t)(csnStream_t* ar, bitvec *vector, unsigned& readIndex, void* data);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030086typedef enum
87{
88 CSN_END = 0,
89 CSN_BIT,
90 CSN_UINT,
91 CSN_TYPE,
92 CSN_CHOICE,
93 CSN_UNION,
94 CSN_UNION_LH,
95 CSN_UINT_ARRAY,
96 CSN_TYPE_ARRAY,
97 CSN_BITMAP, /* Bitmap with constant: <bitmap: bit(64)> */
98 CSN_VARIABLE_BITMAP, /* <N: bit (5)> <bitmap: bit(N + offset)> */
99 CSN_VARIABLE_BITMAP_1, /* <bitmap: bit**> i.e. to the end of message (R99) */
100 CSN_LEFT_ALIGNED_VAR_BMP, /* As variable bitmap but the result is left aligned (R99) */
101 CSN_LEFT_ALIGNED_VAR_BMP_1,/* As above only size is to the end of message (R99) */
102 CSN_VARIABLE_ARRAY, /* Array with length specified in parameter: <N: bit(4)> <list: octet(N + offset)> */
103 CSN_VARIABLE_TARRAY, /* Type Array with length specified in parameter: <N: bit(x)> <Type>*N */
104 CSN_VARIABLE_TARRAY_OFFSET,/* As above but with offset. The offset is stored as third parameter of CSN_DESCR (descr.value) */
105 CSN_RECURSIVE_ARRAY, /* Recursive way to specify an array of uint: <list> ::= {1 <number: bit(4) <list>|0}; */
106 CSN_RECURSIVE_TARRAY, /* Recursive way to specify an array of type: <list> ::= {1 <type>} ** 0 ; */
107 CSN_RECURSIVE_TARRAY_1, /* same as above but first element always exist:<list> ::= <type> {1 <type>} ** 0 ; */
108 CSN_RECURSIVE_TARRAY_2, /* same as above but with reversed separators :<lists> ::= <type> { 0 <type> } ** 1 ; */
109 CSN_EXIST,
110 CSN_EXIST_LH,
111 CSN_NEXT_EXIST,
112 CSN_NEXT_EXIST_LH,
113 CSN_NULL,
114 CSN_FIXED,
115 CSN_CALLBACK,
116 CSN_UINT_OFFSET, /* unpack will add offset, inverse pack will subtract offset */
117 CSN_UINT_LH, /* Low High extraction of int */
118 CSN_SERIALIZE,
119 CSN_TRAP_ERROR
120} csn_type_t;
121
122/******************************************************************************************
123 * CSN_DESCR structure:
124 *
125 * type:
126 * This is the CSN type. All existing types are specified in the section above.
127 *
128 * i:
129 * Depending on the contents of the type parameter, the parameter "i" may have following meaning:
130 * - specifies the number of bits for the CSN_UINT type
131 * - the offset for an array size by which the size is incremented
132 * for the CSN_VAR_ARRAY type
133 * - the length of each element of an array for the CSN_REC_ARRAY type
134 * - the number of the elements in an array for the CSN_TYPE_ARRAY type
135 * - the offset to the variable keeping the number of elements of an array for in the CSN_VAR_TARRAY type
136 * - the number of different data types in a union for the CSN_UNION, CSN_UNION_LH, and for the CSN_CHOICE types
137 * - the length in bits of the fixed number defined for the CSN_FIXED type
138 * - the number of lines to skip in the CSN_DESCR type specified for the CSN_NEXT_EXIST, CSN_NEXT_EXIST_LH,
139 * CSN_NEXT_EXIST_OR_NULL, and CSN_NEXT_EXIST_OR_NULL_LH types
140 * - the number of bits in a bitmap for the CSN_BITMAP type
141 * - the value by which the number of bits in a bitmap has to be incremented or decremented for the
142 * CSN_VAR_BITMAP, CSN_LEFT_VAR_BMP, and CSN_LEFT_BMP_1 types
143 * - the offset to param1 for the CSN_CALLBACK type
144 * - ERRORCODE used by the CSN_ERROR type
145 *
146 * descr
147 * This parameter has different meaning depending on the value of the type parameter:
148 * - the offset for the CSN_UINT_OFFSET type
149 * - the number of the elements in an array of the CSN_UINT_ARRAY type
150 * - the offset to the parameter where the size of the array has to be stored for the CSN_REC_ARRAY type
151 * - the address of the internal structure, describing the member type (by means of the CSN_DESCR type) in the
152 * CSN_TYPE_ARRAY, CSN_VAR_TARRAY, and CSN_TYPE types
153 * - the address of the variable of type CSN_ChoiceElement_t describing all elements in the CSN_CHOICE type union
154 * - the offset to the variable where the number of bits has to be or is stored for the CSN_VAR_BITMAP,
155 * CSN_LEFT_VAR_BMP, and CSN_LEFT_BMP_1 types
156 * - the function number (case number) for the CSN_CALLBACK and CSN_CALLBACK_NO_ARGS types
157 * - the free text used by the CSN_TRAP_ERROR
158 *
159 * offset
160 * This is an offset to the _MEMBER parameter counting from the beginning of struct
161 * where the unpacked or packed value shall be stored or fetched. The meaning of the _MEMBER parameter
162 * varies depending on the type which is specified and so is the meaning of the offset parameter.
163 * Some types (and corresponding macros) do not have the _MEMBER parameter and then the offset parameter
164 * is not used or is different from the offset to the _MEMBER.
165 * - the fixed value for the CSN_FIXED type
166 * - an offset to the variable UnionType for CSN_UNION and CSN_UNION_LH types
167 * - an offset to the variable Exist for CSN_NEXT_EXIST and CSN_NEXT_EXIST_LH types
168 * - an offset to param2 in the CSN_CALLBACK type
169 *
170 * sz
171 * - is the name of the parameter within the descr where their unpacked or packed value shall be stored or fetched.
172 * This paramater is pointed out by the offset parameter in the same CSN_DESCR variable as the sz.
173 * - the free text used by the CSN_TRAP_ERROR (the same as parameter "i")
174 *
175 * serialize
176 * - stores the size of _MEMBER type in case of the M_TYPE_ARRAY and M_VAR_TARRAY,
177 * - the address of the function which is provided by the M_SERIALIZE type.
178 ******************************************************************************************/
179
180
181typedef struct
182{
183 gint16 type;
184 gint16 i;
185 union
186 {
187 void* ptr;
188 guint32 value;
189 } descr;
Ivan Kluchnikov9b06ff02012-06-15 10:13:30 +0400190 unsigned offset;
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300191 const char* sz;
192 union
193 {
194 StreamSerializeFcn_t fcn;
195 guint32 value;
196 int* hf_ptr;
197 } serialize;
198} CSN_DESCR;
199
200typedef struct
201{
202 guint8 bits;
203 guint8 value;
204 CSN_DESCR descr;
205} CSN_ChoiceElement_t;
206
207void csnStreamInit(csnStream_t* ar,gint BitOffset,gint BitCount);
208
209/******************************************************************************
210* FUNCTION: csnStreamDecoder
211* DESCRIPTION:
212* UnPacks data from bit stream. According to CSN description.
213* ARGS:
214* ar stream will hold the parameters to the pack function
215* ar->remaining_bits_len [IN] Number of bits to unpack [OUT] number of bits left to unpack.
216* ar->bit_offset [IN/OUT] is the current bit where to proceed with the next bit to unpack.
217
218* pDescr CSN description.
219* tvb buffer containing the bit stream to unpack.
220* data unpacked data.
221* ett_csn1 tree
222*
223* RETURNS: int Number of bits left to be unpacked. Negative Error code if failed to unpack all bits
224******************************************************************************/
225
Ivan Kluchnikov9b06ff02012-06-15 10:13:30 +0400226gint16 csnStreamDecoder(csnStream_t* ar, const CSN_DESCR* pDescr, bitvec *vector, unsigned& readIndex, void* data);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300227
Ivan Kluchnikov9b06ff02012-06-15 10:13:30 +0400228gint16 csnStreamEncoder(csnStream_t* ar, const CSN_DESCR* pDescr, bitvec *vector, unsigned& readIndex, void* data);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300229
230/* CSN struct macro's */
231#define CSN_DESCR_BEGIN(_STRUCT)\
232 CSN_DESCR CSNDESCR_##_STRUCT[] = {
233
234#define CSN_DESCR_END(_STRUCT)\
235 {CSN_END, 0, {0}, 0, "", {(StreamSerializeFcn_t)0}} };
236
237/******************************************************************************
238 * CSN_ERROR(Par1, Par2, Par3)
239 * May be called at any time when an abort of packing or unpacking of a message
240 * is desired
241 * Par1: C structure name
242 * Par2: free text which will appear in the error handler
243 * Par3: Error code
244 *****************************************************************************/
245#define CSN_ERROR(_STRUCT, _Text, _ERRCODE)\
246 {CSN_TRAP_ERROR, _ERRCODE, {(void*)_Text}, 0, _Text, {(StreamSerializeFcn_t)0}}
247
248/******************************************************************************
249 * M_BIT(Par1, Par2)
250 * Defines one bit element in the CSN1 syntax.
251 * Par1: C structure name
252 * Par2: C structure element name
253 *****************************************************************************/
254#define M_BIT(_STRUCT, _MEMBER)\
255 {CSN_BIT, 0, {0}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
256
257/******************************************************************************
258 * M_NEXT_EXIST(Par1, Par2, Par3)
259 * Indicates whether the next element or a group of elements defined in the
260 * structure is present or not.
261 * Par1: C structure name
262 * Par2: C structure element name
263 * Par3: number of lines to skip in the CSN_DESCR type specified if the
264 * element(s) does not exist
265 *****************************************************************************/
266#define M_NEXT_EXIST(_STRUCT, _MEMBER, _NoOfExisting)\
267 {CSN_NEXT_EXIST, _NoOfExisting, {0}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
268
269/******************************************************************************
270 * M_NEXT_EXIST_LH(Par1, Par2, Par3)
271 * similar to the M_NEXT_EXIST except that instead of bit 0/1 which is fetched
272 * from the message in order to find out whether the next element/elements are
273 * present in the message, the logical operation XOR with the background
274 * pattern 0x2B is performed on the read bit before the decision is made.
275 *****************************************************************************/
276#define M_NEXT_EXIST_LH(_STRUCT, _MEMBER, _NoOfExisting)\
277 {CSN_NEXT_EXIST_LH, _NoOfExisting, {0}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
278
279/******************************************************************************
280 * M_NEXT_EXIST_OR_NULL(Par1, Par2, Par3)
281 * Similar to the M_NEXT_EXIST except that not only bit 0 or 1 but also the end
282 * of the message may be encountered when looking for the next element in the
283 * message.
284 * Covers the case {null | 0 | 1 < IE >}
285 *****************************************************************************/
286#define M_NEXT_EXIST_OR_NULL(_STRUCT, _MEMBER, _NoOfExisting)\
287 {CSN_NEXT_EXIST, _NoOfExisting, {(void*)1}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
288
289/******************************************************************************
290 * M_NEXT_EXIST_OR_NULL_LH(Par1, Par2, Par3)
291 * Similar to the M_NEXT_EXIST_LH except that not only bit 0 or 1 but also the
292 * end of the message may be encountered when looking for the next element in
293 * the message.
294 * Covers the case {null | L | H < IE >}
295 *****************************************************************************/
296#define M_NEXT_EXIST_OR_NULL_LH(_STRUCT, _MEMBER, _NoOfExisting)\
297 {CSN_NEXT_EXIST_LH, _NoOfExisting, {(void*)1}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
298
299/******************************************************************************
300 * M_UINT(Par1, Par2, Par3)
301 * Defines an integer number.
302 * Par1: C structure name
303 * Par2: C structure element name
304 * Par3: number of bits used to code the element (between 1 and 32)
305 *****************************************************************************/
306#define M_UINT(_STRUCT, _MEMBER, _BITS)\
307 {CSN_UINT, _BITS, {(void*)1}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
308
309/******************************************************************************
310 * M_UINT(Par1, Par2, Par3)
311 * This macro has the same functionality as M_UINT except that in addition the
312 * logical "exclusive or" operation with the background value "0x2B" is
313 * performed before the final value of the integer number is delivered from the
314 * received CSN.1 message
315 *****************************************************************************/
316#define M_UINT_LH(_STRUCT, _MEMBER, _BITS)\
317 {CSN_UINT_LH, _BITS, {(void*)1}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
318
319/******************************************************************************
320 * M_UINT_OFFSET(Par1, Par2, Par3, Par4)
321 * Defines an integer number.
322 * Par1: C structure name
323 * Par2: C structure element name
324 * Par3: number of bits used to code the element (between 1 and 32)
325 * Par4: value added to the returned integer (offset)
326 *****************************************************************************/
327#define M_UINT_OFFSET(_STRUCT, _MEMBER, _BITS, _OFFSET)\
328 {CSN_UINT_OFFSET, _BITS, {(void*)_OFFSET}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
329
330/******************************************************************************
331 * M_UINT_ARRAY(Par1, Par2, Par3, Par4)
332 * Defines an array of integer numbers. The size of the array is fixed.
333 * Par1: C structure name
334 * Par2: C structure element name
335 * Par3: number of bits used to code the each integer element (between 1 and 32)
336 * Par4: number of elements in the array (fixed integer value)
337 *****************************************************************************/
338#define M_UINT_ARRAY(_STRUCT, _MEMBER, _BITS, _ElementCount)\
339 {CSN_UINT_ARRAY, _BITS, {(void*)_ElementCount}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
340
341/******************************************************************************
342 * M_VAR_UINT_ARRAY(Par1, Par2, Par3, Par4)
343 * Defines an array of integer numbers. The size of the array is variable.
344 * Par1: C structure name
345 * Par2: C structure element name
346 * Par3: number of bits used to code the each integer element (between 1 and 32)
347 * Par4: number of elements in the array supplied by reference to the
348 * structure member holding the length value
349 *****************************************************************************/
350#define M_VAR_UINT_ARRAY(_STRUCT, _MEMBER, _BITS, _ElementCountField)\
351 {CSN_UINT_ARRAY, _BITS, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)1}}
352
353/******************************************************************************
354 * M_VAR_ARRAY(Par1, Par2, Par3, Par4)
355 * Defines an array of 8 bit large integer numbers. The size of the array is variable.
356 * Par1: C structure name
357 * Par2: C structure element name
358 * Par3: name of the structure member holding the size of the array
359 * Par4: offset that is added to the Par3 to get the actual size of the array
360 *****************************************************************************/
361#define M_VAR_ARRAY(_STRUCT, _MEMBER, _ElementCountField, _OFFSET)\
362 {CSN_VARIABLE_ARRAY, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
363
364/******************************************************************************
365 * M_VAR_TARRAY(Par1, Par2, Par3, Par4)
366 * Similar to M_TYPE_ARRAY except that the size of the array is variable.
367 * Par1: C structure name
368 * Par2: C structure element name
369 * Par3: the type of each element of the array
370 * Par4: name of the structure member holding the size of the array
371 *****************************************************************************/
372#define M_VAR_TARRAY(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField)\
373 {CSN_VARIABLE_TARRAY, offsetof(_STRUCT, _ElementCountField), {(void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)sizeof(_MEMBER_TYPE)}}
374
375/******************************************************************************
376 * M_VAR_TARRAY_OFFSET(Par1, Par2, Par3, Par4)
377 * Same as M_VAR_TARRAY with offset
378 *****************************************************************************/
379#define M_VAR_TARRAY_OFFSET(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField)\
380 {CSN_VARIABLE_TARRAY_OFFSET, offsetof(_STRUCT, _ElementCountField), {(void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)sizeof(_MEMBER_TYPE)}}
381
382/******************************************************************************
383 * M_REC_ARRAY(Par1, Par2, Par3, Par4)
384 * similar to the M_VAR_ARRAY. The difference is that the size of the array is
385 * not known in advance and it has to be calculated during unpacking. Its value
386 * is stored in a variable which belongs to the same structure as the array.
387 * A zero element terminates the array. The CSN.1 syntax describes it
388 * recursively as:
389 * <array> ::={1 <element> <array>| 0}
390 *
391 * Par1: C structure name
392 * Par2: C structure element name
393 * Par3: name of the structure member where the calculated the size of the
394 * array will be stored
395 * Par4: length of each element in bits
396 *****************************************************************************/
397#define M_REC_ARRAY(_STRUCT, _MEMBER, _ElementCountField, _BITS)\
398 {CSN_RECURSIVE_ARRAY, _BITS, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
399
400/******************************************************************************
401 * M_VAR_TYPE_ARRAY(Par1, Par2, Par3, Par4)
402 * Defines an array of structures. The size of the array is variable.
403 * Par1: C structure name
404 * Par2: C structure element name
405 * Par3: name of the structure
406 * Par4: number of elements in the array (fixed integer value)
407 *****************************************************************************/
408#define M_TYPE_ARRAY(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCount)\
409 {CSN_TYPE_ARRAY, _ElementCount, {(void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)sizeof(_MEMBER_TYPE)}}
410
411/******************************************************************************
412 * M_REC_TARRAY(Par1, Par2, Par3, Par4)
413 * Defines an recursive array of structures. The size of the array is variable.
414 * <list> ::= {1 <type>} ** 0 ;
415 * Par1: C structure name
416 * Par2: C structure element name
417 * Par3: name of the structure
418 * Par4: will hold the number of element in the array after unpacking
419 *****************************************************************************/
420#define M_REC_TARRAY(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField)\
421 {CSN_RECURSIVE_TARRAY, offsetof(_STRUCT, _ElementCountField), {(void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)sizeof(_MEMBER_TYPE)}}
422
423/******************************************************************************
424 * M_REC_TARRAY1(Par1, Par2, Par3, Par4)
425 * Same as M_REC_TARRAY but first element always exist:
426 * <list> ::= <type> {1 <type>} ** 0 ;
427 *****************************************************************************/
428#define M_REC_TARRAY_1(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField)\
429 {CSN_RECURSIVE_TARRAY_1, offsetof(_STRUCT, _ElementCountField), {(void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)sizeof(_MEMBER_TYPE)}}
430
431/******************************************************************************
432 * M_REC_TARRAY2(Par1, Par2, Par3, Par4)
433 * Same as M_REC_TARRAY but with reversed separators :
434 * <lists> ::= <type> { 0 <type> } ** 1 ;
435 *****************************************************************************/
436#define M_REC_TARRAY_2(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField)\
437 {CSN_RECURSIVE_TARRAY_2, offsetof(_STRUCT, _ElementCountField), {(void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)sizeof(_MEMBER_TYPE)}}
438
439/******************************************************************************
440 * M_TYPE(Par1, Par2, Par3)
441 * Defines a reference to a structure which is described elsewhere
442 * <list> ::= {1 <type>} ** 0 ;
443 * Par1: C structure name
444 * Par2: C structure element name
445 * Par3: type of member
446 *****************************************************************************/
447#define M_TYPE(_STRUCT, _MEMBER, _MEMBER_TYPE)\
448 {CSN_TYPE, 0, {(void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
449
450/******************************************************************************
451 * M_UNION(Par1, Par2)
452 * Informs the CSN.1 library that a union follows and how many possible choices
453 * there are in the union. The actual value of the choice, which points out the
454 * chosen element of the union is stored in the uint8 variable and is usually
455 * called UnionType. The elements of the union have to be listed directly after
456 * the M_UNION statement.
457 * Par1: C structure name
458 * Par2: number of possible choice in the union
459 *****************************************************************************/
460#define M_UNION(_STRUCT, _COUNT)\
461 {CSN_UNION, _COUNT, {0}, offsetof(_STRUCT, UnionType), "UnionType", {(StreamSerializeFcn_t)0}}
462
463/******************************************************************************
464 * M_UNION_LH(Par1, Par2)
465 * Same as M_UNION but masked with background value 0x2B
466 *****************************************************************************/
467#define M_UNION_LH(_STRUCT, _COUNT)\
468 {CSN_UNION_LH, _COUNT, {0}, offsetof(_STRUCT, UnionType), "UnionType", {(StreamSerializeFcn_t)0}}
469
470/******************************************************************************
471 * M_CHOICE(Par1, Par2, Par3, Par4)
472 * Similar to the M_UNION. In the M_UNION the selected element of all possible
473 * choices in the union is referred as a sequential numbers, i.e., the first
474 * choice is addressed as choice 0 the second as choice 1, the third as choice
475 * 2 and so on, both in the encoded message and in the variable UnionType which
476 * is the part of the message. In the CSN_CHOICE case, this rule does not
477 * apply. There is free but predefined mapping of the element of the union and
478 * the value which addresses this element.
479 * The value of the address is called a selector.
480 * After unpacking, this value is then converted to the sequential number of the
481 * element in the union and stored in the UnionType variable.
482 * Par1: C structure name
483 * Par2: C structure element name
484 * Par3: address of an array of type CSN_ChoiceElement_t where all possible
485 * values of the selector are provided, together with the selector
486 * length expressed in bits and the address of the CSN_DESCR type
487 * where the element is defined. For every element in the union
488 * there is one line in the Choice variable. These lines have to
489 * appear in the _CHOICE in the same order as the elements in the
490 * union. The element of the union selected in the message through
491 * the _CHOICE parameter is after unpacking translated to the
492 * corresponding sequential number of this element and stored in
493 * the variable pointed out by the _MEMBER
494 * Par4: number of possible choices in the union
495 *****************************************************************************/
496#define M_CHOICE(_STRUCT, _MEMBER, _CHOICE, _ElementCount)\
497 {CSN_CHOICE, _ElementCount, {(void*)_CHOICE}, offsetof(_STRUCT, _MEMBER), #_CHOICE, {(StreamSerializeFcn_t)0}}
498
499/******************************************************************************
500 * M_FIXED(Par1, Par2, Par3)
501 * Defines a fixed value of type integer which should be fetched from or stored
502 * in the message
503 * Par1: C structure name
504 * Par2: gives the length of the fixed number in bits.
505 * Par3: the value of the number. If the expected value is not present in
506* the message the unpacking procedure is aborted
507 *****************************************************************************/
508#define M_FIXED(_STRUCT, _BITS, _BITVALUE)\
509 {CSN_FIXED, _BITS, {0}, _BITVALUE, #_BITVALUE, {(StreamSerializeFcn_t)0}}
510
511/******************************************************************************
512 * M_SERIALIZE(Par1, Par2, Par3)
513 * Allows using a complete free format of data being encoded or decoded.
514 * When the M_SERIALIZE is uncounted during encoding or decoding of a message
515 * the CSNstream program passes the control over to the specified function
516 * together with all necessary parameters about the current position within
517 * the message being unpacked or packed. When transferring of "serialized"
518 * data to or from the message is finished by the function the CSNstream gets
519 * back control over the data stream and continues to work with the message.
520 *****************************************************************************/
521#define M_SERIALIZE(_STRUCT, _MEMBER, _SERIALIZEFCN)\
522 {CSN_SERIALIZE, 1, {0}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {_SERIALIZEFCN}}
523
524#define M_CALLBACK(_STRUCT, _CSNCALLBACKFCN, _PARAM1, _PARAM2)\
525 {CSN_CALLBACK, offsetof(_STRUCT, _PARAM1), {_CSNCALLBACKFCN}, offsetof(_STRUCT, _PARAM2), "CallBack_"#_CSNCALLBACKFCN, {(StreamSerializeFcn_t)0}}
526
527/******************************************************************************
528 * M_BITMAP(Par1, Par2, Par3)
529 * Defines a type which consists of a bitmap. The size of the bitmap in bits
530 * is fixed and provided by the parameter Par3
531 * Par1: C structure name
532 * Par2: C structure element name
533 * Par3: length of the bitmap expressed in bits
534 *****************************************************************************/
535#define M_BITMAP(_STRUCT, _MEMBER, _BITS)\
536 {CSN_BITMAP, _BITS, {0}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
537
538/* variable length, right aligned bitmap i.e. _ElementCountField = 11 => 00000111 11111111 */
539#define M_VAR_BITMAP(_STRUCT, _MEMBER, _ElementCountField, _OFFSET)\
540 {CSN_VARIABLE_BITMAP, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
541
542/* variable length, right aligned bitmap filling the rest of message
543 * - when unpacking the _ElementCountField will be set in runtime
544 * - when packing _ElementCountField contains the size of bitmap
545 */
546#define M_VAR_BITMAP_1(_STRUCT, _MEMBER, _ElementCountField, _OFFSET)\
547 {CSN_VARIABLE_BITMAP_1, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
548
549/* variable length, left aligned bitmap i.e. _ElementCountField = 11 => 11111111 11100000 */
550#define M_LEFT_VAR_BMP(_STRUCT, _MEMBER, _ElementCountField, _OFFSET)\
551 {CSN_LEFT_ALIGNED_VAR_BMP, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
552
553/* variable length, left aligned bitmap filling the rest of message
554 *- when unpacking the _ElementCountField will be set in runtime
555 * - when packing _ElementCountField contains the size of bitmap
556 */
557#define M_LEFT_VAR_BMP_1(_STRUCT, _MEMBER, _ElementCountField, _OFFSET)\
558 {CSN_LEFT_ALIGNED_VAR_BMP_1, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
559
560#define M_NULL(_STRUCT, _MEMBER)\
561 {CSN_NULL, 0, {0}, offsetof(_STRUCT, _MEMBER), #_MEMBER, {(StreamSerializeFcn_t)0}}
562
563#define M_THIS_EXIST(_STRUCT)\
564 {CSN_EXIST, 0, {0}, offsetof(_STRUCT, Exist), "Exist", {(StreamSerializeFcn_t)0}}
565
566#define M_THIS_EXIST_LH(_STRUCT)\
567 {CSN_EXIST_LH, 0, {0}, offsetof(_STRUCT, Exist), "Exist", {(StreamSerializeFcn_t)0}}
568
569/* return value 0 if ok else discontionue the unpacking */
570typedef gint16 (*CsnCallBackFcn_t)(void* pv ,...);
571
572#define CSNDESCR(_FuncType) CSNDESCR_##_FuncType
573
574#endif /*_PACKET_CSN1_H_*/