f759030c884946bdec08c0904f7b80d15d14da46
[metze/wireshark/wip.git] / epan / dissectors / packet-ieee1722.c
1 /* packet-ieee1722.c
2  * Routines for AVB-TP (Audio Video Bridging - Transport Protocol) dissection
3  * Copyright 2010, Torrey Atcitty <tatcitty@harman.com>
4  *                 Dave Olsen <dave.olsen@harman.com>
5  *                 Levi Pearson <levi.pearson@harman.com>
6  *
7  * Copyright 2011, Thomas Bottom <tom.bottom@labxtechnologies.com>
8  *
9  * Copyright 2016, Andreas Leibold <andreas.leibold@harman.com>
10  *                 Dissection for the following 1722 subtypes added:
11  *                 Clock Reference Format (CRF).
12  *                 IEC 61883-4 MPEG-TS data transmission.
13  *                 IEC 61883-6 audio/music data transmission protocol improved.
14  *                 Changes to meet 1722 Draft 15 specification.
15  *
16  * Copyright 2017, Marouen Ghodhbane <marouen.ghodhbane@nxp.com>
17  *                 Dissection for the 1722 Compressed Video subtype added.
18  *                 CVF Format subtype supported: H264 and MJPEG
19  *                 The dissection meets the 1722-2016 specification.
20  *
21  * Wireshark - Network traffic analyzer
22  * By Gerald Combs <gerald@wireshark.org>
23  * Copyright 1998 Gerald Combs
24  *
25  * SPDX-License-Identifier: GPL-2.0-or-later
26  *
27  * The 1722 Protocol specification can be found at the following:
28  * http://grouper.ieee.org/groups/1722/
29  *
30  */
31
32 #include "config.h"
33
34 #include <epan/packet.h>
35 #include <epan/expert.h>
36 #include <epan/etypes.h>
37
38 void proto_register_1722(void);
39 void proto_reg_handoff_1722(void);
40 void proto_register_1722_crf(void);
41 void proto_reg_handoff_1722_crf(void);
42 void proto_register_1722_aaf(void);
43 void proto_reg_handoff_1722_aaf(void);
44 void proto_register_1722_61883(void);
45 void proto_reg_handoff_1722_61883(void);
46 void proto_register_1722_cvf(void);
47 void proto_reg_handoff_1722_cvf(void);
48
49 /**************************************************************************************************/
50 /* 1722                                                                                           */
51 /*                                                                                                */
52 /**************************************************************************************************/
53 #define IEEE_1722_SUBTYPE_61883             0x00
54 #define IEEE_1722_SUBTYPE_AAF               0x02
55 #define IEEE_1722_SUBTYPE_CVF               0x03
56 #define IEEE_1722_SUBTYPE_CRF               0x04
57
58 /* Bit Field Masks */
59 #define IEEE_1722_SV_MASK        0x80
60 #define IEEE_1722_VER_MASK       0x70
61
62 /**************************************************************************************************/
63 /* subtype IEC 61883                                                                              */
64 /*                                                                                                */
65 /**************************************************************************************************/
66 #define IEEE_1722_CIP_HEADER_SIZE           8
67 #define IEEE_1722_61883_TAG_NO_CIP          0x00
68 #define IEEE_1722_61883_TAG_CIP             0x40
69 #define IEEE_1722_61883_CHANNEL_AVTP        31
70 #define IEEE_1722_61883_SID_AVTP            63
71 #define IEEE_1722_61883_4_LEN_SOURCE_PACKET 192
72 #define IEEE_1722_61883_4_LEN_SP_TIMESTAMP  4
73 #define IEEE_1722_61883_4                   0x20
74 #define IEEE_1722_61883_6                   0x10
75
76 /* Bit Field Masks */
77 #define IEEE_1722_MR_MASK       0x08
78 #define IEEE_1722_GV_MASK       0x02
79 #define IEEE_1722_TV_MASK       0x01
80 #define IEEE_1722_TU_MASK       0x01
81 #define IEEE_1722_TAG_MASK      0xc0
82 #define IEEE_1722_CHANNEL_MASK  0x3f
83 #define IEEE_1722_TCODE_MASK    0xf0
84 #define IEEE_1722_SY_MASK       0x0f
85 #define IEEE_1722_QI1_MASK      0xc0
86 #define IEEE_1722_SID_MASK      0x3f
87 #define IEEE_1722_FN_MASK       0xc0
88 #define IEEE_1722_QPC_MASK      0x38
89 #define IEEE_1722_SPH_MASK      0x04
90 #define IEEE_1722_QI2_MASK      0xc0
91 #define IEEE_1722_FMT_MASK      0x3f
92 #define IEEE_1722_FDF_TSF_MASK  0x80
93 #define IEEE_1722_FDF_MASK      0xf8
94
95 /**************************************************************************************************/
96 /* subtype AAF                                                                                    */
97 /*                                                                                                */
98 /**************************************************************************************************/
99 #define IEEE_1722_AAF_FORMAT_USER                       0x00
100 #define IEEE_1722_AAF_FORMAT_FLOAT_32_BIT               0x01
101 #define IEEE_1722_AAF_FORMAT_INT_32_BIT                 0x02
102 #define IEEE_1722_AAF_FORMAT_INT_24_BIT                 0x03
103 #define IEEE_1722_AAF_FORMAT_INT_16_BIT                 0x04
104 #define IEEE_1722_AAF_FORMAT_AES3_32_BIT                0x05
105
106 /* Bit Field Masks */
107 #define IEEE_1722_MR_MASK                               0x08
108 #define IEEE_1722_TV_MASK                               0x01
109 #define IEEE_1722_SEQ_NUM_MASK                          0x00
110 #define IEEE_1722_TU_MASK                               0x01
111 #define IEEE_1722_STREAM_ID_MASK                        0x00
112 #define IEEE_1722_TIMESTAMP_MASK                        0x00
113 #define IEEE_1722_FORMAT_MASK                           0x00
114 #define IEEE_1722_NOM_SAMPLE_RATE_MASK                  0xf000
115 #define IEEE_1722_CHANNEL_PER_FRAME_MASK                0x03ff
116 #define IEEE_1722_BIT_DEPTH_MASK                        0x00
117 #define IEEE_1722_AES3_DATA_TYPE_H_MASK                 0x00
118 #define IEEE_1722_STREAM_DATA_LENGTH_MASK               0x00
119 #define IEEE_1722_AES3_DATA_TYPE_REFERENCE_MASK         0xe0
120 #define IEEE_1722_SP_MASK                               0x10
121 #define IEEE_1722_EVT_MASK                              0x0f
122 #define IEEE_1722_AES3_DATA_TYPE_L_MASK                 0x00
123 #define IEEE_1722_DATA_MASK                             0x00
124 #define IEEE_1722_SAMPLE_MASK                           0x00
125
126 /**************************************************************************************************/
127 /* subtype CVF                                                                                    */
128 /*                                                                                                */
129 /**************************************************************************************************/
130 #define IEEE_1722_CVF_FORMAT_SUBTYPE_MJPEG              0x00
131 #define IEEE_1722_CVF_FORMAT_SUBTYPE_H264               0x01
132 #define IEEE_1722_CVF_FORMAT_SUBTYPE_JPEG2000           0x02
133
134 /* Bit Field Masks */
135 #define IEEE_1722_MR_MASK                               0x08
136 #define IEEE_1722_TV_MASK                               0x01
137 #define IEEE_1722_SEQ_NUM_MASK                          0x00
138 #define IEEE_1722_TU_MASK                               0x01
139 #define IEEE_1722_STREAM_ID_MASK                        0x00
140 #define IEEE_1722_TIMESTAMP_MASK                        0x00
141 #define IEEE_1722_FORMAT_MASK                           0x00
142 #define IEEE_1722_FORMAT_SUBTYPE_MASK                   0x00
143 #define IEEE_1722_CVF_H264_TIMESTAMP_MASK               0x00
144 #define IEEE_1722_CVF_H264_FORBIDDEN_MASK               0x80
145 #define IEEE_1722_CVF_H264_NRI_MASK                     0x60
146 #define IEEE_1722_CVF_H264_NAL_TYPE_MASK                0x1f
147 #define IEEE_1722_CVF_MJPEG_TS_MASK                     0x00
148 #define IEEE_1722_CVF_MJPEG_FRAGMENT_OFFSET_MASK        0x00
149 #define IEEE_1722_CVF_MJPEG_TYPE_MASK                   0x00
150 #define IEEE_1722_CVF_MJPEG_Q_MASK                      0x00
151 #define IEEE_1722_CVF_MJPEG_WIDTH_MASK                  0x00
152 #define IEEE_1722_CVF_MJPEG_HEIGHT_MASK                 0x00
153 #define IEEE_1722_MARKER_BIT_MASK                       0x10
154 #define IEEE_1722_EVT_MASK                              0x0f
155
156 /**************************************************************************************************/
157 /* subtype CRF                                                                                    */
158 /*                                                                                                */
159 /**************************************************************************************************/
160 #define IEEE_1722_CRF_TIMESTAMP_SIZE        8 /* size of the CRF timestamp in bytes */
161
162 /* Bit Field Masks */
163 #define IEEE_1722_MR_MASK                   0x08
164 #define IEEE_1722_FS_MASK                   0x02
165 #define IEEE_1722_TU_MASK                   0x01
166 #define IEEE_1722_PULL_MASK                 0xe0000000
167 #define IEEE_1722_BASE_FREQUENCY_MASK       0x1fffffff
168
169 /**************************************************************************************************/
170 /* 1722                                                                                           */
171 /*                                                                                                */
172 /**************************************************************************************************/
173 static const range_string subtype_range_rvals[] = {
174     { 0,    0,      "IEC 61883/IIDC Format" },
175     { 1,    1,      "MMA Streams" },
176     { 2,    2,      "AVTP Audio Format" },
177     { 3,    3,      "Compressed Video Format" },
178     { 4,    4,      "Clock Reference Format" },
179     { 5,    5,      "Time Synchronous Control Format" },
180     { 6,    6,      "SDI Video Format" },
181     { 7,    7,      "Raw Video Format" },
182     { 8,    0x6d,   "Reserved for future protocols" },
183     { 0x6e, 0x6e,   "AES Encrypted Format Continuous" },
184     { 0x6f, 0x6f,   "Vendor Specific Format Stream" },
185     { 0x70, 0x7e,   "Reserved for future protocols" },
186     { 0x7f, 0x7f,   "Experimental Format Stream" },
187     { 0x80, 0x81,   "Reserved for future protocols" },
188     { 0x82, 0x82,   "Non Time Synchronous Control Format" },
189     { 0x83, 0xed,   "Reserved for future protocols" },
190     { 0xec, 0xec,   "ECC Signed Control Format" },
191     { 0xed, 0xed,   "ECC Encrypted Control Format" },
192     { 0xee, 0xee,   "AES Encrypted Format Discrete" },
193     { 0xef, 0xf9,   "Reserved for future protocols" },
194     { 0xfa, 0xfa,   "AVDECC Discovery Protocol" },
195     { 0xfb, 0xfb,   "AVDECC Enumeration and Control Protocol" },
196     { 0xfc, 0xfc,   "AVDECC Connection Management Protocol" },
197     { 0xfd, 0xfd,   "Reserved for future protocols" },
198     { 0xfe, 0xfe,   "MAAP" },
199     { 0xff, 0xff,   "Experimental Format Control" },
200     { 0,    0,      NULL }
201 };
202
203 /* Initialize the protocol and registered fields          */
204 static int proto_1722 = -1;
205 static int hf_1722_subtype = -1;
206 static int hf_1722_svfield = -1;
207 static int hf_1722_verfield = -1;
208
209 /* Initialize the subtree pointers */
210 static int ett_1722 = -1;
211
212 static dissector_table_t avb_dissector_table;
213
214 /**************************************************************************************************/
215 /* subtype IEC 61883                                                                              */
216 /*                                                                                                */
217 /**************************************************************************************************/
218 static const value_string tag_vals [] = {
219     {0, "No CIP header included"},
220     {1, "CIP header included"},
221     {2, "Reserved by IEEE 1394.1 clock adjustment"},
222     {3, "Global asynchronous stream packet format"},
223     {0, NULL}
224 };
225
226 static const range_string format_rvals [] = {
227     {0,                 0,                  "DVCR transmission"},
228     {1,                 0x0f,               "Reserved"},
229     {IEEE_1722_61883_4, IEEE_1722_61883_4,  "IEC 61883-4: MPEG2-TS data transmission"},
230     {0x11,              0x1d,               "Reserved"},
231     {0x1e,              0x1e,               "Free (vendor unique)"},
232     {0x1f,              0x1f,               "Reserved"},
233     {IEEE_1722_61883_6, IEEE_1722_61883_6,  "IEC 61883-6: Audio and music transmission"},
234     {0x21,              0x21,               "ITU-R B0.1294 System B transmission"},
235     {0x22,              0x2d,               "Reserved"},
236     {0x3e,              0x3e,               "Free (vendor unique)"},
237     {0x3f,              0x3f,               "No data"},
238     {0,                 0,                  NULL}
239 };
240
241 static const value_string fraction_number_vals [] = {
242     {0,    "Not divided"},
243     {1,    "Divided into 2 datablocks"},
244     {2,    "Divided into 4 datablocks"},
245     {3,    "Divided into 8 datablocks"},
246     {0,    NULL}
247 };
248
249 static const range_string fdf_rvals [] = {
250     {0x00, 0x07,    "Basic format for AM824"},
251     {0x08, 0x0f,    "Basic format for AM824. Transmission rate may be controlled by an AV/C command set"},
252     {0x10, 0x17,    "Basic format for 24-bit*4 audio pack"},
253     {0x18, 0x1f,    "Reserved"},
254     {0x20, 0x27,    "Basic format for 32-bit floating-point data"},
255     {0x28, 0x2f,    "Reserved"},
256     {0x30, 0x37,    "Basic format for 32-bit generic data"},
257     {0x38, 0x3f,    "Reserved"},
258     {0x40, 0xfe,    "Reserved"},
259     {0xff, 0xff,    "Packet for NO-DATA"},
260     {0,    0,       NULL}
261 };
262
263 static const range_string syt_rvals [] = {
264     {0x0000, 0x0bff,    "Timestamp"},
265     {0x0c00, 0x0fff,    "Reserved"},
266     {0x1000, 0x1bff,    "Timestamp"},
267     {0x1c00, 0x1fff,    "Reserved"},
268     {0x2000, 0x2bff,    "Timestamp"},
269     {0x2c00, 0x2fff,    "Reserved"},
270     {0x3000, 0x3bff,    "Timestamp"},
271     {0x3c00, 0x3fff,    "Reserved"},
272     {0x4000, 0x4bff,    "Timestamp"},
273     {0x4c00, 0x4fff,    "Reserved"},
274     {0x5000, 0x5bff,    "Timestamp"},
275     {0x5c00, 0x5fff,    "Reserved"},
276     {0x6000, 0x6bff,    "Timestamp"},
277     {0x6c00, 0x6fff,    "Reserved"},
278     {0x7000, 0x7bff,    "Timestamp"},
279     {0x7c00, 0x7fff,    "Reserved"},
280     {0x8000, 0x8bff,    "Timestamp"},
281     {0x8c00, 0x8fff,    "Reserved"},
282     {0x9000, 0x9bff,    "Timestamp"},
283     {0x9c00, 0x9fff,    "Reserved"},
284     {0xa000, 0xabff,    "Timestamp"},
285     {0xac00, 0xafff,    "Reserved"},
286     {0xb000, 0xbbff,    "Timestamp"},
287     {0xbc00, 0xbfff,    "Reserved"},
288     {0xc000, 0xcbff,    "Timestamp"},
289     {0xcc00, 0xcfff,    "Reserved"},
290     {0xd000, 0xdbff,    "Timestamp"},
291     {0xdc00, 0xdfff,    "Reserved"},
292     {0xe000, 0xebff,    "Timestamp"},
293     {0xec00, 0xefff,    "Reserved"},
294     {0xf000, 0xfbff,    "Timestamp"},
295     {0xfc00, 0xfffe,    "Reserved"},
296     {0xffff, 0xffff,    "No information"},
297     {0,      0,         NULL}
298 };
299
300 /* Initialize the protocol and registered fields          */
301 static int proto_1722_61883 = -1;
302 static int hf_1722_61883_mrfield = -1;
303 static int hf_1722_61883_gvfield = -1;
304 static int hf_1722_61883_tvfield = -1;
305 static int hf_1722_61883_seqnum = -1;
306 static int hf_1722_61883_tufield = -1;
307 static int hf_1722_61883_stream_id = -1;
308 static int hf_1722_61883_avtp_timestamp = -1;
309 static int hf_1722_61883_gateway_info = -1;
310 static int hf_1722_61883_stream_data_length = -1;
311 static int hf_1722_61883_tag = -1;
312 static int hf_1722_61883_channel = -1;
313 static int hf_1722_61883_tcode = -1;
314 static int hf_1722_61883_sy = -1;
315 static int hf_1722_61883_cip_qi1 = -1;
316 static int hf_1722_61883_cip_sid = -1;
317 static int hf_1722_61883_cip_dbs = -1;
318 static int hf_1722_61883_cip_fn = -1;
319 static int hf_1722_61883_cip_qpc = -1;
320 static int hf_1722_61883_cip_sph = -1;
321 static int hf_1722_61883_cip_dbc = -1;
322 static int hf_1722_61883_cip_qi2 = -1;
323 static int hf_1722_61883_cip_fmt = -1;
324 static int hf_1722_61883_cip_fdf_no_syt = -1;
325 static int hf_1722_61883_cip_fdf_tsf = -1;
326 static int hf_1722_61883_cip_fdf = -1;
327 static int hf_1722_61883_cip_syt = -1;
328 static int hf_1722_61883_audio_data = -1;
329 static int hf_1722_61883_label = -1;
330 static int hf_1722_61883_sample = -1;
331 static int hf_1722_61883_video_data = -1;
332 static int hf_1722_61883_source_packet_header_timestamp = -1;
333
334 /* Initialize the subtree pointers */
335 static int ett_1722_61883 = -1;
336 static int ett_1722_61883_audio = -1;
337 static int ett_1722_61883_sample = -1;
338 static int ett_1722_61883_video = -1;
339
340 /* Initialize expert fields */
341 static expert_field ei_1722_61883_incorrect_tag = EI_INIT;
342 static expert_field ei_1722_61883_incorrect_tcode = EI_INIT;
343 static expert_field ei_1722_61883_incorrect_qi1 = EI_INIT;
344 static expert_field ei_1722_61883_incorrect_qpc = EI_INIT;
345 static expert_field ei_1722_61883_incorrect_qi2 = EI_INIT;
346 static expert_field ei_1722_61883_unknown_format = EI_INIT;
347 static expert_field ei_1722_61883_incorrect_channel_sid = EI_INIT;
348 static expert_field ei_1722_61883_incorrect_datalen = EI_INIT;
349 static expert_field ei_1722_61883_4_incorrect_cip_fn = EI_INIT;
350 static expert_field ei_1722_61883_4_incorrect_cip_dbs = EI_INIT;
351 static expert_field ei_1722_61883_4_incorrect_cip_sph = EI_INIT;
352 static expert_field ei_1722_61883_6_incorrect_cip_fn = EI_INIT;
353 static expert_field ei_1722_61883_6_incorrect_cip_sph = EI_INIT;
354 static expert_field ei_1722_61883_incorrect_cip_fdf = EI_INIT;
355
356 /**************************************************************************************************/
357 /* subtype AAF                                                                                    */
358 /*                                                                                                */
359 /**************************************************************************************************/
360 static const range_string aaf_format_range_rvals [] = {
361     {0, 0,      "User specified"},
362     {1, 1,      "32bit floating point"},
363     {2, 2,      "32bit integer"},
364     {3, 3,      "24bit integer"},
365     {4, 4,      "16bit integer"},
366     {5, 5,      "32bit AES3 format"},
367     {6, 0xff,   "Reserved"},
368     {0, 0,      NULL}
369 };
370
371 static const range_string aaf_nominal_sample_rate_range_rvals [] = {
372     {0,    0,       "User specified"},
373     {1,    1,       "8kHz"},
374     {2,    2,       "16kHz"},
375     {3,    3,       "32kHz"},
376     {4,    4,       "44.1kHz"},
377     {5,    5,       "48kHz"},
378     {6,    6,       "88.2kHz"},
379     {7,    7,       "96kHz"},
380     {8,    8,       "176.4kHz"},
381     {9,    9,       "192kHz"},
382     {0xa, 0xa,      "24kHz"},
383     {0xb, 0xf,      "Reserved"},
384     {0,    0,       NULL}
385 };
386
387 static const value_string aaf_sparse_timestamp_vals [] = {
388     {0,     "Normal operation, timestamp in every AAF AVTPDU"},
389     {1,     "Sparse mode, timestamp in every eighth AAF AVTPDU"},
390     {0,     NULL}
391 };
392
393 /* Initialize the protocol and registered fields          */
394 static int proto_1722_aaf = -1;
395 static int hf_1722_aaf_mrfield = -1;
396 static int hf_1722_aaf_tvfield = -1;
397 static int hf_1722_aaf_seqnum = -1;
398 static int hf_1722_aaf_tufield = -1;
399 static int hf_1722_aaf_stream_id = -1;
400 static int hf_1722_aaf_avtp_timestamp = -1;
401 static int hf_1722_aaf_format = -1;
402 static int hf_1722_aaf_nominal_sample_rate = -1;
403 static int hf_1722_aaf_bit_depth = -1;
404 static int hf_1722_aaf_stream_data_length = -1;
405 static int hf_1722_aaf_sparse_timestamp = -1;
406 static int hf_1722_aaf_evtfield = -1;
407 static int hf_1722_aaf_channels_per_frame = -1;
408 static int hf_1722_aaf_data = -1;
409 static int hf_1722_aaf_sample = -1;
410
411 /* Initialize the subtree pointers */
412 static int ett_1722_aaf = -1;
413 static int ett_1722_aaf_audio = -1;
414 static int ett_1722_aaf_sample = -1;
415
416 /* Initialize expert fields */
417 static expert_field ei_aaf_sample_width = EI_INIT;
418 static expert_field ei_aaf_reserved_format = EI_INIT;
419 static expert_field ei_aaf_aes3_format = EI_INIT;
420 static expert_field ei_aaf_channels_per_frame = EI_INIT;
421 static expert_field ei_aaf_incorrect_bit_depth = EI_INIT;
422
423 /**************************************************************************************************/
424 /* subtype CRF                                                                                    */
425 /*                                                                                                */
426 /**************************************************************************************************/
427 static const range_string crf_pull_range_rvals [] = {
428     {0, 0,  "[1.0]"},
429     {1, 1,  "[1/1.001]"},
430     {2, 2,  "[1.001]"},
431     {3, 3,  "[24/25]"},
432     {4, 4,  "[25/24]"},
433     {5, 5,  "[1/8]"},
434     {6, 7,  "Reserved"},
435     {0, 0,  NULL}
436 };
437
438 static const range_string crf_type_range_rvals [] = {
439     {0, 0,      "User Specified"},
440     {1, 1,      "Audio Sample Timestamp"},
441     {2, 2,      "Video Frame Sync Timestamp"},
442     {3, 3,      "Video Line Sync Timestamp"},
443     {4, 4,      "Machine Cycle Timestamp"},
444     {5, 0xff,   "Reserved"},
445     {0, 0,      NULL}
446 };
447
448 /* Initialize the protocol and registered fields          */
449 static int proto_1722_crf = -1;
450 static int hf_1722_crf_mrfield = -1;
451 static int hf_1722_crf_fsfield = -1;
452 static int hf_1722_crf_tufield = -1;
453 static int hf_1722_crf_seqnum = -1;
454 static int hf_1722_crf_type = -1;
455 static int hf_1722_crf_stream_id = -1;
456 static int hf_1722_crf_pull = -1;
457 static int hf_1722_crf_base_frequency = -1;
458 static int hf_1722_crf_data_length = -1;
459 static int hf_1722_crf_timestamp_interval = -1;
460 static int hf_1722_crf_timestamp_data = -1;
461 static int hf_1722_crf_timestamp = -1;
462
463 /* Initialize the subtree pointers */
464 static int ett_1722_crf = -1;
465 static int ett_1722_crf_timestamp = -1;
466
467 /* Initialize expert fields */
468 static expert_field ei_crf_datalen = EI_INIT;
469
470 /**************************************************************************************************/
471 /* subtype CVF                                                                                    */
472 /*                                                                                                */
473 /**************************************************************************************************/
474 static const range_string cvf_format_range_rvals [] = {
475     {0, 1,      "Reserved"},
476     {2, 2,      "RFC payload type"},
477     {3, 0xff,   "Reserved"},
478     {0, 0,      NULL}
479 };
480
481 static const true_false_string tfs_marker_bit_set_not_set = { "Marker Bit is set", "Marker bit not set" };
482
483 static const range_string cvf_format_subtype_range_rvals [] = {
484     {0, 0,      "MJPEG Format (RFC2435)"},
485     {1, 1,      "H264 Format"},
486     {2, 2,      "JPEG 2000 Video"},
487     {3, 0xff,   "Reserved"},
488     {0, 0,      NULL}
489 };
490
491 static const range_string cvf_h264_nal_type_range_rvals [] = {
492     {0x00, 0x00,    "Undefined"},
493     {0x01, 0x17,    "Single Nal Unit Packet"},
494     {0x18, 0x18,    "STAP-A"},
495     {0x19, 0x19,    "STAP-B"},
496     {0x1a, 0x1a,    "MTAP16"},
497     {0x1b, 0x1b,    "MTAP24"},
498     {0x1c, 0x1c,    "FU-A"},
499     {0x1d, 0x1d,    "FU-B"},
500     {0x1e, 0xff,    "Unspecified"},
501     {0, 0,      NULL}
502 };
503
504 static const range_string cvf_mjpeg_ts_range_rvals [] = {
505     {0, 0,          "MJPEG TYPE SPEC PROGRESSIVE"},
506     {1, 1,          "MJPEG TYPE SPEC ODD"},
507     {2, 2,          "MJPEG TYPE SPEC EVEN"},
508     {3, 3,          "MJPEG TYPE SPEC SINGLE"},
509     {3, 0xff,       "Unspecified"},
510     {0, 0,      NULL}
511 };
512
513 /* Initialize the protocol and registered fields          */
514
515 static int proto_1722_cvf = -1;
516 static int hf_1722_cvf_mrfield = -1;
517 static int hf_1722_cvf_tvfield = -1;
518 static int hf_1722_cvf_seqnum = -1;
519 static int hf_1722_cvf_tufield = -1;
520 static int hf_1722_cvf_stream_id = -1;
521 static int hf_1722_cvf_avtp_timestamp = -1;
522 static int hf_1722_cvf_format = -1;
523 static int hf_1722_cvf_format_subtype = -1;
524 static int hf_1722_cvf_stream_data_length = -1;
525 static int hf_1722_cvf_evtfield = -1;
526 static int hf_1722_cvf_marker_bit = -1;
527 static int hf_1722_cvf_h264_timestamp = -1;
528 static int hf_1722_cvf_h264_forbidden_bit = -1;
529 static int hf_1722_cvf_h264_nri = -1;
530 static int hf_1722_cvf_h264_nal_type = -1;
531 static int hf_1722_cvf_mjpeg_ts = -1;
532 static int hf_1722_cvf_mjpeg_fragment_offset = -1;
533 static int hf_1722_cvf_mjpeg_type = -1;
534 static int hf_1722_cvf_mjpeg_q = -1;
535 static int hf_1722_cvf_mjpeg_width = -1;
536 static int hf_1722_cvf_mjpeg_height = -1;
537
538 /* Initialize the subtree pointers */
539 static int ett_1722_cvf = -1;
540
541 /* Initialize expert fields */
542 static expert_field ei_cvf_jpeg2000_format = EI_INIT;
543 static expert_field ei_cvf_reserved_format = EI_INIT;
544
545 /**************************************************************************************************/
546 /* 1722 dissector implementation                                                                  */
547 /*                                                                                                */
548 /**************************************************************************************************/
549 static int dissect_1722(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
550 {
551     proto_item *ti;
552     proto_tree *ieee1722_tree;
553     guint       subtype = 0;
554     gint        offset = 0;
555     const gint *fields[] = {
556         &hf_1722_svfield,
557         &hf_1722_verfield,
558         NULL
559     };
560
561     col_set_str(pinfo->cinfo, COL_PROTOCOL, "IEEE1722");
562     col_set_str(pinfo->cinfo, COL_INFO, "AVB Transportation Protocol");
563
564     ti = proto_tree_add_item(tree, proto_1722, tvb, 0, -1, ENC_NA);
565     ieee1722_tree = proto_item_add_subtree(ti, ett_1722);
566
567     proto_tree_add_item_ret_uint(ieee1722_tree, hf_1722_subtype, tvb, offset, 1, ENC_BIG_ENDIAN, &subtype);
568     offset += 1;
569     proto_tree_add_bitmask_list(ieee1722_tree, tvb, offset, 1, fields, ENC_NA);
570
571     /* call any registered subtype dissectors which use only the common AVTPDU (e.g. 1722.1, MAAP, 61883, AAF, CRF or CVF) */
572     if (dissector_try_uint(avb_dissector_table, subtype, tvb, pinfo, tree))
573         return tvb_captured_length(tvb);
574
575     return tvb_captured_length(tvb);
576 }
577
578 /* Register the protocol with Wireshark */
579 void proto_register_1722(void)
580 {
581     static hf_register_info hf[] = {
582         { &hf_1722_subtype,
583             { "AVBTP Subtype", "ieee1722.subtype",
584               FT_UINT8, BASE_HEX | BASE_RANGE_STRING, RVALS(subtype_range_rvals), 0x00, NULL, HFILL }
585         },
586         { &hf_1722_svfield,
587             { "AVTP Stream ID Valid", "ieee1722.svfield",
588               FT_BOOLEAN, 8, NULL, IEEE_1722_SV_MASK, NULL, HFILL }
589         },
590         { &hf_1722_verfield,
591             { "AVTP Version", "ieee1722.verfield",
592               FT_UINT8, BASE_HEX, NULL, IEEE_1722_VER_MASK, NULL, HFILL }
593         }
594     };
595
596     static gint *ett[] = {
597         &ett_1722
598     };
599
600     /* Register the protocol name and description */
601     proto_1722 = proto_register_protocol("IEEE 1722 Protocol", "IEEE1722", "ieee1722");
602
603     /* Required function calls to register the header fields and subtrees used */
604     proto_register_field_array(proto_1722, hf, array_length(hf));
605     proto_register_subtree_array(ett, array_length(ett));
606
607     /* Sub-dissector for 1772.1, 1722 AAF, 1722 CRF, 1722 61883, 1722 CVF */
608     avb_dissector_table = register_dissector_table("ieee1722.subtype",
609                           "IEEE1722 AVBTP Subtype", proto_1722, FT_UINT8, BASE_HEX);
610 }
611
612 void proto_reg_handoff_1722(void)
613 {
614     dissector_handle_t avbtp_handle;
615
616     avbtp_handle = create_dissector_handle(dissect_1722, proto_1722);
617     dissector_add_uint("ethertype", ETHERTYPE_AVBTP, avbtp_handle);
618 }
619
620 /**************************************************************************************************/
621 /* IEC 61883 dissector implementation                                                             */
622 /*                                                                                                */
623 /**************************************************************************************************/
624 static int dissect_1722_61883(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
625 {
626     proto_item *ti;
627     proto_tree *ti_61883_tree;
628     proto_tree *ti_channel;
629     proto_tree *ti_datalen;
630     proto_tree *ti_cip_fn;
631     proto_tree *ti_cip_dbs;
632     proto_tree *ti_cip_sph;
633     proto_tree *ti_cip_fmt;
634     proto_tree *ti_cip_fdf;
635     proto_tree *ti_audio_tree;
636     proto_tree *ti_sample_tree;
637     proto_tree *ti_video_tree;
638     gint        offset = 1;
639     guint8      cip_dbs = 0;
640     guint8      tag = 0;
641     guint8      channel = 0;
642     guint8      tcode = 0;
643     guint8      cip_qi1 = 0;
644     guint8      cip_sid = 0;
645     guint8      cip_qpc = 0;
646     guint8      cip_qi2 = 0;
647     guint8      cip_fmt = 0;
648     guint8      cip_sph = 0;
649     guint8      cip_fn = 0;
650     guint       datalen = 0;
651     guint       db_size = 0;
652     guint       numSourcePackets = 0;
653     guint       i = 0;
654     guint       j = 0;
655     const gint *fields[] = {
656         &hf_1722_61883_mrfield,
657         &hf_1722_61883_gvfield,
658         &hf_1722_61883_tvfield,
659         NULL
660     };
661
662     ti = proto_tree_add_item(tree, proto_1722_61883, tvb, 0, -1, ENC_NA);
663     ti_61883_tree = proto_item_add_subtree(ti, ett_1722_61883);
664
665     proto_tree_add_bitmask_list(ti_61883_tree, tvb, offset, 1, fields, ENC_NA);
666     offset += 1;
667     proto_tree_add_item(ti_61883_tree, hf_1722_61883_seqnum, tvb, offset, 1, ENC_BIG_ENDIAN);
668     offset += 1;
669     proto_tree_add_item(ti_61883_tree, hf_1722_61883_tufield, tvb, offset, 1, ENC_BIG_ENDIAN);
670     offset += 1;
671     proto_tree_add_item(ti_61883_tree, hf_1722_61883_stream_id, tvb, offset, 8, ENC_BIG_ENDIAN);
672     offset += 8;
673
674     proto_tree_add_item(ti_61883_tree, hf_1722_61883_avtp_timestamp, tvb, offset, 4, ENC_BIG_ENDIAN);
675     offset += 4;
676     proto_tree_add_item(ti_61883_tree, hf_1722_61883_gateway_info, tvb, offset, 4, ENC_BIG_ENDIAN);
677     offset += 4;
678
679     ti_datalen = proto_tree_add_item_ret_uint(ti_61883_tree, hf_1722_61883_stream_data_length, tvb, offset, 2, ENC_BIG_ENDIAN, &datalen);
680     offset += 2;
681
682     /* tag field defines if CIP header is included or not */
683     ti = proto_tree_add_item(ti_61883_tree, hf_1722_61883_tag, tvb, offset, 1, ENC_BIG_ENDIAN);
684
685     tag = tvb_get_guint8(tvb, offset) & IEEE_1722_TAG_MASK;
686     if (tag > 0x40)
687     {
688         expert_add_info(pinfo, ti, &ei_1722_61883_incorrect_tag);
689     }
690
691     ti_channel = proto_tree_add_item(ti_61883_tree, hf_1722_61883_channel, tvb, offset, 1, ENC_BIG_ENDIAN);
692     channel = tvb_get_guint8(tvb, offset) & IEEE_1722_CHANNEL_MASK;
693     if (channel != IEEE_1722_61883_CHANNEL_AVTP)
694     {
695         proto_item_append_text(ti_channel, ": Originating Source ID from an IEEE 1394 serial bus");
696     }
697     else
698     {
699         proto_item_append_text(ti_channel, ": Originating source is on AVTP network (native AVTP)");
700     }
701     offset += 1;
702
703     ti = proto_tree_add_item(ti_61883_tree, hf_1722_61883_tcode, tvb, offset, 1, ENC_BIG_ENDIAN);
704     tcode = tvb_get_guint8(tvb, offset) & IEEE_1722_TCODE_MASK;
705     if (tcode != 0xa0)
706     {
707        expert_add_info(pinfo, ti, &ei_1722_61883_incorrect_tcode);
708     }
709
710     proto_tree_add_item(ti_61883_tree, hf_1722_61883_sy, tvb, offset, 1, ENC_BIG_ENDIAN);
711     offset += 1;
712
713     switch (tag) {
714     case IEEE_1722_61883_TAG_NO_CIP:
715         proto_item_prepend_text(ti, "IIDC 1394 video payload:");
716         break;
717     case IEEE_1722_61883_TAG_CIP:
718         ti = proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_qi1, tvb, offset, 1, ENC_BIG_ENDIAN);
719         cip_qi1 = tvb_get_guint8(tvb, offset) & IEEE_1722_QI1_MASK;
720         if (cip_qi1 != 0)
721         {
722             expert_add_info(pinfo, ti, &ei_1722_61883_incorrect_qi1);
723         }
724
725         ti = proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_sid, tvb, offset, 1, ENC_BIG_ENDIAN);
726         cip_sid = tvb_get_guint8(tvb, offset) & IEEE_1722_SID_MASK;
727         if (cip_sid != IEEE_1722_61883_SID_AVTP)
728         {
729             proto_item_append_text(ti, ": Originating Source ID from an IEEE 1394 serial bus");
730             if (channel == IEEE_1722_61883_CHANNEL_AVTP)
731             {
732                 expert_add_info(pinfo, ti, &ei_1722_61883_incorrect_channel_sid);
733                 expert_add_info(pinfo, ti_channel, &ei_1722_61883_incorrect_channel_sid);
734
735             }
736         }
737         else
738         {
739             proto_item_append_text(ti, ": Originating source is on AVTP network");
740             if (channel != IEEE_1722_61883_CHANNEL_AVTP)
741             {
742                 expert_add_info(pinfo, ti, &ei_1722_61883_incorrect_channel_sid);
743                 expert_add_info(pinfo, ti_channel, &ei_1722_61883_incorrect_channel_sid);
744             }
745         }
746         offset += 1;
747
748         ti_cip_dbs = proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_dbs, tvb, offset, 1, ENC_BIG_ENDIAN);
749         cip_dbs = tvb_get_guint8(tvb, offset);
750         offset += 1;
751         ti_cip_fn = proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_fn, tvb, offset, 1, ENC_BIG_ENDIAN);
752
753         switch (tvb_get_guint8(tvb, offset) & IEEE_1722_FN_MASK) {
754         case 0:
755             cip_fn = 0;
756             break;
757         case 0x40:
758             cip_fn = 2;
759             break;
760         case 0x80:
761             cip_fn = 4;
762             break;
763         case 0xc0:
764             cip_fn = 8;
765             break;
766         default:
767             break;
768         }
769
770         ti = proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_qpc, tvb, offset, 1, ENC_BIG_ENDIAN);
771         cip_qpc = tvb_get_guint8(tvb, offset) & IEEE_1722_QPC_MASK;
772         if (cip_qpc != 0)
773         {
774             expert_add_info(pinfo, ti, &ei_1722_61883_incorrect_qpc);
775         }
776
777         ti_cip_sph = proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_sph, tvb, offset, 1, ENC_BIG_ENDIAN);
778         cip_sph = tvb_get_guint8(tvb, offset) & IEEE_1722_SPH_MASK;
779         offset += 1;
780         proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_dbc, tvb, offset, 1, ENC_BIG_ENDIAN);
781         offset += 1;
782
783         ti = proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_qi2, tvb, offset, 1, ENC_BIG_ENDIAN);
784         cip_qi2 = tvb_get_guint8(tvb, offset) & IEEE_1722_QI2_MASK;
785         if (cip_qi2 != 0x80)
786         {
787             expert_add_info(pinfo, ti, &ei_1722_61883_incorrect_qi2);
788         }
789
790         /* Check format field for 61883-4 MPEG-TS video or 61883-6 for audio */
791         ti_cip_fmt = proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_fmt, tvb, offset, 1, ENC_BIG_ENDIAN);
792         cip_fmt = tvb_get_guint8(tvb, offset) & IEEE_1722_FMT_MASK;
793         offset += 1;
794
795         if ((cip_fmt & 0x20) == 0)
796         {
797             proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_fdf, tvb, offset, 1, ENC_BIG_ENDIAN);
798             offset += 1;
799             proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_syt, tvb, offset, 2, ENC_BIG_ENDIAN);
800             offset += 2;
801         }
802         else
803         {
804             ti_cip_fdf = proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_fdf_no_syt, tvb, offset, 3, ENC_BIG_ENDIAN);
805             if (((tvb_get_guint8(tvb, offset) & 0x007fffff) != 0))
806             {
807                 expert_add_info(pinfo, ti_cip_fdf, &ei_1722_61883_incorrect_cip_fdf);
808             }
809
810             proto_tree_add_item(ti_61883_tree, hf_1722_61883_cip_fdf_tsf, tvb, offset, 3, ENC_BIG_ENDIAN);
811             offset += 3;
812         }
813
814         /* Calculate the remaining size by subtracting the CIP header size from the value in the packet data length field */
815         datalen -= IEEE_1722_CIP_HEADER_SIZE;
816
817         if (cip_dbs == 0) {
818             db_size = 256;
819         }
820         else
821         {
822             db_size = cip_dbs;
823         }
824
825         switch (cip_fmt) {
826         case IEEE_1722_61883_6:
827             if (cip_fn != 0)
828             {
829                 expert_add_info(pinfo, ti_cip_fn, &ei_1722_61883_6_incorrect_cip_fn);
830             }
831             if (cip_sph != 0)
832             {
833                 expert_add_info(pinfo, ti_cip_sph, &ei_1722_61883_6_incorrect_cip_sph);
834             }
835
836             /* Make the Audio sample tree. */
837             ti = proto_tree_add_item(ti_61883_tree, hf_1722_61883_audio_data, tvb, offset, datalen, ENC_NA);
838             ti_audio_tree = proto_item_add_subtree(ti, ett_1722_61883_audio);
839             if ((datalen % (db_size*4)) != 0)
840             {
841                 expert_add_info(pinfo, ti, &ei_1722_61883_incorrect_datalen);
842                 expert_add_info(pinfo, ti_datalen, &ei_1722_61883_incorrect_datalen);
843             }
844             numSourcePackets = datalen / (db_size*4);
845
846             if (ti_audio_tree) {
847                 /* Loop through all samples and add them to the audio tree. */
848                 for (j = 0; j < numSourcePackets; j++) {
849                     ti_sample_tree = proto_tree_add_subtree_format(ti_audio_tree, tvb, offset, 1, ett_1722_61883_sample, NULL, "Sample %d", j+1);
850                     for (i = 0; i < db_size; i++) {
851                         proto_tree_add_item(ti_sample_tree, hf_1722_61883_label, tvb, offset, 1, ENC_BIG_ENDIAN);
852                         offset += 1;
853                         proto_tree_add_item(ti_sample_tree, hf_1722_61883_sample, tvb, offset, 3, ENC_NA);
854                         offset += 3;
855                     }
856                 }
857             }
858             break;
859         case IEEE_1722_61883_4:
860             if (db_size != 6)
861             {
862                 expert_add_info(pinfo, ti_cip_dbs, &ei_1722_61883_4_incorrect_cip_dbs);
863             }
864             if (cip_fn != 8)
865             {
866                 expert_add_info(pinfo, ti_cip_fn, &ei_1722_61883_4_incorrect_cip_fn);
867             }
868             if (cip_sph != 4)
869             {
870                 expert_add_info(pinfo, ti_cip_sph, &ei_1722_61883_4_incorrect_cip_sph);
871             }
872             /* Make the video tree. */
873             ti = proto_tree_add_item(ti_61883_tree, hf_1722_61883_video_data, tvb, offset, datalen, ENC_NA);
874             ti_video_tree = proto_item_add_subtree(ti, ett_1722_61883_video);
875             if ((datalen % IEEE_1722_61883_4_LEN_SOURCE_PACKET) != 0)
876             {
877                 expert_add_info(pinfo, ti, &ei_1722_61883_incorrect_datalen);
878                 expert_add_info(pinfo, ti_datalen, &ei_1722_61883_incorrect_datalen);
879             }
880             numSourcePackets = datalen / IEEE_1722_61883_4_LEN_SOURCE_PACKET;
881
882             if (ti_video_tree) {
883                 /* Loop through all packets and add them to the video tree. */
884                 for (j = 0; j < numSourcePackets; j++) {
885                     proto_tree_add_item(ti_video_tree, hf_1722_61883_source_packet_header_timestamp, tvb, offset, IEEE_1722_61883_4_LEN_SP_TIMESTAMP, ENC_BIG_ENDIAN);
886                     offset += IEEE_1722_61883_4_LEN_SP_TIMESTAMP;
887                     proto_tree_add_item(ti_video_tree, hf_1722_61883_video_data, tvb, offset, (IEEE_1722_61883_4_LEN_SOURCE_PACKET - IEEE_1722_61883_4_LEN_SP_TIMESTAMP), ENC_NA);
888                     offset += (IEEE_1722_61883_4_LEN_SOURCE_PACKET - IEEE_1722_61883_4_LEN_SP_TIMESTAMP);
889                 }
890             }
891             break;
892         default:
893             expert_add_info(pinfo, ti_cip_fmt, &ei_1722_61883_unknown_format);
894             break;
895         }
896         break;
897     default:
898         break;
899     }
900     return tvb_captured_length(tvb);
901 }
902
903 void proto_register_1722_61883(void)
904 {
905     static hf_register_info hf[] = {
906         { &hf_1722_61883_mrfield,
907             { "Media Clock Restart", "61883.mrfield",
908               FT_BOOLEAN, 8, NULL, IEEE_1722_MR_MASK, NULL, HFILL }
909         },
910         { &hf_1722_61883_gvfield,
911             { "Gateway Info Valid", "61883.gvfield",
912               FT_BOOLEAN, 8, NULL, IEEE_1722_GV_MASK, NULL, HFILL }
913         },
914         { &hf_1722_61883_tvfield,
915             { "Timestamp Valid", "61883.tvfield",
916               FT_BOOLEAN, 8, NULL, IEEE_1722_TV_MASK, NULL, HFILL }
917             },
918         { &hf_1722_61883_seqnum,
919             { "Sequence Number", "61883.seqnum",
920               FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
921         },
922         { &hf_1722_61883_tufield,
923             { "Timestamp Uncertain", "61883.tufield",
924               FT_BOOLEAN, 8, NULL, IEEE_1722_TU_MASK, NULL, HFILL }
925         },
926         { &hf_1722_61883_stream_id,
927             { "Stream ID", "61883.stream_id",
928               FT_UINT64, BASE_HEX, NULL, 0x00, NULL, HFILL }
929         },
930         { &hf_1722_61883_avtp_timestamp,
931             { "AVTP Timestamp", "61883.avtp_timestamp",
932               FT_UINT32, BASE_HEX, NULL, 0x00, NULL, HFILL }
933         },
934         { &hf_1722_61883_gateway_info,
935             { "Gateway Info", "61883.gateway_info",
936               FT_UINT32, BASE_HEX, NULL, 0x00, NULL, HFILL }
937         },
938         { &hf_1722_61883_stream_data_length,
939             { "1394 Stream Data Length", "61883.stream_data_len",
940               FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, 0x00, NULL, HFILL }
941         },
942         { &hf_1722_61883_tag,
943             { "1394 Packet Format Tag", "61883.tag",
944               FT_UINT8, BASE_HEX, VALS(tag_vals), IEEE_1722_TAG_MASK, NULL, HFILL }
945         },
946         { &hf_1722_61883_channel,
947             { "1394 Packet Channel", "61883.channel",
948                 FT_UINT8, BASE_DEC, NULL, IEEE_1722_CHANNEL_MASK, NULL, HFILL }
949         },
950         { &hf_1722_61883_tcode,
951             { "1394 Packet Tcode", "61883.tcode",
952               FT_UINT8, BASE_HEX, NULL, IEEE_1722_TCODE_MASK, NULL, HFILL }
953         },
954         { &hf_1722_61883_sy,
955             { "1394 App-specific Control", "61883.sy",
956               FT_UINT8, BASE_HEX, NULL, IEEE_1722_SY_MASK, NULL, HFILL }
957         },
958         { &hf_1722_61883_cip_qi1,
959             { "CIP Quadlet Indicator 1", "61883.qi1",
960               FT_UINT8, BASE_HEX, NULL, IEEE_1722_QI1_MASK, NULL, HFILL }
961         },
962         { &hf_1722_61883_cip_sid,
963             { "CIP Source ID", "61883.sid",
964               FT_UINT8, BASE_DEC, NULL, IEEE_1722_SID_MASK, NULL, HFILL }
965         },
966         { &hf_1722_61883_cip_dbs,
967             { "CIP Data Block Size", "61883.dbs",
968               FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
969         },
970         { &hf_1722_61883_cip_fn,
971             { "CIP Fraction Number", "61883.fn",
972               FT_UINT8, BASE_HEX, VALS(fraction_number_vals), IEEE_1722_FN_MASK, NULL, HFILL }
973         },
974         { &hf_1722_61883_cip_qpc,
975             { "CIP Quadlet Padding Count", "61883.qpc",
976               FT_UINT8, BASE_HEX, NULL, IEEE_1722_QPC_MASK, NULL, HFILL }
977         },
978         { &hf_1722_61883_cip_sph,
979             { "CIP Source Packet Header", "61883.sph",
980               FT_BOOLEAN, 8, NULL, IEEE_1722_SPH_MASK, NULL, HFILL }
981         },
982         { &hf_1722_61883_cip_dbc,
983             { "CIP Data Block Continuity", "61883.dbc",
984               FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
985         },
986         { &hf_1722_61883_cip_qi2,
987             { "CIP Quadlet Indicator 2", "61883.qi2",
988               FT_UINT8, BASE_HEX, NULL, IEEE_1722_QI2_MASK, NULL, HFILL }
989         },
990         { &hf_1722_61883_cip_fmt,
991             { "CIP Format ID", "61883.fmt",
992               FT_UINT8, BASE_HEX | BASE_RANGE_STRING, RVALS(format_rvals), IEEE_1722_FMT_MASK, NULL, HFILL }
993         },
994         { &hf_1722_61883_cip_fdf_no_syt,
995             { "CIP Format Dependent Field", "61883.fdf_no_syt",
996               FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
997         },
998         { &hf_1722_61883_cip_fdf_tsf,
999             { "Time shift flag", "61883.fdf_tsf",
1000               FT_BOOLEAN, 8, NULL, IEEE_1722_FDF_TSF_MASK, NULL, HFILL }
1001         },
1002         { &hf_1722_61883_cip_fdf,
1003             { "CIP Format Dependent Field", "61883.fdf",
1004               FT_UINT8, BASE_HEX | BASE_RANGE_STRING, RVALS(fdf_rvals), IEEE_1722_FDF_MASK, NULL, HFILL }
1005         },
1006         { &hf_1722_61883_cip_syt,
1007             { "CIP SYT", "61883.syt",
1008               FT_UINT16, BASE_HEX | BASE_RANGE_STRING, RVALS(syt_rvals), 0x00, NULL, HFILL }
1009         },
1010         { &hf_1722_61883_audio_data,
1011             { "Audio Data", "61883.audiodata",
1012               FT_BYTES, BASE_NONE, NULL, 0x00, NULL, HFILL }
1013         },
1014         { &hf_1722_61883_label,
1015             { "Label", "61883.audiodata.sample.label",
1016               FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
1017         },
1018         { &hf_1722_61883_sample,
1019             { "Sample", "61883.audiodata.sample.sampledata",
1020               FT_BYTES, BASE_NONE, NULL, 0x00, NULL, HFILL }
1021         },
1022         { &hf_1722_61883_video_data,
1023             { "Video Data", "61883.videodata",
1024               FT_BYTES, BASE_NONE, NULL, 0x00, NULL, HFILL }
1025         },
1026         { &hf_1722_61883_source_packet_header_timestamp,
1027             { "Source Packet Header Timestamp", "61883.spht",
1028               FT_UINT32, BASE_HEX, NULL, 0x00, NULL, HFILL }
1029         }
1030     };
1031
1032     static gint *ett[] = {
1033         &ett_1722_61883,
1034         &ett_1722_61883_audio,
1035         &ett_1722_61883_sample,
1036         &ett_1722_61883_video
1037     };
1038
1039     static ei_register_info ei[] = {
1040         { &ei_1722_61883_incorrect_tag,         { "61883.incorrect_tag", PI_PROTOCOL, PI_WARN,
1041                                                   "Incorrect tag field, only 0x00 and 0x01 supported for AVTP", EXPFILL }},
1042         { &ei_1722_61883_incorrect_tcode,       { "61883.incorrect_tcode", PI_PROTOCOL, PI_WARN,
1043                                                   "Incorrect tcode, talker shall set this field to 0x0A", EXPFILL }},
1044         { &ei_1722_61883_incorrect_qi1,         { "61883.incorrect_qi1", PI_PROTOCOL, PI_WARN,
1045                                                   "Incorrect quadlet indicator 1 field, talker shall set this field to 0x00", EXPFILL }},
1046         { &ei_1722_61883_incorrect_qpc,         { "61883.incorrect_qpc", PI_PROTOCOL, PI_WARN,
1047                                                   "Incorrect quadlet padding count field, shall be set to 0", EXPFILL }},
1048         { &ei_1722_61883_incorrect_qi2,         { "61883.incorrect_qi2", PI_PROTOCOL, PI_WARN,
1049                                                   "Incorrect quadlet indicator 2 field, talker shall set this field to 0x02", EXPFILL }},
1050         { &ei_1722_61883_unknown_format,        { "61883.unknown_format", PI_PROTOCOL, PI_NOTE,
1051                                                   "IEC 61883 format not dissected yet", EXPFILL }},
1052         { &ei_1722_61883_incorrect_channel_sid, { "61883.incorrect_channel_sid", PI_PROTOCOL, PI_WARN,
1053                                                   "1394 Packet Channel and Source ID don`t match", EXPFILL }},
1054         { &ei_1722_61883_incorrect_datalen,     { "61883.incorrect_datalen", PI_PROTOCOL, PI_WARN,
1055                                                   "Incorrect stream data length field, must be multiple of 192 plus 8 bytes CIP header", EXPFILL }},
1056         { &ei_1722_61883_4_incorrect_cip_fn,    { "61883.4_incorrect_cip_fn", PI_PROTOCOL, PI_WARN,
1057                                                   "Incorrect fraction number, shall be 8 for IEC 61883-4", EXPFILL }},
1058         { &ei_1722_61883_4_incorrect_cip_dbs,   { "61883.4_incorrect_cip_dbs", PI_PROTOCOL, PI_WARN,
1059                                                   "Incorrect data block size, shall be 6 for IEC 61883-4", EXPFILL }},
1060         { &ei_1722_61883_4_incorrect_cip_sph,   { "61883.4_incorrect_cip_sph", PI_PROTOCOL, PI_WARN,
1061                                                   "Incorrect source packet header value, shall be 1 for IEC 61883-4", EXPFILL }},
1062         { &ei_1722_61883_6_incorrect_cip_fn,    { "61883.6_incorrect_cip_fn", PI_PROTOCOL, PI_WARN,
1063                                                   "Incorrect fraction number, shall be 0 for IEC 61883-6", EXPFILL }},
1064         { &ei_1722_61883_6_incorrect_cip_sph,   { "61883.6_incorrect_cip_sph", PI_PROTOCOL, PI_WARN,
1065                                                   "Incorrect source packet header value, shall be 0 for IEC 61883-6", EXPFILL }},
1066         { &ei_1722_61883_incorrect_cip_fdf,     { "61883.6_incorrect_cip_fdf", PI_PROTOCOL, PI_WARN,
1067                                                   "Incorrect frame dependent field value, shall be 0", EXPFILL }}
1068     };
1069
1070     expert_module_t* expert_1722_61883;
1071
1072     /* Register the protocol name and description */
1073     proto_1722_61883 = proto_register_protocol(
1074                 "IEC 61883 Protocol",   /* name */
1075                 "IEC 61883",            /* short name */
1076                 "61883");               /* abbrev */
1077
1078     /* Required function calls to register the header fields and subtrees used */
1079     proto_register_field_array(proto_1722_61883, hf, array_length(hf));
1080     proto_register_subtree_array(ett, array_length(ett));
1081     expert_1722_61883 = expert_register_protocol(proto_1722_61883);
1082     expert_register_field_array(expert_1722_61883, ei, array_length(ei));
1083 }
1084
1085 void proto_reg_handoff_1722_61883(void)
1086 {
1087     dissector_handle_t avb1722_61883_handle;
1088
1089     avb1722_61883_handle = create_dissector_handle(dissect_1722_61883, proto_1722_61883);
1090     dissector_add_uint("ieee1722.subtype", IEEE_1722_SUBTYPE_61883, avb1722_61883_handle);
1091 }
1092
1093 /**************************************************************************************************/
1094 /* 1722 AAF dissector implementation                                                              */
1095 /*                                                                                                */
1096 /**************************************************************************************************/
1097 static int dissect_1722_aaf (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1098 {
1099     proto_item *ti;
1100     proto_tree *ti_aaf_tree;
1101     proto_tree *ti_channels_per_frame;
1102     proto_tree *ti_format;
1103     proto_tree *ti_audio_tree;
1104     proto_tree *ti_sample_tree;
1105     gint        offset = 1;
1106     guint       datalen = 0;
1107     guint       channels_per_frame = 0;
1108     guint       bit_depth = 0;
1109     guint       sample_width = 0;
1110     guint       format = 0;
1111     guint       i = 0;
1112     guint       j = 0;
1113     const gint *fields[] = {
1114         &hf_1722_aaf_mrfield,
1115         &hf_1722_aaf_tvfield,
1116         NULL
1117     };
1118     const gint *fields_pcm[] = {
1119         &hf_1722_aaf_sparse_timestamp,
1120         &hf_1722_aaf_evtfield,
1121         NULL
1122     };
1123
1124     ti = proto_tree_add_item(tree, proto_1722_aaf, tvb, 0, -1, ENC_NA);
1125     ti_aaf_tree = proto_item_add_subtree(ti, ett_1722_aaf);
1126
1127     proto_tree_add_bitmask_list(ti_aaf_tree, tvb, offset, 1, fields, ENC_NA);
1128     offset += 1;
1129     proto_tree_add_item(ti_aaf_tree, hf_1722_aaf_seqnum, tvb, offset, 1, ENC_BIG_ENDIAN);
1130     offset += 1;
1131     proto_tree_add_item(ti_aaf_tree, hf_1722_aaf_tufield, tvb, offset, 1, ENC_BIG_ENDIAN);
1132     offset += 1;
1133     proto_tree_add_item(ti_aaf_tree, hf_1722_aaf_stream_id, tvb, offset, 8, ENC_BIG_ENDIAN);
1134     offset += 8;
1135     proto_tree_add_item(ti_aaf_tree, hf_1722_aaf_avtp_timestamp, tvb, offset, 4, ENC_BIG_ENDIAN);
1136     offset += 4;
1137
1138     ti_format = proto_tree_add_item_ret_uint(ti_aaf_tree, hf_1722_aaf_format, tvb, offset, 1, ENC_BIG_ENDIAN, &format);
1139     offset += 1;
1140     switch (format)
1141     {
1142     case IEEE_1722_AAF_FORMAT_USER:
1143         break;
1144     case IEEE_1722_AAF_FORMAT_FLOAT_32_BIT:
1145         sample_width = 32;
1146         break;
1147     case IEEE_1722_AAF_FORMAT_INT_32_BIT:
1148         sample_width = 32;
1149         break;
1150     case IEEE_1722_AAF_FORMAT_INT_24_BIT:
1151         sample_width = 24;
1152         break;
1153     case IEEE_1722_AAF_FORMAT_INT_16_BIT:
1154         sample_width = 16;
1155         break;
1156     case IEEE_1722_AAF_FORMAT_AES3_32_BIT:
1157         sample_width = 32;
1158         break;
1159     default:
1160         break;
1161     }
1162
1163     if (format < IEEE_1722_AAF_FORMAT_AES3_32_BIT)
1164     {
1165         proto_tree_add_item(ti_aaf_tree, hf_1722_aaf_nominal_sample_rate, tvb, offset, 2, ENC_BIG_ENDIAN);
1166         ti_channels_per_frame = proto_tree_add_item_ret_uint(ti_aaf_tree, hf_1722_aaf_channels_per_frame, tvb, offset, 2, ENC_BIG_ENDIAN, &channels_per_frame);
1167         if (channels_per_frame == 0)
1168         {
1169             expert_add_info(pinfo, ti_channels_per_frame, &ei_aaf_channels_per_frame);
1170         }
1171         else
1172         {
1173             offset += 2;
1174             ti = proto_tree_add_item_ret_uint(ti_aaf_tree, hf_1722_aaf_bit_depth, tvb, offset, 1, ENC_BIG_ENDIAN, &bit_depth);
1175             if ((bit_depth == 0) || (bit_depth > sample_width))
1176             {
1177                 expert_add_info(pinfo, ti, &ei_aaf_incorrect_bit_depth);
1178             }
1179             offset += 1;
1180             proto_tree_add_item_ret_uint(ti_aaf_tree, hf_1722_aaf_stream_data_length, tvb, offset, 2, ENC_BIG_ENDIAN, &datalen);
1181             offset += 2;
1182
1183             proto_tree_add_bitmask_list(ti_aaf_tree, tvb, offset, 1, fields_pcm, ENC_BIG_ENDIAN);
1184             offset += 2;
1185
1186             /* Make the Audio sample tree. */
1187             ti            = proto_tree_add_item(ti_aaf_tree, hf_1722_aaf_data, tvb, offset, datalen, ENC_NA);
1188             ti_audio_tree = proto_item_add_subtree(ti, ett_1722_aaf_audio);
1189
1190             if (sample_width == 0)
1191             {
1192                 expert_add_info(pinfo, ti, &ei_aaf_sample_width);
1193             }
1194             else
1195             {
1196                 /* Loop through all samples and add them to the audio tree. */
1197                 for (j = 0; j < ((datalen * 8) / (channels_per_frame * sample_width)); j++)
1198                 {
1199                     ti_sample_tree = proto_tree_add_subtree_format(ti_audio_tree, tvb, offset, 1,
1200                                          ett_1722_aaf_sample, NULL, "Sample Chunk %d", j);
1201                     for (i = 0; i < channels_per_frame; i++)
1202                     {
1203                         ti = proto_tree_add_item(ti_sample_tree, hf_1722_aaf_sample, tvb, offset, sample_width / 8, ENC_NA);
1204                         proto_item_prepend_text(ti, "Channel: %d ", i);
1205                         offset += (sample_width / 8);
1206                     }
1207                 }
1208             }
1209         }
1210     }
1211     else if (format == IEEE_1722_AAF_FORMAT_AES3_32_BIT)
1212     {
1213         expert_add_info(pinfo, ti_format, &ei_aaf_aes3_format);
1214     }
1215     else
1216     {
1217         expert_add_info(pinfo, ti_format, &ei_aaf_reserved_format);
1218     }
1219     return tvb_captured_length(tvb);
1220 }
1221
1222 void proto_register_1722_aaf (void)
1223 {
1224     static hf_register_info hf[] =
1225     {
1226         { &hf_1722_aaf_mrfield,
1227             { "Media Clock Restart", "aaf.mrfield",
1228               FT_BOOLEAN, 8, NULL, IEEE_1722_MR_MASK, NULL, HFILL }
1229         },
1230         { &hf_1722_aaf_tvfield,
1231             { "Source Timestamp Valid", "aaf.tvfield",
1232               FT_BOOLEAN, 8, NULL, IEEE_1722_TV_MASK, NULL, HFILL }
1233             },
1234         { &hf_1722_aaf_seqnum,
1235             { "Sequence Number", "aaf.seqnum",
1236               FT_UINT8, BASE_DEC, NULL, IEEE_1722_SEQ_NUM_MASK, NULL, HFILL }
1237         },
1238         { &hf_1722_aaf_tufield,
1239             { "Timestamp Uncertain", "aaf.tufield",
1240               FT_BOOLEAN, 8, NULL, IEEE_1722_TU_MASK, NULL, HFILL }
1241         },
1242         { &hf_1722_aaf_stream_id,
1243             { "Stream ID", "aaf.stream_id",
1244               FT_UINT64, BASE_HEX, NULL, IEEE_1722_STREAM_ID_MASK, NULL, HFILL }
1245         },
1246         { &hf_1722_aaf_avtp_timestamp,
1247             { "AVTP Timestamp", "aaf.avtp_timestamp",
1248               FT_UINT32, BASE_DEC, NULL, IEEE_1722_TIMESTAMP_MASK, NULL, HFILL }
1249         },
1250         { &hf_1722_aaf_format,
1251             { "Format", "aaf.format_info",
1252               FT_UINT8, BASE_HEX | BASE_RANGE_STRING, RVALS(aaf_format_range_rvals), IEEE_1722_FORMAT_MASK, NULL, HFILL }
1253         },
1254         { &hf_1722_aaf_nominal_sample_rate,
1255             { "Nominal Sample Rate", "aaf.nominal_sample_rate",
1256               FT_UINT16, BASE_HEX | BASE_RANGE_STRING, RVALS(aaf_nominal_sample_rate_range_rvals), IEEE_1722_NOM_SAMPLE_RATE_MASK, NULL, HFILL }
1257         },
1258         { &hf_1722_aaf_channels_per_frame,
1259             { "Channels per Frame", "aaf.channels_per_frame",
1260               FT_UINT16, BASE_DEC, NULL, IEEE_1722_CHANNEL_PER_FRAME_MASK, NULL, HFILL }
1261         },
1262         { &hf_1722_aaf_bit_depth,
1263             { "Bit Depth", "aaf.bit_depth",
1264               FT_UINT8, BASE_DEC, NULL, IEEE_1722_BIT_DEPTH_MASK, NULL, HFILL }
1265         },
1266         { &hf_1722_aaf_stream_data_length,
1267             { "Stream Data Length", "aaf.stream_data_len",
1268               FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, IEEE_1722_STREAM_DATA_LENGTH_MASK, NULL, HFILL }
1269         },
1270         { &hf_1722_aaf_sparse_timestamp,
1271             { "Sparse Timestamp Mode", "aaf.sparse_timestamp",
1272               FT_UINT8, BASE_DEC, VALS(aaf_sparse_timestamp_vals), IEEE_1722_SP_MASK, NULL, HFILL }
1273         },
1274         { &hf_1722_aaf_evtfield,
1275             { "EVT", "aaf.evtfield",
1276               FT_UINT8, BASE_HEX, NULL, IEEE_1722_EVT_MASK, NULL, HFILL }
1277         },
1278         { &hf_1722_aaf_data,
1279             { "Audio Data", "aaf.data",
1280               FT_BYTES, BASE_NONE, NULL, IEEE_1722_DATA_MASK, NULL, HFILL }
1281         },
1282         { &hf_1722_aaf_sample,
1283             { "Sample Data", "aaf.data.sample",
1284               FT_BYTES, BASE_NONE, NULL, IEEE_1722_SAMPLE_MASK, NULL, HFILL }
1285         }
1286     };
1287
1288     static ei_register_info ei[] = {
1289         { &ei_aaf_sample_width,          { "aaf.expert.sample_width_zero", PI_PROTOCOL, PI_WARN, "Sample_width of 0 can`t be dissected", EXPFILL }},
1290         { &ei_aaf_reserved_format,       { "aaf.expert.reserved_format", PI_PROTOCOL, PI_WARN, "Incorrect format, can`t be dissected", EXPFILL }},
1291         { &ei_aaf_aes3_format,           { "aaf.expert.aes3_format", PI_PROTOCOL, PI_WARN, "AES3 format is currently not supported", EXPFILL }},
1292         { &ei_aaf_channels_per_frame,    { "aaf.expert.channels_per_frame_zero", PI_PROTOCOL, PI_WARN, "Channels_per_frame value shall not be 0", EXPFILL }},
1293         { &ei_aaf_incorrect_bit_depth,   { "aaf.expert.incorrect_bit_depth", PI_PROTOCOL, PI_WARN, "Incorrect bit_depth value", EXPFILL }}
1294     };
1295
1296     static gint *ett[] =
1297     {
1298         &ett_1722_aaf,
1299         &ett_1722_aaf_audio,
1300         &ett_1722_aaf_sample,
1301     };
1302
1303     expert_module_t *expert_1722_aaf;
1304
1305     /* Register the protocol name and description */
1306     proto_1722_aaf = proto_register_protocol("AVTP Audio Format", "AAF", "aaf");
1307
1308     /* Required function calls to register the header fields and subtrees used */
1309     proto_register_field_array(proto_1722_aaf, hf, array_length(hf));
1310     proto_register_subtree_array(ett, array_length(ett));
1311
1312     expert_1722_aaf = expert_register_protocol(proto_1722_aaf);
1313     expert_register_field_array(expert_1722_aaf, ei, array_length(ei));
1314 }
1315
1316 void proto_reg_handoff_1722_aaf(void)
1317 {
1318     dissector_handle_t avb1722_aaf_handle;
1319
1320     avb1722_aaf_handle = create_dissector_handle(dissect_1722_aaf, proto_1722_aaf);
1321     dissector_add_uint("ieee1722.subtype", IEEE_1722_SUBTYPE_AAF, avb1722_aaf_handle);
1322 }
1323
1324 /**************************************************************************************************/
1325 /* 1722 CVF dissector implementation                                                              */
1326 /*                                                                                                */
1327 /**************************************************************************************************/
1328 static int dissect_1722_cvf (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1329 {
1330     proto_item *ti;
1331     proto_tree *ti_cvf_tree;
1332     gint        offset = 1;
1333     guint       format_subtype = 0;
1334     proto_tree *ti_format;
1335
1336     const gint *fields[] = {
1337         &hf_1722_cvf_mrfield,
1338         &hf_1722_cvf_tvfield,
1339         NULL
1340     };
1341     const gint *fields_cvf[] = {
1342         &hf_1722_cvf_marker_bit,
1343         &hf_1722_cvf_evtfield,
1344         NULL
1345     };
1346
1347     const gint *fields_h264[] = {
1348         &hf_1722_cvf_h264_forbidden_bit,
1349         &hf_1722_cvf_h264_nri,
1350         &hf_1722_cvf_h264_nal_type,
1351         NULL
1352     };
1353
1354     ti = proto_tree_add_item(tree, proto_1722_cvf, tvb, 0, -1, ENC_NA);
1355     ti_cvf_tree = proto_item_add_subtree(ti, ett_1722_cvf);
1356
1357     proto_tree_add_bitmask_list(ti_cvf_tree, tvb, offset, 1, fields, ENC_NA);
1358     offset += 1;
1359     proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_seqnum, tvb, offset, 1, ENC_BIG_ENDIAN);
1360     offset += 1;
1361     proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_tufield, tvb, offset, 1, ENC_BIG_ENDIAN);
1362     offset += 1;
1363     proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_stream_id, tvb, offset, 8, ENC_BIG_ENDIAN);
1364     offset += 8;
1365     proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_avtp_timestamp, tvb, offset, 4, ENC_BIG_ENDIAN);
1366     offset += 4;
1367     proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_format, tvb, offset, 1, ENC_BIG_ENDIAN);
1368     offset += 1;
1369     ti_format = proto_tree_add_item_ret_uint(ti_cvf_tree, hf_1722_cvf_format_subtype, tvb, offset, 1, ENC_BIG_ENDIAN, &format_subtype);
1370     offset += 3;
1371     proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_stream_data_length, tvb, offset, 2, ENC_BIG_ENDIAN);
1372     offset += 2;
1373     proto_tree_add_bitmask_list(ti_cvf_tree, tvb, offset, 1, fields_cvf, ENC_BIG_ENDIAN);
1374     offset += 2;
1375
1376     switch(format_subtype) {
1377     case IEEE_1722_CVF_FORMAT_SUBTYPE_MJPEG:
1378         proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_mjpeg_ts, tvb, offset, 1, ENC_BIG_ENDIAN);
1379         offset += 1;
1380         proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_mjpeg_fragment_offset, tvb, offset, 3, ENC_BIG_ENDIAN);
1381         offset += 3;
1382         proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_mjpeg_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1383         offset += 1;
1384         proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_mjpeg_q, tvb, offset, 1, ENC_BIG_ENDIAN);
1385         offset += 1;
1386         proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_mjpeg_width, tvb, offset, 1, ENC_BIG_ENDIAN);
1387         offset += 1;
1388         proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_mjpeg_height, tvb, offset, 1, ENC_BIG_ENDIAN);
1389         break;
1390
1391     case IEEE_1722_CVF_FORMAT_SUBTYPE_H264:
1392         proto_tree_add_item(ti_cvf_tree, hf_1722_cvf_h264_timestamp, tvb, offset, 4, ENC_BIG_ENDIAN);
1393         offset += 4;
1394         proto_tree_add_bitmask_list(ti_cvf_tree, tvb, offset, 1, fields_h264, ENC_BIG_ENDIAN);
1395         break;
1396
1397     case IEEE_1722_CVF_FORMAT_SUBTYPE_JPEG2000:
1398         expert_add_info(pinfo, ti_format, &ei_cvf_jpeg2000_format);
1399         break;
1400
1401     default:
1402         expert_add_info(pinfo, ti_format, &ei_cvf_reserved_format);
1403         break;
1404     }
1405     return tvb_captured_length(tvb);
1406 }
1407
1408 void proto_register_1722_cvf (void)
1409 {
1410     static hf_register_info hf[] =
1411     {
1412         { &hf_1722_cvf_mrfield,
1413             { "Media Clock Restart", "cvf.mrfield",
1414               FT_BOOLEAN, 8, NULL, IEEE_1722_MR_MASK, NULL, HFILL }
1415         },
1416         { &hf_1722_cvf_tvfield,
1417             { "Source Timestamp Valid", "cvf.tvfield",
1418               FT_BOOLEAN, 8, NULL, IEEE_1722_TV_MASK, NULL, HFILL }
1419             },
1420         { &hf_1722_cvf_seqnum,
1421             { "Sequence Number", "cvf.seqnum",
1422               FT_UINT8, BASE_DEC, NULL, IEEE_1722_SEQ_NUM_MASK, NULL, HFILL }
1423         },
1424         { &hf_1722_cvf_tufield,
1425             { "Timestamp Uncertain", "cvf.tufield",
1426               FT_BOOLEAN, 8, NULL, IEEE_1722_TU_MASK, NULL, HFILL }
1427         },
1428         { &hf_1722_cvf_stream_id,
1429             { "Stream ID", "cvf.stream_id",
1430               FT_UINT64, BASE_HEX, NULL, IEEE_1722_STREAM_ID_MASK, NULL, HFILL }
1431         },
1432         { &hf_1722_cvf_avtp_timestamp,
1433             { "AVTP Timestamp", "cvf.avtp_timestamp",
1434               FT_UINT32, BASE_DEC, NULL, IEEE_1722_TIMESTAMP_MASK, NULL, HFILL }
1435         },
1436         { &hf_1722_cvf_format,
1437             { "Format", "cvf.format",
1438               FT_UINT8, BASE_HEX | BASE_RANGE_STRING, RVALS(cvf_format_range_rvals), IEEE_1722_FORMAT_MASK, NULL, HFILL }
1439         },
1440         { &hf_1722_cvf_format_subtype,
1441             { "CVF Format Subtype", "cvf.format_subtype",
1442               FT_UINT8, BASE_HEX | BASE_RANGE_STRING, RVALS(cvf_format_subtype_range_rvals), IEEE_1722_FORMAT_SUBTYPE_MASK, NULL, HFILL }
1443         },
1444         { &hf_1722_cvf_stream_data_length,
1445             { "Stream Data Length", "cvf.stream_data_len",
1446               FT_UINT16, BASE_DEC | BASE_UNIT_STRING, &units_byte_bytes, IEEE_1722_STREAM_DATA_LENGTH_MASK, NULL, HFILL }
1447         },
1448         { &hf_1722_cvf_marker_bit,
1449             { "Marker Bit", "cvf.marker_bit",
1450               FT_BOOLEAN, 8, TFS(&tfs_marker_bit_set_not_set), IEEE_1722_MARKER_BIT_MASK, NULL, HFILL }
1451         },
1452         { &hf_1722_cvf_evtfield,
1453             { "EVT", "cvf.evtfield",
1454               FT_UINT8, BASE_HEX, NULL, IEEE_1722_EVT_MASK, NULL, HFILL }
1455         },
1456         { &hf_1722_cvf_h264_timestamp,
1457             { "H264 Timestamp", "cvf.h264_timestamp",
1458               FT_UINT32, BASE_DEC, NULL, IEEE_1722_CVF_H264_TIMESTAMP_MASK, NULL, HFILL }
1459         },
1460         { &hf_1722_cvf_h264_forbidden_bit,
1461             { "H264 Forbidden Bit", "cvf.h264_f_bit",
1462               FT_BOOLEAN, 8, NULL, IEEE_1722_CVF_H264_FORBIDDEN_MASK, NULL, HFILL }
1463         },
1464         { &hf_1722_cvf_h264_nri,
1465             { "H264 NRI", "cvf.h264_nri",
1466               FT_UINT8, BASE_HEX, NULL, IEEE_1722_CVF_H264_NRI_MASK, NULL, HFILL }
1467         },
1468         { &hf_1722_cvf_h264_nal_type,
1469             { "H264 NAL Type", "cvf.h264_nal_type",
1470               FT_UINT8, BASE_HEX | BASE_RANGE_STRING, RVALS(cvf_h264_nal_type_range_rvals), IEEE_1722_CVF_H264_NAL_TYPE_MASK, NULL, HFILL }
1471         },
1472         { &hf_1722_cvf_mjpeg_ts,
1473             { "MJPEG Type Specific", "cvf.mjpeg_type_specific",
1474               FT_UINT8, BASE_DEC | BASE_RANGE_STRING, RVALS(cvf_mjpeg_ts_range_rvals), IEEE_1722_CVF_MJPEG_TS_MASK, NULL, HFILL }
1475         },
1476         { &hf_1722_cvf_mjpeg_fragment_offset,
1477             { "MJPEG Fragment Offset", "cvf.mjpeg_fragment_offset",
1478               FT_UINT24, BASE_DEC, NULL, IEEE_1722_CVF_MJPEG_FRAGMENT_OFFSET_MASK, NULL, HFILL }
1479         },
1480         { &hf_1722_cvf_mjpeg_type,
1481             { "MJPEG Type", "cvf.mjpeg_type",
1482               FT_UINT8, BASE_DEC, NULL, IEEE_1722_CVF_MJPEG_TYPE_MASK, NULL, HFILL }
1483         },
1484         { &hf_1722_cvf_mjpeg_q,
1485             { "MJPEG Q", "cvf.mjpeg_q",
1486                FT_UINT8, BASE_DEC, NULL, IEEE_1722_CVF_MJPEG_Q_MASK, NULL, HFILL }
1487         },
1488         { &hf_1722_cvf_mjpeg_width,
1489             { "MJPEG Width", "cvf.mjpeg_width",
1490                FT_UINT8, BASE_DEC, NULL, IEEE_1722_CVF_MJPEG_WIDTH_MASK, NULL, HFILL }
1491         },
1492         { &hf_1722_cvf_mjpeg_height,
1493             { "MJPEG Height", "cvf.mjpeg_height",
1494                FT_UINT8, BASE_DEC, NULL, IEEE_1722_CVF_MJPEG_HEIGHT_MASK, NULL, HFILL }
1495         },
1496
1497     };
1498
1499     static ei_register_info ei[] = {
1500         { &ei_cvf_jpeg2000_format,          { "cvf.expert.jpeg2000_video", PI_PROTOCOL, PI_WARN, "JPEG2000 format is currently not supported", EXPFILL }},
1501         { &ei_cvf_reserved_format,          { "cvf.expert.reserved_format", PI_PROTOCOL, PI_WARN, "Incorrect format, can`t be dissected", EXPFILL }}
1502     };
1503
1504     static gint *ett[] =
1505     {
1506         &ett_1722_cvf,
1507     };
1508
1509     expert_module_t *expert_1722_cvf;
1510
1511     /* Register the protocol name and description */
1512     proto_1722_cvf = proto_register_protocol("AVTP Compressed Video Format", "CVF", "cvf");
1513
1514     /* Required function calls to register the header fields and subtrees used */
1515     proto_register_field_array(proto_1722_cvf, hf, array_length(hf));
1516     proto_register_subtree_array(ett, array_length(ett));
1517
1518     expert_1722_cvf = expert_register_protocol(proto_1722_cvf);
1519     expert_register_field_array(expert_1722_cvf, ei, array_length(ei));
1520
1521 }
1522
1523 void proto_reg_handoff_1722_cvf(void)
1524 {
1525     dissector_handle_t avb1722_cvf_handle;
1526
1527     avb1722_cvf_handle = create_dissector_handle(dissect_1722_cvf, proto_1722_cvf);
1528     dissector_add_uint("ieee1722.subtype", IEEE_1722_SUBTYPE_CVF, avb1722_cvf_handle);
1529 }
1530
1531 /**************************************************************************************************/
1532 /* 1722 CRF dissector implementation                                                              */
1533 /*                                                                                                */
1534 /**************************************************************************************************/
1535 static int dissect_1722_crf (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1536 {
1537     proto_item *ti;
1538     proto_tree *ti_crf_tree;
1539     proto_tree *timestamp_tree;
1540     gint        offset = 1;
1541     guint       datalen = 0;
1542     guint       j = 0;
1543     const gint *fields[] = {
1544         &hf_1722_crf_mrfield,
1545         &hf_1722_crf_fsfield,
1546         &hf_1722_crf_tufield,
1547         NULL
1548     };
1549     const gint *pull_frequency[] = {
1550         &hf_1722_crf_pull,
1551         &hf_1722_crf_base_frequency,
1552         NULL
1553     };
1554
1555     ti = proto_tree_add_item(tree, proto_1722_crf, tvb, 0, -1, ENC_NA);
1556     ti_crf_tree = proto_item_add_subtree(ti, ett_1722_crf);
1557
1558     proto_tree_add_bitmask_list(ti_crf_tree, tvb, offset, 1, fields, ENC_NA);
1559     offset += 1;
1560     proto_tree_add_item(ti_crf_tree, hf_1722_crf_seqnum, tvb, offset, 1, ENC_BIG_ENDIAN);
1561     offset += 1;
1562     proto_tree_add_item(ti_crf_tree, hf_1722_crf_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1563     offset += 1;
1564     proto_tree_add_item(ti_crf_tree, hf_1722_crf_stream_id, tvb, offset, 8, ENC_BIG_ENDIAN);
1565     offset += 8;
1566     proto_tree_add_bitmask_list(ti_crf_tree, tvb, offset, 4, pull_frequency, ENC_NA);
1567     offset += 4;
1568     proto_tree_add_item_ret_uint(ti_crf_tree, hf_1722_crf_data_length, tvb, offset, 2, ENC_BIG_ENDIAN, &datalen);
1569     offset += 2;
1570     proto_tree_add_item(ti_crf_tree, hf_1722_crf_timestamp_interval, tvb, offset, 2, ENC_BIG_ENDIAN);
1571     offset += 2;
1572
1573     /* Make the Timestamp tree. */
1574     ti = proto_tree_add_item(ti_crf_tree, hf_1722_crf_timestamp_data, tvb, offset, datalen, ENC_NA);
1575     timestamp_tree = proto_item_add_subtree(ti, ett_1722_crf_timestamp);
1576
1577     if (datalen%8)
1578     {
1579         expert_add_info(pinfo, ti, &ei_crf_datalen);
1580     }
1581     else
1582     {
1583         /* Loop through all timestamps and add them to the timestamp tree. */
1584         for (j = 0; j < (datalen / IEEE_1722_CRF_TIMESTAMP_SIZE); j++)
1585         {
1586             ti = proto_tree_add_item(timestamp_tree, hf_1722_crf_timestamp, tvb, offset, IEEE_1722_CRF_TIMESTAMP_SIZE, ENC_BIG_ENDIAN);
1587             proto_item_prepend_text(ti, "Timestamp %d ", j);
1588             offset += IEEE_1722_CRF_TIMESTAMP_SIZE;
1589         }
1590     }
1591
1592     return tvb_captured_length(tvb);
1593 }
1594
1595 void proto_register_1722_crf(void)
1596 {
1597     static hf_register_info hf[] =
1598     {
1599         { &hf_1722_crf_mrfield,
1600           { "Media Clock Restart", "crf.mrfield",
1601             FT_BOOLEAN, 8, NULL, IEEE_1722_MR_MASK, NULL, HFILL }
1602         },
1603         { &hf_1722_crf_fsfield,
1604           { "Frame Sync", "crf.fsfield",
1605             FT_BOOLEAN, 8, NULL, IEEE_1722_FS_MASK, NULL, HFILL }
1606         },
1607         { &hf_1722_crf_tufield,
1608             { "Timestamp Uncertain", "crf.tufield",
1609               FT_BOOLEAN, 8, NULL, IEEE_1722_TU_MASK, NULL, HFILL }
1610         },
1611         { &hf_1722_crf_seqnum,
1612             { "Sequence Number", "crf.seqnum",
1613               FT_UINT8, BASE_DEC, NULL, 0x00, NULL, HFILL }
1614         },
1615         { &hf_1722_crf_type,
1616             { "Type", "crf.type",
1617               FT_UINT8, BASE_HEX | BASE_RANGE_STRING, RVALS(crf_type_range_rvals), 0x00, NULL, HFILL }
1618         },
1619         { &hf_1722_crf_stream_id,
1620             { "Stream ID", "crf.stream_id",
1621               FT_UINT64, BASE_HEX, NULL, 0x00, NULL, HFILL }
1622         },
1623         { &hf_1722_crf_pull,
1624             { "Pull", "crf.pull",
1625               FT_UINT32, BASE_HEX | BASE_RANGE_STRING, RVALS(crf_pull_range_rvals), IEEE_1722_PULL_MASK, NULL, HFILL }
1626         },
1627         { &hf_1722_crf_base_frequency,
1628             { "Base Frequency", "crf.base_frequency",
1629               FT_UINT32, BASE_DEC, NULL, IEEE_1722_BASE_FREQUENCY_MASK, NULL, HFILL }
1630         },
1631         { &hf_1722_crf_data_length,
1632             { "Data Length", "crf.data_len",
1633               FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, 0x00, NULL, HFILL }
1634         },
1635         { &hf_1722_crf_timestamp_interval,
1636             { "Timestamp Interval", "crf.timestamp_interval",
1637               FT_UINT16, BASE_DEC, NULL, 0x00, NULL, HFILL }
1638         },
1639         { &hf_1722_crf_timestamp_data,
1640             { "Timestamp Data", "crf.timestamp_data",
1641               FT_BYTES, BASE_NONE, NULL, 0x00, NULL, HFILL }
1642         },
1643         { &hf_1722_crf_timestamp,
1644             { "Data", "crf.timestamp",
1645               FT_UINT64, BASE_HEX, NULL, 0x00, NULL, HFILL }
1646         }
1647     };
1648
1649     static ei_register_info ei[] = {
1650         { &ei_crf_datalen,              { "crf.expert.crf_datalen", PI_PROTOCOL, PI_WARN, "The CRF data length must be multiple of 8", EXPFILL }}
1651     };
1652
1653     static gint *ett[] =
1654     {
1655         &ett_1722_crf,
1656         &ett_1722_crf_timestamp
1657     };
1658
1659     expert_module_t *expert_1722_crf;
1660
1661     /* Register the protocol name and description */
1662     proto_1722_crf = proto_register_protocol("Clock Reference Format", "CRF", "crf");
1663
1664     /* Required function calls to register the header fields and subtrees used */
1665     proto_register_field_array(proto_1722_crf, hf, array_length(hf));
1666     proto_register_subtree_array(ett, array_length(ett));
1667     expert_1722_crf = expert_register_protocol(proto_1722_crf);
1668     expert_register_field_array(expert_1722_crf, ei, array_length(ei));
1669 }
1670
1671 void proto_reg_handoff_1722_crf(void)
1672 {
1673     dissector_handle_t avb1722_crf_handle;
1674
1675     avb1722_crf_handle = create_dissector_handle(dissect_1722_crf, proto_1722_crf);
1676     dissector_add_uint("ieee1722.subtype", IEEE_1722_SUBTYPE_CRF, avb1722_crf_handle);
1677 }
1678
1679 /*
1680  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
1681  *
1682  * Local variables:
1683  * c-basic-offset: 4
1684  * tab-width: 8
1685  * indent-tabs-mode: nil
1686  * End:
1687  *
1688  * vi: set shiftwidth=4 tabstop=8 expandtab:
1689  * :indentSize=4:tabSize=8:noTabs=true:
1690  */