Wireshark 2.9.0-477-g68ec514b The Wireshark network protocol analyzer

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

packet-csn1.h
1 /* packet-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 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
14 #ifndef _PACKET_CSN1_H_
15 #define _PACKET_CSN1_H_
16
17 #include <epan/expert.h>
18
19 /* Error codes */
20 #define CSN_OK 0
21 #define CSN_ERROR_GENERAL -1
22 #define CSN_ERROR_DATA_NOT_VALID -2
23 #define CSN_ERROR_IN_SCRIPT -3
24 #define CSN_ERROR_INVALID_UNION_INDEX -4
25 #define CSN_ERROR_NEED_MORE_BITS_TO_UNPACK -5
26 #define CSN_ERROR_ILLEGAL_BIT_VALUE -6
27 #define CSN_ERROR_INTERNAL -7
28 #define CSN_ERROR_STREAM_NOT_SUPPORTED -8
29 #define CSN_ERROR_MESSAGE_TOO_LONG -9
30 #define CSN_ERROR_ -10
31
32 /* CallBack return status */
33 typedef gint16 CSN_CallBackStatus_t;
34
35 #define CSNCBS_OK 0
36 #define CSNCBS_NOT_OK -10
37 #define CSNCBS_NOT_TO_US -11
38 #define CSNCBS_NOT_COMPLETE -12
39
40 #define CSNCBS_REVISION_LIMIT_STOP -20 /* Stop packing/unpacking - revision limit */
41 #define CSNCBS_NOT_SUPPORTED_IE -21 /* Handling of the unpacked IE is not supported by MS-software */
42
43
44
45 #ifndef ElementsOf
46 #define ElementsOf(array) (sizeof(array) / sizeof(array[0]))
47 #endif
48 typedef void(*void_fn_t)(void);
49
50 /* Context holding CSN1 parameters */
51 typedef struct
52 {
53 gint remaining_bits_len; /* IN to an csn stream operation */
54 gint bit_offset; /* IN/OUT to an csn stream operation */
55 packet_info* pinfo;
56 } csnStream_t;
57
58 typedef gint16 (*StreamSerializeFcn_t)(proto_tree *tree, csnStream_t* ar, tvbuff_t *tvb, void* data, int ett_csn1);
59 typedef CSN_CallBackStatus_t (*DissectorCallbackFcn_t)(proto_tree *tree, tvbuff_t *tvb, void* param1, void* param2, int bit_offset, int ett_csn1, packet_info* pinfo);
60
61
62 typedef enum
63 {
64 CSN_END = 0,
65 CSN_BIT,
66 CSN_UINT,
67 CSN_TYPE,
68 CSN_CHOICE,
69 CSN_UNION,
70 CSN_UNION_LH,
71 CSN_UINT_ARRAY,
72 CSN_TYPE_ARRAY,
73 CSN_BITMAP, /* Bitmap with constant: <bitmap: bit(64)> */
74 CSN_VARIABLE_BITMAP, /* <N: bit (5)> <bitmap: bit(N + offset)> */
75 CSN_VARIABLE_BITMAP_1, /* <bitmap: bit**> i.e. to the end of message (R99) */
76 CSN_LEFT_ALIGNED_VAR_BMP, /* As variable bitmap but the result is left aligned (R99) */
77 CSN_LEFT_ALIGNED_VAR_BMP_1,/* As above only size is to the end of message (R99) */
78 CSN_PADDING_BITS, /* Padding bits fill to the end of the buffer */
79 CSN_VARIABLE_ARRAY, /* Array with length specified in parameter: <N: bit(4)> <list: octet(N + offset)> */
80 CSN_VARIABLE_TARRAY, /* Type Array with length specified in parameter: <N: bit(x)> <Type>*N */
81 CSN_VARIABLE_TARRAY_OFFSET,/* As above but with offset. The offset is stored as third parameter of CSN_DESCR (descr.value) */
82 CSN_RECURSIVE_ARRAY, /* Recursive way to specify an array of uint: <list> ::= {1 <number: bit(4) <list>|0}; */
83 CSN_RECURSIVE_TARRAY, /* Recursive way to specify an array of type: <list> ::= {1 <type>} ** 0 ; */
84 CSN_RECURSIVE_TARRAY_1, /* same as above but first element always exist:<list> ::= <type> {1 <type>} ** 0 ; */
85 CSN_RECURSIVE_TARRAY_2, /* same as above but with reversed separators :<lists> ::= <type> { 0 <type> } ** 1 ; */
86 CSN_EXIST,
87 CSN_EXIST_LH,
88 CSN_NEXT_EXIST,
89 CSN_NEXT_EXIST_LH,
90 CSN_NULL,
91 CSN_FIXED,
92 CSN_CALLBACK,
93 CSN_UINT_OFFSET, /* unpack will add offset, inverse pack will subtract offset */
94 CSN_UINT_LH, /* Low High extraction of int */
95 CSN_SERIALIZE,
96 CSN_SPLIT_BITS,
97 CSN_SPLIT_BITS_CRUMB,
98 CSN_TRAP_ERROR
99 } csn_type_t;
100
101 /******************************************************************************************
102 * CSN_DESCR structure:
103 *
104 * type:
105 * This is the CSN type. All existing types are specified in the section above.
106 *
107 * i:
108 * Depending on the contents of the type parameter, the parameter "i" may have following meaning:
109 * - specifies the number of bits for the CSN_UINT or CSN_UINT_OR_NULL types
110 * - the offset for an array size by which the size is incremented
111 * for the CSN_VAR_ARRAY type
112 * - the length of each element of an array for the CSN_REC_ARRAY type
113 * - the number of the elements in an array for the CSN_TYPE_ARRAY type
114 * - the offset to the variable keeping the number of elements of an array for in the CSN_VAR_TARRAY type
115 * - the number of different data types in a union for the CSN_UNION, CSN_UNION_LH, and for the CSN_CHOICE types
116 * - the length in bits of the fixed number defined for the CSN_FIXED type
117 * - the number of lines to skip in the CSN_DESCR type specified for the CSN_NEXT_EXIST, CSN_NEXT_EXIST_LH,
118 * CSN_NEXT_EXIST_OR_NULL, and CSN_NEXT_EXIST_OR_NULL_LH types
119 * - the number of bits in a bitmap for the CSN_BITMAP type
120 * - the value by which the number of bits in a bitmap has to be incremented or decremented for the
121 * CSN_VAR_BITMAP, CSN_LEFT_VAR_BMP, and CSN_LEFT_BMP_1 types
122 * - the offset to param1 for the CSN_CALLBACK type
123 * - ERRORCODE used by the CSN_ERROR type
124 * - the bit-lngth of the LENGTH field in a CSN_SERIALISE type
125 *
126 * descr
127 * This parameter has different meaning depending on the value of the type parameter:
128 * - the offset for the CSN_UINT_OFFSET type
129 * - the number of the elements in an array of the CSN_UINT_ARRAY type
130 * - the offset to the parameter where the size of the array has to be stored for the CSN_REC_ARRAY type
131 * - the address of the internal structure, describing the member type (by means of the CSN_DESCR type) in the
132 * CSN_TYPE_ARRAY, CSN_VAR_TARRAY, and CSN_TYPE types
133 * - the address of the variable of type CSN_ChoiceElement_t describing all elements in the CSN_CHOICE type union
134 * - the offset to the variable where the number of bits has to be or is stored for the CSN_VAR_BITMAP,
135 * CSN_LEFT_VAR_BMP, and CSN_LEFT_BMP_1 types
136 * - the function number (case number) for the CSN_CALLBACK and CSN_CALLBACK_NO_ARGS types
137 * - the free text used by the CSN_TRAP_ERROR
138 *
139 * offset
140 * This is an offset to the _MEMBER parameter counting from the beginning of struct
141 * where the unpacked or packed value shall be stored or fetched. The meaning of the _MEMBER parameter
142 * varies depending on the type which is specified and so is the meaning of the offset parameter.
143 * Some types (and corresponding macros) do not have the _MEMBER parameter and then the offset parameter
144 * is not used or is different from the offset to the _MEMBER.
145 * - the fixed value for the CSN_FIXED type
146 * - an offset to the variable UnionType for CSN_UNION and CSN_UNION_LH types
147 * - an offset to the variable Exist for CSN_NEXT_EXIST and CSN_NEXT_EXIST_LH types
148 * - an offset to param2 in the CSN_CALLBACK type
149 *
150 * may_be_null
151 * TRUE: if dissection may be attempted at an offset beyond the length of existing data bits
152 * FALSE: othewise
153 *
154 * sz
155 * - is the name of the parameter within the descr where their unpacked or packed value shall be stored or fetched.
156 * This paramater is pointed out by the offset parameter in the same CSN_DESCR variable as the sz.
157 * - the free text used by the CSN_TRAP_ERROR (the same as parameter "i")
158 *
159 * serialize
160 * - stores the size of _MEMBER type in case of the M_TYPE_ARRAY and M_VAR_TARRAY,
161 * - the address of the function which is provided by the M_SERIALIZE type.
162 ******************************************************************************************/
163
164
165 typedef struct
166 {
167 gint16 type;
168 gint16 i;
169 union
170 {
171 const void* ptr;
172 guint32 value;
173 const crumb_spec_t *crumb_spec;
174 } descr;
175 size_t offset;
176 gboolean may_be_null;
177 const char* sz;
178 expert_field* error;
179 guint32 value;
180 int* hf_ptr;
181 /* used in M_REC_ARRAY to distinguish between "field" and "field exists",
182 it's not used on fields that just "exist" */
183 int* hf_exist_ptr;
184 void_fn_t aux_fn;
185 } CSN_DESCR;
186
187 typedef struct
188 {
189 guint8 bits;
190 guint8 value;
191 gboolean keep_bits;
192 CSN_DESCR descr;
193 } CSN_ChoiceElement_t;
194
195 void csnStreamInit(csnStream_t* ar, gint BitOffset, gint BitCount, packet_info* pinfo);
196
197 /******************************************************************************
198 * FUNCTION: csnStreamDissector
199 * DESCRIPTION:
200 * UnPacks data from bit stream. According to CSN description.
201 * ARGS:
202 * ar stream will hold the parameters to the pack function
203 * ar->remaining_bits_len [IN] Number of bits to unpack [OUT] number of bits left to unpack.
204 * ar->bit_offset [IN/OUT] is the current bit where to proceed with the next bit to unpack.
205
206 * pDescr CSN description.
207 * tvb buffer containing the bit stream to unpack.
208 * data unpacked data.
209 * ett_csn1 tree
210 *
211 * RETURNS: int Number of bits left to be unpacked. Negative Error code if failed to unpack all bits
212 ******************************************************************************/
213 gint16 csnStreamDissector(proto_tree *tree, csnStream_t* ar, const CSN_DESCR* pDescr, tvbuff_t *tvb, void* data, int ett_csn1);
214
215 /* CSN struct macro's */
216 #define CSN_DESCR_BEGIN(_STRUCT)\
217 CSN_DESCR CSNDESCR_##_STRUCT[] = {
218
219 #define CSN_DESCR_END(_STRUCT)\
220 {CSN_END, 0, {0}, 0, FALSE, "", NULL, 0, NULL, NULL, NULL} };
221
222 /******************************************************************************
223 * CSN_ERROR(Par1, Par2, Par3)
224 * May be called at any time when an abort of packing or unpacking of a message
225 * is desired
226 * Par1: C structure name
227 * Par2: free text which will appear in the error handler
228 * Par3: Error code
229 *****************************************************************************/
230 #define CSN_ERROR(_STRUCT, _Text, _ERRCODE, _EI_ERROR)\
231 {CSN_TRAP_ERROR, _ERRCODE, {_Text}, 0, FALSE, _Text, _EI_ERROR, 0, NULL, NULL, NULL}
232
233 /******************************************************************************
234 * M_BIT(Par1, Par2, Par3)
235 * Defines one bit element in the CSN1 syntax.
236 * Par1: C structure name
237 * Par2: C structure element name
238 * Par3: pointer to the header field
239 *****************************************************************************/
240 #define M_BIT(_STRUCT, _MEMBER, _HF_PTR)\
241 {CSN_BIT, 0, {0}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
242
243 /******************************************************************************
244 * M_BIT_OR_NULL(Par1, Par2, Par3)
245 * Similar to the M_BIT except that not only bit 0 or 1 but also the
246 * end of the message may be encountered when looking for the next element in
247 * the message.
248 * Covers the case {null | 0 | 1}
249 *****************************************************************************/
250 #define M_BIT_OR_NULL(_STRUCT, _MEMBER, _HF_PTR)\
251 {CSN_BIT, 0, {0}, offsetof(_STRUCT, _MEMBER), TRUE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
252 /******************************************************************************
253 * M_NEXT_EXIST(Par1, Par2, Par3)
254 * Indicates whether the next element or a group of elements defined in the
255 * structure is present or not.
256 * Par1: C structure name
257 * Par2: C structure element name
258 * Par3: number of lines to skip in the CSN_DESCR type specified if the
259 * element(s) does not exist
260 *****************************************************************************/
261 #define M_NEXT_EXIST(_STRUCT, _MEMBER, _NoOfExisting, _HF_PTR)\
262 {CSN_NEXT_EXIST, _NoOfExisting, {0}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
263
264 /******************************************************************************
265 * M_NEXT_EXIST_LH(Par1, Par2, Par3)
266 * similar to the M_NEXT_EXIST except that instead of bit 0/1 which is fetched
267 * from the message in order to find out whether the next element/elements are
268 * present in the message, the logical operation XOR with the background
269 * pattern 0x2B is performed on the read bit before the decision is made.
270 *****************************************************************************/
271 #define M_NEXT_EXIST_LH(_STRUCT, _MEMBER, _NoOfExisting, _HF_PTR)\
272 {CSN_NEXT_EXIST_LH, _NoOfExisting, {0}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
273
274 /******************************************************************************
275 * M_NEXT_EXIST_OR_NULL(Par1, Par2, Par3)
276 * Similar to the M_NEXT_EXIST except that not only bit 0 or 1 but also the end
277 * of the message may be encountered when looking for the next element in the
278 * message.
279 * Covers the case {null | 0 | 1 < IE >}
280 *****************************************************************************/
281 #define M_NEXT_EXIST_OR_NULL(_STRUCT, _MEMBER, _NoOfExisting, _HF_PTR)\
282 {CSN_NEXT_EXIST, _NoOfExisting, {0}, offsetof(_STRUCT, _MEMBER), TRUE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
283
284 /******************************************************************************
285 * M_NEXT_EXIST_OR_NULL_LH(Par1, Par2, Par3)
286 * Similar to the M_NEXT_EXIST_LH except that not only bit 0 or 1 but also the
287 * end of the message may be encountered when looking for the next element in
288 * the message.
289 * Covers the case {null | L | H < IE >}
290 *****************************************************************************/
291 #define M_NEXT_EXIST_OR_NULL_LH(_STRUCT, _MEMBER, _NoOfExisting, _HF_PTR)\
292 {CSN_NEXT_EXIST_LH, _NoOfExisting, {(void*)1}, offsetof(_STRUCT, _MEMBER), TRUE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
293
294 /******************************************************************************
295 * M_UINT(Par1, Par2, Par3, Par4)
296 * Defines an integer number.
297 * Par1: C structure name
298 * Par2: C structure element name
299 * Par3: number of bits used to code the element (between 1 and 32)
300 * Par4: pointer to the header field
301 *****************************************************************************/
302 #define M_UINT(_STRUCT, _MEMBER, _BITS, _HF_PTR)\
303 {CSN_UINT, _BITS, {0}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
304
305 /******************************************************************************
306 * M_UINT_SPLIT(Par1, Par2, Par3, Par4)
307 * Defines an integer number split into segments which may be reordered or have gaps between them.
308 * Par1: C structure name
309 * Par2: C structure element name
310 * Par3: bits_spec_t array
311 * Par4: bit-width of the aggregate field
312 * Par4: pointer to the header field
313 *****************************************************************************/
314 #define M_SPLIT_BITS(_STRUCT, _MEMBER, _SPEC, _BITS, _HF_PTR)\
315 {CSN_SPLIT_BITS, _BITS, {_SPEC}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
316
317 /******************************************************************************
318 * M_NULL_SPLIT(Par1, Par2, Par3, Par4)
319 * Defines a subsequent segment of a split integer type.
320 * Par1: C structure name
321 * Par2: C structure element name
322 * Par3: bits_spec_t array
323 * Par4: segment number (0 based)
324 *****************************************************************************/
325 #define M_BITS_CRUMB(_STRUCT, _MEMBER, _SPEC, _SEG, _HF_PTR)\
326 {CSN_SPLIT_BITS_CRUMB, _SEG, {_SPEC}, 0, FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
327
328 /******************************************************************************
329 * M_UINT_OR_NULL(Par1, Par2, Par3, Par4)
330 * Similar to the M_UINT except that not only the request set of bits but also the
331 * end of the message may be encountered when looking for the next element in
332 * the message.
333 * Covers the case {null | 0 | 1 < IE >}
334 *****************************************************************************/
335 #define M_UINT_OR_NULL(_STRUCT, _MEMBER, _BITS, _HF_PTR)\
336 {CSN_UINT, _BITS, {0}, offsetof(_STRUCT, _MEMBER), TRUE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
337
338 /******************************************************************************
339 * M_UINT_LH(Par1, Par2, Par3, Par4)
340 * This macro has the same functionality as M_UINT except that in addition the
341 * logical "exclusive or" operation with the background value "0x2B" is
342 * performed before the final value of the integer number is delivered from the
343 * received CSN.1 message
344 *****************************************************************************/
345 #define M_UINT_LH(_STRUCT, _MEMBER, _BITS, _HF_PTR)\
346 {CSN_UINT_LH, _BITS, {0}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
347
348 /******************************************************************************
349 * M_UINT_OFFSET(Par1, Par2, Par3, Par4)
350 * Defines an integer number.
351 * Par1: C structure name
352 * Par2: C structure element name
353 * Par3: number of bits used to code the element (between 1 and 32)
354 * Par4: value added to the returned integer (offset)
355 *****************************************************************************/
356 #define M_UINT_OFFSET(_STRUCT, _MEMBER, _BITS, _OFFSET, _HF_PTR)\
357 {CSN_UINT_OFFSET, _BITS, {(void*)_OFFSET}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
358
359 /******************************************************************************
360 * M_UINT_ARRAY(Par1, Par2, Par3, Par4)
361 * Defines an array of integer numbers. The size of the array is fixed.
362 * Par1: C structure name
363 * Par2: C structure element name
364 * Par3: number of bits used to code the each integer element (between 1 and 32)
365 * Par4: number of elements in the array (fixed integer value)
366 *****************************************************************************/
367 #define M_UINT_ARRAY(_STRUCT, _MEMBER, _BITS, _ElementCount, _HF_PTR)\
368 {CSN_UINT_ARRAY, _BITS, {(void*)_ElementCount}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
369
370 /******************************************************************************
371 * M_VAR_UINT_ARRAY(Par1, Par2, Par3, Par4)
372 * Defines an array of integer numbers. The size of the array is variable.
373 * Par1: C structure name
374 * Par2: C structure element name
375 * Par3: number of bits used to code the each integer element (between 1 and 32)
376 * Par4: number of elements in the array supplied by reference to the
377 * structure member holding the length value
378 *****************************************************************************/
379 #define M_VAR_UINT_ARRAY(_STRUCT, _MEMBER, _BITS, _ElementCountField, _HF_PTR)\
380 {CSN_UINT_ARRAY, _BITS, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 1, _HF_PTR, NULL, NULL}
381
382 /******************************************************************************
383 * M_VAR_ARRAY(Par1, Par2, Par3, Par4)
384 * Defines an array of 8 bit large integer numbers. The size of the array is variable.
385 * Par1: C structure name
386 * Par2: C structure element name
387 * Par3: name of the structure member holding the size of the array
388 * Par4: offset that is added to the Par3 to get the actual size of the array
389 *****************************************************************************/
390 #define M_VAR_ARRAY(_STRUCT, _MEMBER, _ElementCountField, _OFFSET, _HF_PTR)\
391 {CSN_VARIABLE_ARRAY, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
392
393 /******************************************************************************
394 * M_VAR_TARRAY(Par1, Par2, Par3, Par4)
395 * Similar to M_TYPE_ARRAY except that the size of the array is variable.
396 * Par1: C structure name
397 * Par2: C structure element name
398 * Par3: the type of each element of the array
399 * Par4: name of the structure member holding the size of the array
400 *****************************************************************************/
401 #define M_VAR_TARRAY(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField)\
402 {CSN_VARIABLE_TARRAY, offsetof(_STRUCT, _ElementCountField), {(const void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, sizeof(_MEMBER_TYPE), NULL, NULL, NULL}
403
404 /******************************************************************************
405 * M_VAR_TARRAY_OFFSET(Par1, Par2, Par3, Par4)
406 * Same as M_VAR_TARRAY with offset
407 *****************************************************************************/
408 #define M_VAR_TARRAY_OFFSET(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField)\
409 {CSN_VARIABLE_TARRAY_OFFSET, offsetof(_STRUCT, _ElementCountField), {(const void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, sizeof(_MEMBER_TYPE), NULL, NULL, NULL}
410
411 /******************************************************************************
412 * M_REC_ARRAY(Par1, Par2, Par3, Par4)
413 * similar to the M_VAR_ARRAY. The difference is that the size of the array is
414 * not known in advance and it has to be calculated during unpacking. Its value
415 * is stored in a variable which belongs to the same structure as the array.
416 * A zero element terminates the array. The CSN.1 syntax describes it
417 * recursively as:
418 * <array> ::={1 <element> <array>| 0}
419 *
420 * Par1: C structure name
421 * Par2: C structure element name
422 * Par3: name of the structure member where the calculated the size of the
423 * array will be stored
424 * Par4: length of each element in bits
425 *****************************************************************************/
426 /* XXX - need 2 hf support */
427 #define M_REC_ARRAY(_STRUCT, _MEMBER, _ElementCountField, _BITS, _HF_PTR, _HF_PTR_EXIST)\
428 {CSN_RECURSIVE_ARRAY, _BITS, {(const void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, _HF_PTR_EXIST, NULL}
429
430 /******************************************************************************
431 * M_VAR_TYPE_ARRAY(Par1, Par2, Par3, Par4)
432 * Defines an array of structures. The size of the array is variable.
433 * Par1: C structure name
434 * Par2: C structure element name
435 * Par3: name of the structure
436 * Par4: number of elements in the array (fixed integer value)
437 *****************************************************************************/
438 #define M_TYPE_ARRAY(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCount)\
439 {CSN_TYPE_ARRAY, _ElementCount, {(const void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, sizeof(_MEMBER_TYPE), NULL, NULL, NULL}
440
441 /******************************************************************************
442 * M_REC_TARRAY(Par1, Par2, Par3, Par4)
443 * Defines an recursive array of structures. The size of the array is variable.
444 * <list> ::= {1 <type>} ** 0 ;
445 * Par1: C structure name
446 * Par2: C structure element name
447 * Par3: name of the structure
448 * Par4: will hold the number of element in the array after unpacking
449 *****************************************************************************/
450 #define M_REC_TARRAY(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField, _HF_PTR)\
451 {CSN_RECURSIVE_TARRAY, offsetof(_STRUCT, _ElementCountField), {(const void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, sizeof(_MEMBER_TYPE), _HF_PTR, NULL, NULL}
452
453 /******************************************************************************
454 * M_REC_TARRAY1(Par1, Par2, Par3, Par4)
455 * Same as M_REC_TARRAY but first element always exist:
456 * <list> ::= <type> {1 <type>} ** 0 ;
457 *****************************************************************************/
458 #define M_REC_TARRAY_1(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField, _HF_PTR)\
459 {CSN_RECURSIVE_TARRAY_1, offsetof(_STRUCT, _ElementCountField), {(const void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, sizeof(_MEMBER_TYPE), _HF_PTR, NULL, NULL}
460
461 /******************************************************************************
462 * M_REC_TARRAY2(Par1, Par2, Par3, Par4)
463 * Same as M_REC_TARRAY but with reversed separators :
464 * <lists> ::= <type> { 0 <type> } ** 1 ;
465 *****************************************************************************/
466 #define M_REC_TARRAY_2(_STRUCT, _MEMBER, _MEMBER_TYPE, _ElementCountField)\
467 {CSN_RECURSIVE_TARRAY_2, offsetof(_STRUCT, _ElementCountField), {(const void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, sizeof(_MEMBER_TYPE), NULL, NULL, NULL}
468
469 /******************************************************************************
470 * M_TYPE(Par1, Par2, Par3)
471 * Defines a reference to a structure which is described elsewhere
472 * <list> ::= {1 <type>} ** 0 ;
473 * Par1: C structure name
474 * Par2: C structure element name
475 * Par3: type of member
476 *****************************************************************************/
477 #define M_TYPE(_STRUCT, _MEMBER, _MEMBER_TYPE)\
478 {CSN_TYPE, 0, {(const void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, NULL, NULL, NULL}
479
480 /******************************************************************************
481 * M_TYPE_LABEL(Par1, Par2, Par3, Par4)
482 * Same as M_TYPE but allows to define a custom string for the subtree
483 * <list> ::= {1 <type>} ** 0 ;
484 * Par1: C structure name
485 * Par2: C structure element name
486 * Par3: type of member
487 * Par4: C string for the text
488 *****************************************************************************/
489 #define M_TYPE_LABEL(_STRUCT, _MEMBER, _MEMBER_TYPE, _LABEL)\
490 {CSN_TYPE, 0, {(const void*)CSNDESCR_##_MEMBER_TYPE}, offsetof(_STRUCT, _MEMBER), FALSE, _LABEL, NULL, 0, NULL, NULL, NULL}
491
492 /******************************************************************************
493 * M_UNION(Par1, Par2)
494 * Informs the CSN.1 library that a union follows and how many possible choices
495 * there are in the union. The actual value of the choice, which points out the
496 * chosen element of the union is stored in the uint8 variable and is usually
497 * called UnionType. The elements of the union have to be listed directly after
498 * the M_UNION statement.
499 * Par1: C structure name
500 * Par2: number of possible choice in the union
501 *****************************************************************************/
502 #define M_UNION(_STRUCT, _COUNT, _HF_PTR)\
503 {CSN_UNION, _COUNT, {0}, offsetof(_STRUCT, UnionType), FALSE, "UnionType", NULL, 0, _HF_PTR, NULL, NULL}
504
505 /******************************************************************************
506 * M_UNION_LH(Par1, Par2)
507 * Same as M_UNION but masked with background value 0x2B
508 *****************************************************************************/
509 #define M_UNION_LH(_STRUCT, _COUNT, _HF_PTR)\
510 {CSN_UNION_LH, _COUNT, {0}, offsetof(_STRUCT, UnionType), FALSE, "UnionType", NULL, 0, _HF_PTR, NULL, NULL}
511
512 /******************************************************************************
513 * M_CHOICE(Par1, Par2, Par3, Par4)
514 * Similar to the M_UNION. In the M_UNION the selected element of all possible
515 * choices in the union is referred as a sequential numbers, i.e., the first
516 * choice is addressed as choice 0 the second as choice 1, the third as choice
517 * 2 and so on, both in the encoded message and in the variable UnionType which
518 * is the part of the message. In the CSN_CHOICE case, this rule does not
519 * apply. There is free but predefined mapping of the element of the union and
520 * the value which addresses this element.
521 * The value of the address is called a selector.
522 * After unpacking, this value is then converted to the sequential number of the
523 * element in the union and stored in the UnionType variable.
524 * Par1: C structure name
525 * Par2: C structure element name
526 * Par3: address of an array of type CSN_ChoiceElement_t where all possible
527 * values of the selector are provided, together with the selector
528 * length expressed in bits and the address of the CSN_DESCR type
529 * where the element is defined. For every element in the union
530 * there is one line in the Choice variable. These lines have to
531 * appear in the _CHOICE in the same order as the elements in the
532 * union. The element of the union selected in the message through
533 * the _CHOICE parameter is after unpacking translated to the
534 * corresponding sequential number of this element and stored in
535 * the variable pointed out by the _MEMBER
536 * Par4: number of possible choices in the union
537 *****************************************************************************/
538 #define M_CHOICE(_STRUCT, _MEMBER, _CHOICE, _ElementCount, _HF_PTR)\
539 {CSN_CHOICE, _ElementCount, {(const void*)_CHOICE}, offsetof(_STRUCT, _MEMBER), FALSE, #_CHOICE, NULL, 0, _HF_PTR, NULL, NULL}
540
541 /******************************************************************************
542 * M_CHOICE_IL(Par1, Par2, Par3, Par4)
543 * See M_CHOICE above, but displayed inline (i.e. no specific elements are
544 * displayed to show there was a choice
545 *****************************************************************************/
546 #define M_CHOICE_IL(_STRUCT, _MEMBER, _CHOICE, _ElementCount, _HF_PTR)\
547 {CSN_CHOICE, _ElementCount, {(const void*)_CHOICE}, offsetof(_STRUCT, _MEMBER), FALSE, NULL, NULL, 0, _HF_PTR, NULL, NULL}
548
549 /******************************************************************************
550 * M_FIXED(Par1, Par2, Par3)
551 * Defines a fixed value of type integer which should be fetched from or stored
552 * in the message
553 * Par1: C structure name
554 * Par2: gives the length of the fixed number in bits.
555 * Par3: the value of the number. If the expected value is not present in
556 * the message the unpacking procedure is aborted
557 *****************************************************************************/
558 #define M_FIXED(_STRUCT, _BITS, _BITVALUE, _HF_PTR)\
559 {CSN_FIXED, _BITS, {0}, _BITVALUE, FALSE, #_BITVALUE, NULL, 0, _HF_PTR, NULL, NULL}
560
561 /******************************************************************************
562 * M_FIXED_LABEL(Par1, Par2, Par3, Par4)
563 * Same as M_FIXED but allows to define a custom string for the subtree
564 * Par1: C structure name
565 * Par2: gives the length of the fixed number in bits.
566 * Par3: the value of the number. If the expected value is not present in
567 * the message the unpacking procedure is aborted
568 * Par4: C string for the text
569 *****************************************************************************/
570 #define M_FIXED_LABEL(_STRUCT, _BITS, _BITVALUE, _LABEL, _HF_PTR)\
571 {CSN_FIXED, _BITS, {0}, _BITVALUE, FALSE, _LABEL, NULL, 0, _HF_PTR, NULL, NULL}
572
573 /******************************************************************************
574 * M_SERIALIZE(Par1, Par2, Par3)
575 * Allows using a complete free format of data being encoded or decoded.
576 * When the M_SERIALIZE is encounted during encoding or decoding of a message
577 * the CSNstream program passes the control over to the specified function
578 * together with all necessary parameters about the current position within
579 * the message being unpacked or packed. When transferring of "serialized"
580 * data to or from the message is finished by the function the CSNstream gets
581 * back control over the data stream and continues to work with the message.
582 *****************************************************************************/
583 #define M_SERIALIZE(_STRUCT, _MEMBER, _LENGTH_LEN, _HF_PTR, _SERIALIZEFCN)\
584 {CSN_SERIALIZE, _LENGTH_LEN, {0}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, (void_fn_t)_SERIALIZEFCN}
585
586 #define M_CALLBACK(_STRUCT, _CSNCALLBACKFCN, _PARAM1, _PARAM2)\
587 {CSN_CALLBACK, offsetof(_STRUCT, _PARAM1), {0}, offsetof(_STRUCT, _PARAM2), FALSE, "CallBack_"#_CSNCALLBACKFCN, NULL, 0, NULL, NULL, (void_fn_t)_CSNCALLBACKFCN}
588
589 /******************************************************************************
590 * M_BITMAP(Par1, Par2, Par3)
591 * Defines a type which consists of a bitmap. The size of the bitmap in bits
592 * is fixed and provided by the parameter Par3
593 * Par1: C structure name
594 * Par2: C structure element name
595 * Par3: length of the bitmap expressed in bits
596 *****************************************************************************/
597 #define M_BITMAP(_STRUCT, _MEMBER, _BITS, _HF_PTR)\
598 {CSN_BITMAP, _BITS, {0}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
599
600 /* variable length, right aligned bitmap i.e. _ElementCountField = 11 => 00000111 11111111 */
601 #define M_VAR_BITMAP(_STRUCT, _MEMBER, _ElementCountField, _OFFSET, _HF_PTR)\
602 {CSN_VARIABLE_BITMAP, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
603
604 /* variable length, right aligned bitmap filling the rest of message
605 * - when unpacking the _ElementCountField will be set in runtime
606 * - when packing _ElementCountField contains the size of bitmap
607 */
608 #define M_VAR_BITMAP_1(_STRUCT, _MEMBER, _ElementCountField, _OFFSET)\
609 {CSN_VARIABLE_BITMAP_1, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, NULL, NULL, NULL}
610
611 /* variable length, left aligned bitmap i.e. _ElementCountField = 11 => 11111111 11100000 */
612 #define M_LEFT_VAR_BMP(_STRUCT, _MEMBER, _ElementCountField, _OFFSET, _HF_PTR)\
613 {CSN_LEFT_ALIGNED_VAR_BMP, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
614
615 /* variable length, left aligned bitmap filling the rest of message
616 *- when unpacking the _ElementCountField will be set in runtime
617 * - when packing _ElementCountField contains the size of bitmap
618 */
619 #define M_LEFT_VAR_BMP_1(_STRUCT, _MEMBER, _ElementCountField, _OFFSET, _HF_PTR)\
620 {CSN_LEFT_ALIGNED_VAR_BMP_1, _OFFSET, {(void*)offsetof(_STRUCT, _ElementCountField)}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, _HF_PTR, NULL, NULL}
621
622 /* todo: dissect padding bits looking for unexpected extensions */
623 #define M_PADDING_BITS(_STRUCT, _HF_PTR)\
624 {CSN_PADDING_BITS, 0, {0}, 0, TRUE, "Padding", NULL, 0, _HF_PTR, NULL, NULL}
625
626 #define M_NULL(_STRUCT, _MEMBER, _SKIP_BITS)\
627 {CSN_NULL, _SKIP_BITS, {0}, offsetof(_STRUCT, _MEMBER), FALSE, #_MEMBER, NULL, 0, NULL, NULL, NULL}
628
629 #define M_THIS_EXIST(_STRUCT, _HF_PTR)\
630 {CSN_EXIST, 0, {0}, offsetof(_STRUCT, Exist), FALSE, "Exist", NULL, 0, _HF_PTR, NULL, NULL}
631
632 #define M_THIS_EXIST_LH(_STRUCT, _HF_PTR)\
633 {CSN_EXIST_LH, 0, {0}, offsetof(_STRUCT, Exist), FALSE, "Exist", NULL, 0, _HF_PTR, NULL, NULL}
634
635 /* return value 0 if ok else discontionue the unpacking */
636 typedef gint16 (*CsnCallBackFcn_t)(void* pv ,...);
637
638 #define CSNDESCR(_FuncType) CSNDESCR_##_FuncType
639
640 #endif /*_PACKET_CSN1_H_*/
641
642 /*
643 * Editor modelines - http://www.wireshark.org/tools/modelines.html
644 *
645 * Local Variables:
646 * c-basic-offset: 2
647 * tab-width: 8
648 * indent-tabs-mode: nil
649 * End:
650 *
651 * vi: set shiftwidth=2 tabstop=8 expandtab:
652 * :indentSize=2:tabSize=8:noTabs=true:
653 */
_packet_info
Definition: packet_info.h:44
tvbuff
Definition: tvbuff-int.h:35
csnStream_t
Definition: packet-csn1.h:51
CSN_DESCR
Definition: packet-csn1.h:165
expert_field
Definition: expert.h:37
CSN_ChoiceElement_t
Definition: packet-csn1.h:187
_proto_node
Definition: proto.h:759
crumb_spec_t
Definition: proto.h:695