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