MSWSP: add ids for another unknown Property Set
[wireshark-wip.git] / epan / dissectors / packet-ieee1722.c
blobd93cf1e08f8f3df9ed0c686211589e7e3ebdc9fa
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>
7 * Copyright 2011, Thomas Bottom <tom.bottom@labxtechnologies.com>
9 * $Id$
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 * The 1722 Protocol specification can be found at the following:
30 * http://grouper.ieee.org/groups/1722/
34 #include "config.h"
36 #include <epan/packet.h>
37 #include <epan/etypes.h>
39 /* 1722 Offsets */
40 #define IEEE_1722_CD_OFFSET 0
41 #define IEEE_1722_VERSION_OFFSET 1
42 #define IEEE_1722_SEQ_NUM_OFFSET 2
43 #define IEEE_1722_TU_FIELD_OFFSET 3
44 #define IEEE_1722_STREAM_ID_OFFSET 4
45 #define IEEE_1722_TIMESTAMP_OFFSET 12
46 #define IEEE_1722_GW_INFO_OFFSET 16
47 #define IEEE_1722_PKT_DATA_LENGTH_OFFSET 20
48 #define IEEE_1722_TAG_OFFSET 22
49 #define IEEE_1722_TCODE_OFFSET 23
50 #define IEEE_1722_SID_OFFSET 24
51 #define IEEE_1722_DBS_OFFSET 25
52 #define IEEE_1722_FN_OFFSET 26
53 #define IEEE_1722_DBC_OFFSET 27
54 #define IEEE_1722_FMT_OFFSET 28
55 #define IEEE_1722_FDF_OFFSET 29
56 #define IEEE_1722_SYT_OFFSET 30
57 #define IEEE_1722_DATA_OFFSET 32
59 #define IEEE_1722_CIP_HEADER_SIZE 8
61 /* Bit Field Masks */
62 #define IEEE_1722_CD_MASK 0x80
63 #define IEEE_1722_SUBTYPE_MASK 0x7f
64 #define IEEE_1722_SV_MASK 0x80
65 #define IEEE_1722_VER_MASK 0x70
66 #define IEEE_1722_MR_MASK 0x08
67 #define IEEE_1722_GV_MASK 0x02
68 #define IEEE_1722_TV_MASK 0x01
69 #define IEEE_1722_TU_MASK 0x01
70 #define IEEE_1722_TAG_MASK 0xc0
71 #define IEEE_1722_CHANNEL_MASK 0x3f
72 #define IEEE_1722_TCODE_MASK 0xf0
73 #define IEEE_1722_SY_MASK 0x0f
74 #define IEEE_1722_SID_MASK 0x3f
75 #define IEEE_1722_FN_MASK 0xc0
76 #define IEEE_1722_QPC_MASK 0x38
77 #define IEEE_1722_SPH_MASK 0x04
78 #define IEEE_1722_FMT_MASK 0x3f
80 /**********************************************************/
81 /* Initialize the protocol and registered fields */
82 /**********************************************************/
83 static int proto_1722 = -1;
84 static int hf_1722_cdfield = -1;
85 static int hf_1722_subtype = -1;
86 static int hf_1722_svfield = -1;
87 static int hf_1722_verfield = -1;
88 static int hf_1722_mrfield = -1;
89 static int hf_1722_gvfield = -1;
90 static int hf_1722_tvfield = -1;
91 static int hf_1722_seqnum = -1;
92 static int hf_1722_tufield = -1;
93 static int hf_1722_stream_id = -1;
94 static int hf_1722_avbtp_timestamp = -1;
95 static int hf_1722_gateway_info = -1;
96 static int hf_1722_packet_data_length = -1;
97 static int hf_1722_tag = -1;
98 static int hf_1722_channel = -1;
99 static int hf_1722_tcode = -1;
100 static int hf_1722_sy = -1;
101 static int hf_1722_sid = -1;
102 static int hf_1722_dbs = -1;
103 static int hf_1722_fn = -1;
104 static int hf_1722_qpc = -1;
105 static int hf_1722_sph = -1;
106 static int hf_1722_dbc = -1;
107 static int hf_1722_fmt = -1;
108 static int hf_1722_fdf = -1;
109 static int hf_1722_syt = -1;
110 static int hf_1722_data = -1;
111 static int hf_1722_label = -1;
112 static int hf_1722_sample = -1;
114 /* Initialize the subtree pointers */
115 static int ett_1722 = -1;
116 static int ett_1722_audio = -1;
117 static int ett_1722_sample = -1;
119 static dissector_table_t avb_dissector_table;
121 static void
122 dissect_1722(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
124 proto_item *ti;
125 proto_tree *ieee1722_tree = NULL;
126 proto_tree *audio_tree;
127 proto_tree *sample_tree;
128 gint offset;
129 guint16 datalen;
130 guint8 dbs;
131 guint8 subtype;
132 int i, j;
134 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IEEE1722");
136 col_set_str(pinfo->cinfo, COL_INFO, "AVB Transportation Protocol");
138 if (tree) {
139 ti = proto_tree_add_item(tree, proto_1722, tvb, 0, -1, ENC_NA);
141 ieee1722_tree = proto_item_add_subtree(ti, ett_1722);
143 /* Add the CD and Subtype fields
144 * CD field is 1 bit
145 * Subtype field is 7 bits
147 proto_tree_add_item(ieee1722_tree, hf_1722_cdfield, tvb, IEEE_1722_CD_OFFSET, 1, ENC_BIG_ENDIAN);
148 proto_tree_add_item(ieee1722_tree, hf_1722_subtype, tvb, IEEE_1722_CD_OFFSET, 1, ENC_BIG_ENDIAN);
150 proto_tree_add_item(ieee1722_tree, hf_1722_svfield, tvb, IEEE_1722_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
151 proto_tree_add_item(ieee1722_tree, hf_1722_verfield, tvb, IEEE_1722_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
155 /* Version field ends the common AVTPDU. Now parse the specfic packet type */
156 subtype = tvb_get_guint8(tvb, IEEE_1722_CD_OFFSET);
157 subtype &= 0x7F;
159 /* call any registered subtype dissectors which use only the common AVTPDU (e.g. 1722.1 and MAAP) */
160 if (dissector_try_uint(avb_dissector_table, subtype, tvb, pinfo, tree)) return;
162 if (tree) {
163 proto_tree_add_item(ieee1722_tree, hf_1722_mrfield, tvb, IEEE_1722_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
164 proto_tree_add_item(ieee1722_tree, hf_1722_gvfield, tvb, IEEE_1722_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
165 proto_tree_add_item(ieee1722_tree, hf_1722_tvfield, tvb, IEEE_1722_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
167 /* Add the rest of the packet fields */
168 proto_tree_add_item(ieee1722_tree, hf_1722_seqnum, tvb,
169 IEEE_1722_SEQ_NUM_OFFSET, 1, ENC_BIG_ENDIAN);
171 proto_tree_add_item(ieee1722_tree, hf_1722_tufield, tvb,
172 IEEE_1722_TU_FIELD_OFFSET, 1, ENC_BIG_ENDIAN);
174 proto_tree_add_item(ieee1722_tree, hf_1722_stream_id, tvb,
175 IEEE_1722_STREAM_ID_OFFSET, 8, ENC_BIG_ENDIAN);
177 proto_tree_add_item(ieee1722_tree, hf_1722_avbtp_timestamp, tvb,
178 IEEE_1722_TIMESTAMP_OFFSET, 4, ENC_BIG_ENDIAN);
180 proto_tree_add_item(ieee1722_tree, hf_1722_gateway_info, tvb,
181 IEEE_1722_GW_INFO_OFFSET, 4, ENC_BIG_ENDIAN);
183 proto_tree_add_item(ieee1722_tree, hf_1722_packet_data_length, tvb,
184 IEEE_1722_PKT_DATA_LENGTH_OFFSET, 2, ENC_BIG_ENDIAN);
186 proto_tree_add_item(ieee1722_tree, hf_1722_tag, tvb,
187 IEEE_1722_TAG_OFFSET, 1, ENC_BIG_ENDIAN);
188 proto_tree_add_item(ieee1722_tree, hf_1722_channel, tvb,
189 IEEE_1722_TAG_OFFSET, 1, ENC_BIG_ENDIAN);
191 proto_tree_add_item(ieee1722_tree, hf_1722_tcode, tvb,
192 IEEE_1722_TCODE_OFFSET, 1, ENC_BIG_ENDIAN);
193 proto_tree_add_item(ieee1722_tree, hf_1722_sy, tvb,
194 IEEE_1722_TCODE_OFFSET, 1, ENC_BIG_ENDIAN);
196 proto_tree_add_item(ieee1722_tree, hf_1722_sid, tvb,
197 IEEE_1722_SID_OFFSET, 1, ENC_BIG_ENDIAN);
199 proto_tree_add_item(ieee1722_tree, hf_1722_dbs, tvb,
200 IEEE_1722_DBS_OFFSET, 1, ENC_BIG_ENDIAN);
202 proto_tree_add_item(ieee1722_tree, hf_1722_fn, tvb,
203 IEEE_1722_FN_OFFSET, 1, ENC_BIG_ENDIAN);
204 proto_tree_add_item(ieee1722_tree, hf_1722_qpc, tvb,
205 IEEE_1722_FN_OFFSET, 1, ENC_BIG_ENDIAN);
206 proto_tree_add_item(ieee1722_tree, hf_1722_sph, tvb,
207 IEEE_1722_FN_OFFSET, 1, ENC_BIG_ENDIAN);
209 proto_tree_add_item(ieee1722_tree, hf_1722_dbc, tvb,
210 IEEE_1722_DBC_OFFSET, 1, ENC_BIG_ENDIAN);
212 proto_tree_add_item(ieee1722_tree, hf_1722_fmt, tvb,
213 IEEE_1722_FMT_OFFSET, 1, ENC_BIG_ENDIAN);
215 proto_tree_add_item(ieee1722_tree, hf_1722_fdf, tvb,
216 IEEE_1722_FDF_OFFSET, 1, ENC_BIG_ENDIAN);
218 proto_tree_add_item(ieee1722_tree, hf_1722_syt, tvb,
219 IEEE_1722_SYT_OFFSET, 2, ENC_BIG_ENDIAN);
221 /* Calculate the remaining size by subtracting the CIP header size
222 from the value in the packet data length field */
223 datalen = tvb_get_ntohs(tvb, IEEE_1722_PKT_DATA_LENGTH_OFFSET);
224 datalen -= IEEE_1722_CIP_HEADER_SIZE;
226 /* Make the Audio sample tree. */
227 ti = proto_tree_add_item(ieee1722_tree, hf_1722_data, tvb,
228 IEEE_1722_DATA_OFFSET, datalen, ENC_NA);
230 audio_tree = proto_item_add_subtree(ti, ett_1722_audio);
232 /* Need to get the offset of where the audio data starts */
233 offset = IEEE_1722_DATA_OFFSET;
234 dbs = tvb_get_guint8(tvb, IEEE_1722_DBS_OFFSET);
236 /* If the DBS is ever 0 for whatever reason, then just add the rest of packet as unknown */
237 if(dbs == 0)
238 proto_tree_add_text(ieee1722_tree, tvb, IEEE_1722_DATA_OFFSET, datalen, "Incorrect DBS");
240 else {
241 /* Loop through all samples and add them to the audio tree. */
242 for (j = 0; j < (datalen / (dbs*4)); j++) {
243 ti = proto_tree_add_text(audio_tree, tvb, offset, 1, "Sample %d", j+1);
244 sample_tree = proto_item_add_subtree(ti, ett_1722_sample);
245 for (i = 0; i < dbs; i++) {
246 proto_tree_add_item(sample_tree, hf_1722_label, tvb, offset, 1, ENC_BIG_ENDIAN);
247 offset += 1;
249 proto_tree_add_item(sample_tree, hf_1722_sample, tvb, offset, 3, ENC_NA);
250 offset += 3;
257 /* Register the protocol with Wireshark */
258 void proto_register_1722(void)
260 static hf_register_info hf[] = {
261 { &hf_1722_cdfield,
262 { "Control/Data Indicator", "ieee1722.cdfield",
263 FT_BOOLEAN, 8, NULL, IEEE_1722_CD_MASK, NULL, HFILL }
265 { &hf_1722_subtype,
266 { "AVBTP Subtype", "ieee1722.subtype",
267 FT_UINT8, BASE_HEX, NULL, IEEE_1722_SUBTYPE_MASK, NULL, HFILL }
269 { &hf_1722_svfield,
270 { "AVBTP Stream ID Valid", "ieee1722.svfield",
271 FT_BOOLEAN, 8, NULL, IEEE_1722_SV_MASK, NULL, HFILL }
273 { &hf_1722_verfield,
274 { "AVBTP Version", "ieee1722.verfield",
275 FT_UINT8, BASE_HEX, NULL, IEEE_1722_VER_MASK, NULL, HFILL }
277 { &hf_1722_mrfield,
278 { "AVBTP Media Reset", "ieee1722.mrfield",
279 FT_UINT8, BASE_DEC, NULL, IEEE_1722_MR_MASK, NULL, HFILL }
281 { &hf_1722_gvfield,
282 { "AVBTP Gateway Info Valid", "ieee1722.gvfield",
283 FT_BOOLEAN, 8, NULL, IEEE_1722_GV_MASK, NULL, HFILL }
285 { &hf_1722_tvfield,
286 { "Source Timestamp Valid", "ieee1722.tvfield",
287 FT_BOOLEAN, 8, NULL, IEEE_1722_TV_MASK, NULL, HFILL }
289 { &hf_1722_seqnum,
290 { "Sequence Number", "ieee1722.seqnum",
291 FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
293 { &hf_1722_tufield,
294 { "AVBTP Timestamp Uncertain", "ieee1722.tufield",
295 FT_BOOLEAN, 8, NULL, IEEE_1722_TU_MASK, NULL, HFILL }
297 { &hf_1722_stream_id,
298 { "Stream ID", "ieee1722.stream_id",
299 FT_UINT64, BASE_HEX, NULL, 0x00, NULL, HFILL }
301 { &hf_1722_avbtp_timestamp,
302 { "AVBTP Timestamp", "ieee1722.avbtp_timestamp",
303 FT_UINT32, BASE_HEX, NULL, 0x00, NULL, HFILL }
305 { &hf_1722_gateway_info,
306 { "Gateway Info", "ieee1722.gateway_info",
307 FT_UINT32, BASE_HEX, NULL, 0x00, NULL, HFILL }
309 { &hf_1722_packet_data_length,
310 { "1394 Packet Data Length", "ieee1722.packet_data_len",
311 FT_UINT16, BASE_DEC, NULL, 0x00, NULL, HFILL }
313 { &hf_1722_tag,
314 { "1394 Packet Format Tag", "ieee1722.tag",
315 FT_UINT8, BASE_HEX, NULL, IEEE_1722_TAG_MASK, NULL, HFILL }
317 { &hf_1722_channel,
318 { "1394 Packet Channel", "ieee1722.channel",
319 FT_UINT8, BASE_HEX, NULL, IEEE_1722_CHANNEL_MASK, NULL, HFILL }
321 { &hf_1722_tcode,
322 { "1394 Packet Tcode", "ieee1722.tcode",
323 FT_UINT8, BASE_HEX, NULL, IEEE_1722_TCODE_MASK, NULL, HFILL }
325 { &hf_1722_sy,
326 { "1394 App-specific Control", "ieee1722.sy",
327 FT_UINT8, BASE_HEX, NULL, IEEE_1722_SY_MASK, NULL, HFILL }
329 { &hf_1722_sid,
330 { "Source ID", "ieee1722.sid",
331 FT_UINT8, BASE_HEX, NULL, IEEE_1722_SID_MASK, NULL, HFILL }
333 { &hf_1722_dbs,
334 { "Data Block Size", "ieee1722.dbs",
335 FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
337 { &hf_1722_fn,
338 { "Fraction Number", "ieee1722.fn",
339 FT_UINT8, BASE_HEX, NULL, IEEE_1722_FN_MASK, NULL, HFILL }
341 { &hf_1722_qpc,
342 { "Quadlet Padding Count", "ieee1722.qpc",
343 FT_UINT8, BASE_HEX, NULL, IEEE_1722_QPC_MASK, NULL, HFILL }
345 { &hf_1722_sph,
346 { "Source Packet Header", "ieee1722.sph",
347 FT_BOOLEAN, 8, NULL, IEEE_1722_SPH_MASK, NULL, HFILL }
349 { &hf_1722_dbc,
350 { "Data Block Continuity", "ieee1722.dbc",
351 FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
353 { &hf_1722_fmt,
354 { "Format ID", "ieee1722.fmt",
355 FT_UINT8, BASE_HEX, NULL, IEEE_1722_FMT_MASK, NULL, HFILL }
357 { &hf_1722_fdf,
358 { "Format Dependent Field", "ieee1722.fdf",
359 FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
361 { &hf_1722_syt,
362 { "SYT", "ieee1722.syt",
363 FT_UINT16, BASE_HEX, NULL, 0x00, NULL, HFILL }
365 { &hf_1722_data,
366 { "Audio Data", "ieee1722.data",
367 FT_BYTES, BASE_NONE, NULL, 0x00, NULL, HFILL }
369 { &hf_1722_label,
370 { "Label", "ieee1722.data.sample.label",
371 FT_UINT8, BASE_HEX, NULL, 0x00, NULL, HFILL }
373 { &hf_1722_sample,
374 { "Sample", "ieee1722.data.sample.sampledata",
375 FT_BYTES, BASE_NONE, NULL, 0x00, NULL, HFILL }
379 static gint *ett[] = {
380 &ett_1722,
381 &ett_1722_audio,
382 &ett_1722_sample
385 /* Register the protocol name and description */
386 proto_1722 = proto_register_protocol("IEEE 1722 Protocol", "IEEE1722", "ieee1722");
388 /* Required function calls to register the header fields and subtrees used */
389 proto_register_field_array(proto_1722, hf, array_length(hf));
390 proto_register_subtree_array(ett, array_length(ett));
392 /* Sub-dissector for 1772.1 */
393 avb_dissector_table = register_dissector_table("ieee1722.subtype",
394 "IEEE1722 AVBTP Subtype", FT_UINT8, BASE_HEX);
397 void proto_reg_handoff_1722(void)
399 dissector_handle_t avbtp_handle;
401 avbtp_handle = create_dissector_handle(dissect_1722, proto_1722);
402 dissector_add_uint("ethertype", ETHERTYPE_AVBTP, avbtp_handle);