b355c63cef16d85be254fd87c071482849ea00c2
[obnox/wireshark/wip.git] / epan / dissectors / packet-ptp.c
1 /* packet-ptp.c
2  * Routines for PTP (Precision Time Protocol) dissection
3  * Copyright 2004, Auges Tchouante <tchouante2001@yahoo.fr>
4  * Copyright 2004, Dominic Bechaz <bdo@zhwin.ch> , ZHW/InES
5  * Copyright 2004, Markus Seehofer <mseehofe@nt.hirschmann.de>
6  * Copyright 2006, Christian Schaer <scc@zhwin.ch>
7  * Copyright 2007, Markus Renz <Markus.Renz@hirschmann.de>
8  *
9  * Revisions:
10  * - Markus Seehofer 09.08.2005 <mseehofe@nt.hirschmann.de>
11  *   - Included the "startingBoundaryHops" field in
12  *     ptp_management messages.
13  * - Christian Schaer 07.07.2006 <scc@zhwin.ch>
14  *   - Added support for PTP version 2
15  * - Markus Renz 2007-06-01
16  *   updated support for PTPv2
17  *  - Markus Renz added Management for PTPv2, update to Draft 2.2
18  *
19  * $Id$
20  *
21  * Wireshark - Network traffic analyzer
22  * By Gerald Combs <gerald@wireshark.org>
23  * Copyright 1998 Gerald Combs
24  *
25  * This program is free software; you can redistribute it and/or
26  * modify it under the terms of the GNU General Public License
27  * as published by the Free Software Foundation; either version 2
28  * of the License, or (at your option) any later version.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU General Public License
36  * along with this program; if not, write to the Free Software
37  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38  */
39
40 #ifdef HAVE_CONFIG_H
41 # include "config.h"
42 #endif
43
44 #include <stdlib.h>
45 #include <math.h>
46
47
48 #include <glib.h>
49
50 #include <epan/packet.h>
51 #include <epan/etypes.h>
52
53
54 /**********************************************************/
55 /* Port definition's for PTP                                                      */
56 /**********************************************************/
57 #define EVENT_PORT_PTP      319
58 #define GENERAL_PORT_PTP    320
59
60 /*END Port definition's for PTP*/
61
62 static int proto_ptp = -1;
63
64 /***********************************************************************************/
65 /* Definitions and fields for PTPv1 dissection.                                    */
66 /***********************************************************************************/
67
68
69 /**********************************************************/
70 /* Offsets of fields within a PTPv1 packet.                               */
71 /**********************************************************/
72
73 /*Common offsets for all Messages (Synch, Delay_Req, Follow_Up, Delay_Resp ....)*/
74 #define PTP_VERSIONPTP_OFFSET                   0
75 #define PTP_VERSIONNETWORK_OFFSET               2
76 #define PTP_SUBDOMAIN_OFFSET                    4
77 #define PTP_MESSAGETYPE_OFFSET                  20
78 #define PTP_SOURCECOMMUNICATIONTECHNOLOGY_OFFSET        21
79 #define PTP_SOURCEUUID_OFFSET                   22
80 #define PTP_SOURCEPORTID_OFFSET                 28
81 #define PTP_SEQUENCEID_OFFSET                   30
82 #define PTP_CONTROL_OFFSET                              32
83 #define PTP_FLAGS_OFFSET                                34
84 #define PTP_FLAGS_LI61_OFFSET                   34
85 #define PTP_FLAGS_LI59_OFFSET                   34
86 #define PTP_FLAGS_BOUNDARY_CLOCK_OFFSET 34
87 #define PTP_FLAGS_ASSIST_OFFSET                 34
88 #define PTP_FLAGS_EXT_SYNC_OFFSET               34
89 #define PTP_FLAGS_PARENT_STATS_OFFSET   34
90 #define PTP_FLAGS_SYNC_BURST_OFFSET             34
91
92 /*Offsets for PTP_Sync and Delay_Req (=SDR) messages*/
93 #define PTP_SDR_ORIGINTIMESTAMP_OFFSET                                          40
94 #define PTP_SDR_ORIGINTIMESTAMP_SECONDS_OFFSET                          40
95 #define PTP_SDR_ORIGINTIMESTAMP_NANOSECONDS_OFFSET                      44
96 #define PTP_SDR_EPOCHNUMBER_OFFSET                                                      48
97 #define PTP_SDR_CURRENTUTCOFFSET_OFFSET                                         50
98 #define PTP_SDR_GRANDMASTERCOMMUNICATIONTECHNOLOGY_OFFSET       53
99 #define PTP_SDR_GRANDMASTERCLOCKUUID_OFFSET                                     54
100 #define PTP_SDR_GRANDMASTERPORTID_OFFSET                                        60
101 #define PTP_SDR_GRANDMASTERSEQUENCEID_OFFSET                            62
102 #define PTP_SDR_GRANDMASTERCLOCKSTRATUM_OFFSET                          67
103 #define PTP_SDR_GRANDMASTERCLOCKIDENTIFIER_OFFSET                       68
104 #define PTP_SDR_GRANDMASTERCLOCKVARIANCE_OFFSET                         74
105 #define PTP_SDR_GRANDMASTERPREFERRED_OFFSET                                     77
106 #define PTP_SDR_GRANDMASTERISBOUNDARYCLOCK_OFFSET                       79
107 #define PTP_SDR_SYNCINTERVAL_OFFSET                                                     83
108 #define PTP_SDR_LOCALCLOCKVARIANCE_OFFSET                                       86
109 #define PTP_SDR_LOCALSTEPSREMOVED_OFFSET                                        90
110 #define PTP_SDR_LOCALCLOCKSTRATUM_OFFSET                                        95
111 #define PTP_SDR_LOCALCLOCKIDENTIFIER_OFFSET                                     96
112 #define PTP_SDR_PARENTCOMMUNICATIONTECHNOLOGY_OFFSET            101
113 #define PTP_SDR_PARENTUUID_OFFSET                                                       102
114 #define PTP_SDR_PARENTPORTFIELD_OFFSET                                          110
115 #define PTP_SDR_ESTIMATEDMASTERVARIANCE_OFFSET                          114
116 #define PTP_SDR_ESTIMATEDMASTERDRIFT_OFFSET                                     116
117 #define PTP_SDR_UTCREASONABLE_OFFSET                                            123
118
119 /*Offsets for Follow_Up (=FU) messages*/
120 #define PTP_FU_ASSOCIATEDSEQUENCEID_OFFSET                                      42
121 #define PTP_FU_PRECISEORIGINTIMESTAMP_OFFSET                            44
122 #define PTP_FU_PRECISEORIGINTIMESTAMP_SECONDS_OFFSET            44
123 #define PTP_FU_PRECISEORIGINTIMESTAMP_NANOSECONDS_OFFSET        48
124
125 /*Offsets for Delay_Resp (=DR) messages*/
126 #define PTP_DR_DELAYRECEIPTTIMESTAMP_OFFSET                                     40
127 #define PTP_DR_DELAYRECEIPTTIMESTAMP_SECONDS_OFFSET                     40
128 #define PTP_DR_DELAYRECEIPTTIMESTAMP_NANOSECONDS_OFFSET         44
129 #define PTP_DR_REQUESTINGSOURCECOMMUNICATIONTECHNOLOGY_OFFSET   49
130 #define PTP_DR_REQUESTINGSOURCEUUID_OFFSET                                      50
131 #define PTP_DR_REQUESTINGSOURCEPORTID_OFFSET                            56
132 #define PTP_DR_REQUESTINGSOURCESEQUENCEID_OFFSET                        58
133
134 /*Offsets for Management (=MM) messages*/
135 #define PTP_MM_TARGETCOMMUNICATIONTECHNOLOGY_OFFSET                     41
136 #define PTP_MM_TARGETUUID_OFFSET                                                        42
137 #define PTP_MM_TARGETPORTID_OFFSET                                                      48
138 #define PTP_MM_STARTINGBOUNDARYHOPS_OFFSET                                      50
139 #define PTP_MM_BOUNDARYHOPS_OFFSET                                                      52
140 #define PTP_MM_MANAGEMENTMESSAGEKEY_OFFSET                                      55
141 #define PTP_MM_PARAMETERLENGTH_OFFSET                                           58
142         /*PARAMETERLENGTH > 0*/
143 #define PTP_MM_MESSAGEPARAMETERS_OFFSET                                         60
144         /*PTP_MM_CLOCK_IDENTITY (PARAMETERLENGTH = 64)*/
145 #define PTP_MM_CLOCK_IDENTITY_CLOCKCOMMUNICATIONTECHNOLOGY_OFFSET       63
146 #define PTP_MM_CLOCK_IDENTITY_CLOCKUUIDFIELD_OFFSET                                     64
147 #define PTP_MM_CLOCK_IDENTITY_CLOCKPORTFIELD_OFFSET                                     74
148 #define PTP_MM_CLOCK_IDENTITY_MANUFACTURERIDENTITY_OFFSET                       76
149
150         /*PTP_MM_INITIALIZE_CLOCK (PARAMETERLENGTH = 4)*/
151 #define PTP_MM_INITIALIZE_CLOCK_INITIALISATIONKEY_OFFSET                        62
152
153         /*PTP_MM_SET_SUBDOMAIN (PARAMETERLENGTH = 16)*/
154 #define PTP_MM_SET_SUBDOMAIN_SUBDOMAINNAME_OFFSET                                       60
155
156         /*PTP_MM_DEFAULT_DATA_SET (PARAMETERLENGTH = 76)*/
157 #define PTP_MM_DEFAULT_DATA_SET_CLOCKCOMMUNICATIONTECHNOLOGY_OFFSET     63
158 #define PTP_MM_DEFAULT_DATA_SET_CLOCKUUIDFIELD_OFFSET                           64
159 #define PTP_MM_DEFAULT_DATA_SET_CLOCKPORTFIELD_OFFSET                           74
160 #define PTP_MM_DEFAULT_DATA_SET_CLOCKSTRATUM_OFFSET                                     79
161 #define PTP_MM_DEFAULT_DATA_SET_CLOCKIDENTIFIER_OFFSET                          80
162 #define PTP_MM_DEFAULT_DATA_SET_CLOCKVARIANCE_OFFSET                            86
163 #define PTP_MM_DEFAULT_DATA_SET_CLOCKFOLLOWUPCAPABLE_OFFSET                     89
164 #define PTP_MM_DEFAULT_DATA_SET_PREFERRED_OFFSET                                        95
165 #define PTP_MM_DEFAULT_DATA_SET_INITIALIZABLE_OFFSET                            99
166 #define PTP_MM_DEFAULT_DATA_SET_EXTERNALTIMING_OFFSET                           103
167 #define PTP_MM_DEFAULT_DATA_SET_ISBOUNDARYCLOCK_OFFSET                          107
168 #define PTP_MM_DEFAULT_DATA_SET_SYNCINTERVAL_OFFSET                                     111
169 #define PTP_MM_DEFAULT_DATA_SET_SUBDOMAINNAME_OFFSET                            112
170 #define PTP_MM_DEFAULT_DATA_SET_NUMBERPORTS_OFFSET                                      130
171 #define PTP_MM_DEFAULT_DATA_SET_NUMBERFOREIGNRECORDS_OFFSET                     134
172
173         /*PTP_MM_UPDATE_DEFAULT_DATA_SET (PARAMETERLENGTH = 36)*/
174 #define PTP_MM_UPDATE_DEFAULT_DATA_SET_CLOCKSTRATUM_OFFSET                      63
175 #define PTP_MM_UPDATE_DEFAULT_DATA_SET_CLOCKIDENTIFIER_OFFSET           64
176 #define PTP_MM_UPDATE_DEFAULT_DATA_SET_CLOCKVARIANCE_OFFSET                     70
177 #define PTP_MM_UPDATE_DEFAULT_DATA_SET_PREFERRED_OFFSET                         75
178 #define PTP_MM_UPDATE_DEFAULT_DATA_SET_SYNCINTERVAL_OFFSET                      79
179 #define PTP_MM_UPDATE_DEFAULT_DATA_SET_SUBDOMAINNAME_OFFSET                     80
180
181         /*PTP_MM_CURRENT_DATA_SET (PARAMETERLENGTH = 20)*/
182 #define PTP_MM_CURRENT_DATA_SET_STEPSREMOVED_OFFSET                                     62
183 #define PTP_MM_CURRENT_DATA_SET_OFFSETFROMMASTER_OFFSET                         64
184 #define PTP_MM_CURRENT_DATA_SET_OFFSETFROMMASTERSECONDS_OFFSET          64
185 #define PTP_MM_CURRENT_DATA_SET_OFFSETFROMMASTERNANOSECONDS_OFFSET      68
186 #define PTP_MM_CURRENT_DATA_SET_ONEWAYDELAY_OFFSET                                      72
187 #define PTP_MM_CURRENT_DATA_SET_ONEWAYDELAYSECONDS_OFFSET                       72
188 #define PTP_MM_CURRENT_DATA_SET_ONEWAYDELAYNANOSECONDS_OFFSET           76
189
190         /*PTP_MM_PARENT_DATA_SET (PARAMETERLENGTH = 90)*/
191 #define PTP_MM_PARENT_DATA_SET_PARENTCOMMUNICATIONTECHNOLOGY_OFFSET     63
192 #define PTP_MM_PARENT_DATA_SET_PARENTUUID_OFFSET                                        64
193 #define PTP_MM_PARENT_DATA_SET_PARENTPORTID_OFFSET                                      74
194 #define PTP_MM_PARENT_DATA_SET_PARENTLASTSYNCSEQUENCENUMBER_OFFSET      78
195 #define PTP_MM_PARENT_DATA_SET_PARENTFOLLOWUPCAPABLE_OFFSET                     83
196 #define PTP_MM_PARENT_DATA_SET_PARENTEXTERNALTIMING_OFFSET                      87
197 #define PTP_MM_PARENT_DATA_SET_PARENTVARIANCE_OFFSET                            90
198 #define PTP_MM_PARENT_DATA_SET_PARENTSTATS_OFFSET                                       95
199 #define PTP_MM_PARENT_DATA_SET_OBSERVEDVARIANCE_OFFSET                          98
200 #define PTP_MM_PARENT_DATA_SET_OBSERVEDDRIFT_OFFSET                                     100
201 #define PTP_MM_PARENT_DATA_SET_UTCREASONABLE_OFFSET                                     107
202 #define PTP_MM_PARENT_DATA_SET_GRANDMASTERCOMMUNICATIONTECHNOLOGY_OFFSET        111
203 #define PTP_MM_PARENT_DATA_SET_GRANDMASTERUUIDFIELD_OFFSET                      112
204 #define PTP_MM_PARENT_DATA_SET_GRANDMASTERPORTIDFIELD_OFFSET            122
205 #define PTP_MM_PARENT_DATA_SET_GRANDMASTERSTRATUM_OFFSET                        127
206 #define PTP_MM_PARENT_DATA_SET_GRANDMASTERIDENTIFIER_OFFSET                     128
207 #define PTP_MM_PARENT_DATA_SET_GRANDMASTERVARIANCE_OFFSET                       134
208 #define PTP_MM_PARENT_DATA_SET_GRANDMASTERPREFERRED_OFFSET                      139
209 #define PTP_MM_PARENT_DATA_SET_GRANDMASTERISBOUNDARYCLOCK_OFFSET        143
210 #define PTP_MM_PARENT_DATA_SET_GRANDMASTERSEQUENCENUMBER_OFFSET         146
211
212         /*PTP_MM_PORT_DATA_SET (PARAMETERLENGTH = 52)*/
213 #define PTP_MM_PORT_DATA_SET_RETURNEDPORTNUMBER_OFFSET                          62
214 #define PTP_MM_PORT_DATA_SET_PORTSTATE_OFFSET                                           67
215 #define PTP_MM_PORT_DATA_SET_LASTSYNCEVENTSEQUENCENUMBER_OFFSET         70
216 #define PTP_MM_PORT_DATA_SET_LASTGENERALEVENTSEQUENCENUMBER_OFFSET      74
217 #define PTP_MM_PORT_DATA_SET_PORTCOMMUNICATIONTECHNOLOGY_OFFSET         79
218 #define PTP_MM_PORT_DATA_SET_PORTUUIDFIELD_OFFSET                                       80
219 #define PTP_MM_PORT_DATA_SET_PORTIDFIELD_OFFSET                                         90
220 #define PTP_MM_PORT_DATA_SET_BURSTENABLED_OFFSET                                        95
221 #define PTP_MM_PORT_DATA_SET_SUBDOMAINADDRESSOCTETS_OFFSET                      97
222 #define PTP_MM_PORT_DATA_SET_EVENTPORTADDRESSOCTETS_OFFSET                      98
223 #define PTP_MM_PORT_DATA_SET_GENERALPORTADDRESSOCTETS_OFFSET            99
224 #define PTP_MM_PORT_DATA_SET_SUBDOMAINADDRESS_OFFSET                            100
225 #define PTP_MM_PORT_DATA_SET_EVENTPORTADDRESS_OFFSET                            106
226 #define PTP_MM_PORT_DATA_SET_GENERALPORTADDRESS_OFFSET                          110
227
228         /*PTP_MM_GLOBAL_TIME_DATA_SET (PARAMETERLENGTH = 24)*/
229 #define PTP_MM_GLOBAL_TIME_DATA_SET_LOCALTIME_OFFSET                            60
230 #define PTP_MM_GLOBAL_TIME_DATA_SET_LOCALTIMESECONDS_OFFSET                     60
231 #define PTP_MM_GLOBAL_TIME_DATA_SET_LOCALTIMENANOSECONDS_OFFSET         64
232 #define PTP_MM_GLOBAL_TIME_DATA_SET_CURRENTUTCOFFSET_OFFSET                     70
233 #define PTP_MM_GLOBAL_TIME_DATA_SET_LEAP59_OFFSET                                       75
234 #define PTP_MM_GLOBAL_TIME_DATA_SET_LEAP61_OFFSET                                       79
235 #define PTP_MM_GLOBAL_TIME_DATA_SET_EPOCHNUMBER_OFFSET                          82
236
237         /*PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES (PARAMETERLENGTH = 16)*/
238 #define PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES_CURRENTUTCOFFSET_OFFSET    62
239 #define PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES_LEAP59_OFFSET                      67
240 #define PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES_LEAP61_OFFSET                      71
241 #define PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES_EPOCHNUMBER_OFFSET         74
242
243         /*PTP_MM_GET_FOREIGN_DATA_SET (PARAMETERLENGTH = 4)*/
244 #define PTP_MM_GET_FOREIGN_DATA_SET_RECORDKEY_OFFSET                            62
245
246         /*PTP_MM_FOREIGN_DATA_SET (PARAMETERLENGTH = 28)*/
247 #define PTP_MM_FOREIGN_DATA_SET_RETURNEDPORTNUMBER_OFFSET                       62
248 #define PTP_MM_FOREIGN_DATA_SET_RETURNEDRECORDNUMBER_OFFSET                     66
249 #define PTP_MM_FOREIGN_DATA_SET_FOREIGNMASTERCOMMUNICATIONTECHNOLOGY_OFFSET     71
250 #define PTP_MM_FOREIGN_DATA_SET_FOREIGNMASTERUUIDFIELD_OFFSET           72
251 #define PTP_MM_FOREIGN_DATA_SET_FOREIGNMASTERPORTIDFIELD_OFFSET         82
252 #define PTP_MM_FOREIGN_DATA_SET_FOREIGNMASTERSYNCS_OFFSET                       86
253
254         /*PTP_MM_SET_SYNC_INTERVAL (PARAMETERLENGTH = 4)*/
255 #define PTP_MM_SET_SYNC_INTERVAL_SYNCINTERVAL_OFFSET                            62
256
257         /*PTP_MM_SET_TIME (PARAMETERLENGTH = 8)*/
258 #define PTP_MM_SET_TIME_LOCALTIME_OFFSET                                                        60
259 #define PTP_MM_SET_TIME_LOCALTIMESECONDS_OFFSET                                         60
260 #define PTP_MM_SET_TIME_LOCALTIMENANOSECONDS_OFFSET                                     64
261
262 /*END Offsets of fields within a PTP packet.*/
263
264 /**********************************************************/
265 /* flag-field-mask-definitions                                                    */
266 /**********************************************************/
267 #define PTP_FLAGS_LI61_BITMASK                          0x01
268 #define PTP_FLAGS_LI59_BITMASK                          0x02
269 #define PTP_FLAGS_BOUNDARY_CLOCK_BITMASK        0x04
270 #define PTP_FLAGS_ASSIST_BITMASK                        0x08
271 #define PTP_FLAGS_EXT_SYNC_BITMASK                      0x10
272 #define PTP_FLAGS_PARENT_STATS_BITMASK          0x20
273 #define PTP_FLAGS_SYNC_BURST_BITMASK            0x40
274
275 /*END flag-field-mask-definitions*/
276
277 /**********************************************************/
278 /* managementMessage definitions                                                  */
279 /**********************************************************/
280 #define PTP_MM_NULL                                                     0
281 #define PTP_MM_OBTAIN_IDENTITY                          1
282 #define PTP_MM_CLOCK_IDENTITY                           2
283 #define PTP_MM_INITIALIZE_CLOCK                         3
284 #define PTP_MM_SET_SUBDOMAIN                            4
285 #define PTP_MM_CLEAR_DESIGNATED_PREFERRED_MASTER        5
286 #define PTP_MM_SET_DESIGNATED_PREFERRED_MASTER          6
287 #define PTP_MM_GET_DEFAULT_DATA_SET                     7
288 #define PTP_MM_DEFAULT_DATA_SET                         8
289 #define PTP_MM_UPDATE_DEFAULT_DATA_SET          9
290 #define PTP_MM_GET_CURRENT_DATA_SET             10
291 #define PTP_MM_CURRENT_DATA_SET                         11
292 #define PTP_MM_GET_PARENT_DATA_SET                      12
293 #define PTP_MM_PARENT_DATA_SET                          13
294 #define PTP_MM_GET_PORT_DATA_SET                        14
295 #define PTP_MM_PORT_DATA_SET                            15
296 #define PTP_MM_GET_GLOBAL_TIME_DATA_SET         16
297 #define PTP_MM_GLOBAL_TIME_DATA_SET                     17
298 #define PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES    18
299 #define PTP_MM_GOTO_FAULTY_STATE                        19
300 #define PTP_MM_GET_FOREIGN_DATA_SET             20
301 #define PTP_MM_FOREIGN_DATA_SET                         21
302 #define PTP_MM_SET_SYNC_INTERVAL                        22
303 #define PTP_MM_DISABLE_PORT                                     23
304 #define PTP_MM_ENABLE_PORT                                      24
305 #define PTP_MM_DISABLE_BURST                            25
306 #define PTP_MM_ENABLE_BURST                                     26
307 #define PTP_MM_SET_TIME                                         27
308
309 static const value_string ptp_managementMessageKey_vals[] = {
310   {PTP_MM_NULL,  "PTP_MM_NULL"},
311   {PTP_MM_OBTAIN_IDENTITY,  "PTP_MM_OBTAIN_IDENTITY"},
312   {PTP_MM_CLOCK_IDENTITY,  "PTP_MM_CLOCK_IDENTITY"},
313   {PTP_MM_INITIALIZE_CLOCK,  "PTP_MM_INITIALIZE_CLOCK"},
314   {PTP_MM_SET_SUBDOMAIN,  "PTP_MM_SET_SUBDOMAIN"},
315   {PTP_MM_CLEAR_DESIGNATED_PREFERRED_MASTER,  "PTP_MM_CLEAR_DESIGNATED_PREFERRED_MASTER"},
316   {PTP_MM_SET_DESIGNATED_PREFERRED_MASTER,  "PTP_MM_SET_DESIGNATED_PREFERRED_MASTER"},
317   {PTP_MM_GET_DEFAULT_DATA_SET,  "PTP_MM_GET_DEFAULT_DATA_SET"},
318   {PTP_MM_DEFAULT_DATA_SET,  "PTP_MM_DEFAULT_DATA_SET"},
319   {PTP_MM_UPDATE_DEFAULT_DATA_SET,  "PTP_MM_UPDATE_DEFAULT_DATA_SET"},
320   {PTP_MM_GET_CURRENT_DATA_SET,  "PTP_MM_GET_CURRENT_DATA_SET"},
321   {PTP_MM_CURRENT_DATA_SET,  "PTP_MM_CURRENT_DATA_SET"},
322   {PTP_MM_GET_PARENT_DATA_SET,  "PTP_MM_GET_PARENT_DATA_SET"},
323   {PTP_MM_PARENT_DATA_SET,  "PTP_MM_PARENT_DATA_SET"},
324   {PTP_MM_GET_PORT_DATA_SET,  "PTP_MM_GET_PORT_DATA_SET"},
325   {PTP_MM_PORT_DATA_SET,  "PTP_MM_PORT_DATA_SET"},
326   {PTP_MM_GET_GLOBAL_TIME_DATA_SET,  "PTP_MM_GET_GLOBAL_TIME_DATA_SET"},
327   {PTP_MM_GLOBAL_TIME_DATA_SET,  "PTP_MM_GLOBAL_TIME_DATA_SET"},
328   {PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES,  "PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES"},
329   {PTP_MM_GOTO_FAULTY_STATE,  "PTP_MM_GOTO_FAULTY_STATE"},
330   {PTP_MM_GET_FOREIGN_DATA_SET,  "PTP_MM_GET_FOREIGN_DATA_SET"},
331   {PTP_MM_FOREIGN_DATA_SET,  "PTP_MM_FOREIGN_DATA_SET"},
332   {PTP_MM_SET_SYNC_INTERVAL,  "PTP_MM_SET_SYNC_INTERVAL"},
333   {PTP_MM_DISABLE_PORT,  "PTP_MM_DISABLE_PORT"},
334   {PTP_MM_ENABLE_PORT,  "PTP_MM_ENABLE_PORT"},
335   {PTP_MM_DISABLE_BURST,  "PTP_MM_DISABLE_BURST"},
336   {PTP_MM_ENABLE_BURST,  "PTP_MM_ENABLE_BURST"},
337   {PTP_MM_SET_TIME,  "PTP_MM_SET_TIME"},
338   {0,              NULL          } };
339         /*same again but better readable text for info column*/
340   static const value_string ptp_managementMessageKey_infocolumn_vals[] = {
341   {PTP_MM_NULL,  "Null"},
342   {PTP_MM_OBTAIN_IDENTITY,  "Obtain Identity"},
343   {PTP_MM_CLOCK_IDENTITY,  "Clock Identity"},
344   {PTP_MM_INITIALIZE_CLOCK,  "Initialize Clock"},
345   {PTP_MM_SET_SUBDOMAIN,  "Set Subdomain"},
346   {PTP_MM_CLEAR_DESIGNATED_PREFERRED_MASTER,  "Clear Designated Preferred Master"},
347   {PTP_MM_SET_DESIGNATED_PREFERRED_MASTER,  "Set Designated Preferred Master"},
348   {PTP_MM_GET_DEFAULT_DATA_SET,  "Get Default Data Set"},
349   {PTP_MM_DEFAULT_DATA_SET,  "Default Data Set"},
350   {PTP_MM_UPDATE_DEFAULT_DATA_SET,  "Update Default Data Set"},
351   {PTP_MM_GET_CURRENT_DATA_SET,  "Get Current Data Set"},
352   {PTP_MM_CURRENT_DATA_SET,  "Current Data Set"},
353   {PTP_MM_GET_PARENT_DATA_SET,  "Get Parent Data Set"},
354   {PTP_MM_PARENT_DATA_SET,  "Parent Data Set"},
355   {PTP_MM_GET_PORT_DATA_SET,  "Get Port Data Set"},
356   {PTP_MM_PORT_DATA_SET,  "Port Data Set"},
357   {PTP_MM_GET_GLOBAL_TIME_DATA_SET,  "Get Global Time Data Set"},
358   {PTP_MM_GLOBAL_TIME_DATA_SET,  "Global Time Data Set"},
359   {PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES,  "Update Global Time Properties"},
360   {PTP_MM_GOTO_FAULTY_STATE,  "Goto Faulty State"},
361   {PTP_MM_GET_FOREIGN_DATA_SET,  "Get Foreign Data Set"},
362   {PTP_MM_FOREIGN_DATA_SET,  "Foreign Data Set"},
363   {PTP_MM_SET_SYNC_INTERVAL,  "Set Sync Interval"},
364   {PTP_MM_DISABLE_PORT,  "Disable Port"},
365   {PTP_MM_ENABLE_PORT,  "Enable Port"},
366   {PTP_MM_DISABLE_BURST,  "Disable Burst"},
367   {PTP_MM_ENABLE_BURST,  "Enable Burst"},
368   {PTP_MM_SET_TIME,  "Set Time"},
369   {0,              NULL          } };
370
371 /*END managementMessage definitions*/
372
373 /**********************************************************/
374 /* CommunicationId definitions                                                    */
375 /**********************************************************/
376 #define PTP_CLOSED                              0
377 #define PTP_ETHER                               1
378 #define PTP_FFBUS                               4
379 #define PTP_PROFIBUS                    5
380 #define PTP_LON                                 6
381 #define PTP_DNET                                7
382 #define PTP_SDS                                 8
383 #define PTP_CONTROLNET                  9
384 #define PTP_CANOPEN                             10
385 #define PTP_IEEE1394                    243
386 #define PTP_IEEE802_11A                 244
387 #define PTP_IEEE_WIRELESS               245
388 #define PTP_INFINIBAND                  246
389 #define PTP_BLUETOOTH                   247
390 #define PTP_IEEE802_15_1                248
391 #define PTP_IEEE1451_3                  249
392 #define PTP_IEEE1451_5                  250
393 #define PTP_USB                                 251
394 #define PTP_ISA                                 252
395 #define PTP_PCI                                 253
396 #define PTP_VXI                                 254
397 #define PTP_DEFAULT                             255
398
399 static const value_string ptp_communicationid_vals[] = {
400   {PTP_CLOSED,  "Closed system outside the scope of this standard."},
401   {PTP_ETHER,  "IEEE 802.3 (Ethernet)"},
402   {PTP_FFBUS,  "FOUNDATION Fieldbus"},
403   {PTP_PROFIBUS,  "PROFIBUS"},
404   {PTP_LON,  "LonTalk"},
405   {PTP_DNET,  "DeviceNet"},
406   {PTP_SDS,  "SmartDistributedSystem"},
407   {PTP_CONTROLNET,  "ControlNet"},
408   {PTP_CANOPEN,  "CANopen"},
409   {PTP_IEEE1394,  "IEEE 1394"},
410   {PTP_IEEE802_11A,  "IEEE 802.11a"},
411   {PTP_IEEE_WIRELESS,  "IEEE 802.11b"},
412   {PTP_INFINIBAND,  "InfiniBand"},
413   {PTP_BLUETOOTH,  "Bluetooth wireless"},
414   {PTP_IEEE802_15_1,  "IEEE 802.15.1"},
415   {PTP_IEEE1451_3,  "IEEE 1451.3"},
416   {PTP_IEEE1451_5,  "IEEE 1451.5"},
417   {PTP_USB,  "USB bus"},
418   {PTP_ISA,  "ISA bus"},
419   {PTP_PCI,  "PCI bus"},
420   {PTP_VXI,  "VXI bus"},
421   {PTP_DEFAULT,  "Default value"},
422   {0,              NULL          } };
423
424 /*END CommunicationId definitions*/
425
426 /**********************************************************/
427 /* PTP message types    (PTP_CONTROL field)                               */
428 /**********************************************************/
429 #define PTP_SYNC_MESSAGE                0x00
430 #define PTP_DELAY_REQ_MESSAGE   0x01
431 #define PTP_FOLLOWUP_MESSAGE    0x02
432 #define PTP_DELAY_RESP_MESSAGE  0x03
433 #define PTP_MANAGEMENT_MESSAGE  0x04
434 #define PTP_OTHER_MESSAGE               0x05
435
436 static const value_string ptp_control_vals[] = {
437   {PTP_SYNC_MESSAGE,            "Sync Message"},
438   {PTP_DELAY_REQ_MESSAGE,       "Delay_Req Message"},
439   {PTP_FOLLOWUP_MESSAGE,    "Follow_Up Message"},
440   {PTP_DELAY_RESP_MESSAGE,      "Delay_Resp Message"},
441   {PTP_MANAGEMENT_MESSAGE,  "Management Message"},
442   {PTP_OTHER_MESSAGE,           "Other Message"},
443   {0,                                   NULL          } };
444
445 /*END PTP message types*/
446
447 /**********************************************************/
448 /* Channel values for the PTP_MESSAGETYPE field                   */
449 /**********************************************************/
450 #define PTP_MESSAGETYPE_EVENT   0x01
451 #define PTP_MESSAGETYPE_GENERAL 0x02
452
453 static const value_string ptp_messagetype_vals[] = {
454   {PTP_MESSAGETYPE_EVENT, "Event Message"},
455   {PTP_MESSAGETYPE_GENERAL, "General Message"},
456   {0,              NULL          } };
457
458 /*END channel values for the PTP_MESSAGETYPE field*/
459
460 /* Channel values for boolean vals (FLAGS)*/
461
462 static const value_string ptp_bool_vals[] = {
463   {1, "True"},
464   {0, "False"},
465   {0,              NULL          }};
466
467 /**********************************************************/
468 /* Initialize the protocol and registered fields                  */
469 /**********************************************************/
470
471 static int hf_ptp_versionptp = -1;
472 static int hf_ptp_versionnetwork = -1;
473 static int hf_ptp_subdomain = -1;
474 static int hf_ptp_messagetype = -1;
475 static int hf_ptp_sourcecommunicationtechnology = -1;
476 static int hf_ptp_sourceuuid = -1;
477 static int hf_ptp_sourceportid = -1;
478 static int hf_ptp_sequenceid = -1;
479 static int hf_ptp_control = -1;
480 static int hf_ptp_flags = -1;
481 static int hf_ptp_flags_li61 = -1;
482 static int hf_ptp_flags_li59 = -1;
483 static int hf_ptp_flags_boundary_clock = -1;
484 static int hf_ptp_flags_assist = -1;
485 static int hf_ptp_flags_ext_sync = -1;
486 static int hf_ptp_flags_parent = -1;
487 static int hf_ptp_flags_sync_burst = -1;
488
489 /*Fields for ptp_sync and delay_req (=sdr) messages*/
490 static int hf_ptp_sdr_origintimestamp = -1;     /*Field for seconds & nanoseconds*/
491 static int hf_ptp_sdr_origintimestamp_seconds = -1;
492 static int hf_ptp_sdr_origintimestamp_nanoseconds = -1;
493 static int hf_ptp_sdr_epochnumber = -1;
494 static int hf_ptp_sdr_currentutcoffset = -1;
495 static int hf_ptp_sdr_grandmastercommunicationtechnology = -1;
496 static int hf_ptp_sdr_grandmasterclockuuid = -1;
497 static int hf_ptp_sdr_grandmasterportid = -1;
498 static int hf_ptp_sdr_grandmastersequenceid = -1;
499 static int hf_ptp_sdr_grandmasterclockstratum = -1;
500 static int hf_ptp_sdr_grandmasterclockidentifier = -1;
501 static int hf_ptp_sdr_grandmasterclockvariance = -1;
502 static int hf_ptp_sdr_grandmasterpreferred = -1;
503 static int hf_ptp_sdr_grandmasterisboundaryclock = -1;
504 static int hf_ptp_sdr_syncinterval = -1;
505 static int hf_ptp_sdr_localclockvariance = -1;
506 static int hf_ptp_sdr_localstepsremoved = -1;
507 static int hf_ptp_sdr_localclockstratum = -1;
508 static int hf_ptp_sdr_localclockidentifier = -1;
509 static int hf_ptp_sdr_parentcommunicationtechnology = -1;
510 static int hf_ptp_sdr_parentuuid = -1;
511 static int hf_ptp_sdr_parentportfield = -1;
512 static int hf_ptp_sdr_estimatedmastervariance = -1;
513 static int hf_ptp_sdr_estimatedmasterdrift = -1;
514 static int hf_ptp_sdr_utcreasonable = -1;
515
516 /*Fields for follow_up (=fu) messages*/
517 static int hf_ptp_fu_associatedsequenceid = -1;
518 static int hf_ptp_fu_preciseorigintimestamp = -1;
519 static int hf_ptp_fu_preciseorigintimestamp_seconds = -1;
520 static int hf_ptp_fu_preciseorigintimestamp_nanoseconds = -1;
521
522 /*Fields for delay_resp (=dr) messages*/
523 static int hf_ptp_dr_delayreceipttimestamp = -1;
524 static int hf_ptp_dr_delayreceipttimestamp_seconds = -1;
525 static int hf_ptp_dr_delayreceipttimestamp_nanoseconds = -1;
526 static int hf_ptp_dr_requestingsourcecommunicationtechnology = -1;
527 static int hf_ptp_dr_requestingsourceuuid = -1;
528 static int hf_ptp_dr_requestingsourceportid = -1;
529 static int hf_ptp_dr_requestingsourcesequenceid = -1;
530
531 /*Fields for management (=mm) messages*/
532 static int hf_ptp_mm_targetcommunicationtechnology = -1;
533 static int hf_ptp_mm_targetuuid = -1;
534 static int hf_ptp_mm_targetportid = -1;
535 static int hf_ptp_mm_startingboundaryhops = -1;
536 static int hf_ptp_mm_boundaryhops = -1;
537 static int hf_ptp_mm_managementmessagekey = -1;
538 static int hf_ptp_mm_parameterlength = -1;
539         /*parameterlength > 0*/
540 static int hf_ptp_mm_messageparameters = -1;
541         /*ptp_mm_clock_identity (parameterlength = 64)*/
542 static int hf_ptp_mm_clock_identity_clockcommunicationtechnology = -1;
543 static int hf_ptp_mm_clock_identity_clockuuidfield = -1;
544 static int hf_ptp_mm_clock_identity_clockportfield = -1;
545 static int hf_ptp_mm_clock_identity_manufactureridentity = -1;
546
547         /*ptp_mm_initialize_clock (parameterlength = 4)*/
548 static int hf_ptp_mm_initialize_clock_initialisationkey = -1;
549
550         /*ptp_mm_set_subdomain (parameterlength = 16)*/
551 static int hf_ptp_mm_set_subdomain_subdomainname = -1;
552
553         /*ptp_mm_default_data_set (parameterlength = 76)*/
554 static int hf_ptp_mm_default_data_set_clockcommunicationtechnology = -1;
555 static int hf_ptp_mm_default_data_set_clockuuidfield = -1;
556 static int hf_ptp_mm_default_data_set_clockportfield = -1;
557 static int hf_ptp_mm_default_data_set_clockstratum = -1;
558 static int hf_ptp_mm_default_data_set_clockidentifier = -1;
559 static int hf_ptp_mm_default_data_set_clockvariance = -1;
560 static int hf_ptp_mm_default_data_set_clockfollowupcapable = -1;
561 static int hf_ptp_mm_default_data_set_preferred = -1;
562 static int hf_ptp_mm_default_data_set_initializable = -1;
563 static int hf_ptp_mm_default_data_set_externaltiming = -1;
564 static int hf_ptp_mm_default_data_set_isboundaryclock = -1;
565 static int hf_ptp_mm_default_data_set_syncinterval = -1;
566 static int hf_ptp_mm_default_data_set_subdomainname = -1;
567 static int hf_ptp_mm_default_data_set_numberports = -1;
568 static int hf_ptp_mm_default_data_set_numberforeignrecords = -1;
569
570         /*ptp_mm_update_default_data_set (parameterlength = 36)*/
571 static int hf_ptp_mm_update_default_data_set_clockstratum = -1;
572 static int hf_ptp_mm_update_default_data_set_clockidentifier = -1;
573 static int hf_ptp_mm_update_default_data_set_clockvariance = -1;
574 static int hf_ptp_mm_update_default_data_set_preferred = -1;
575 static int hf_ptp_mm_update_default_data_set_syncinterval = -1;
576 static int hf_ptp_mm_update_default_data_set_subdomainname = -1;
577
578         /*ptp_mm_current_data_set (parameterlength = 20)*/
579 static int hf_ptp_mm_current_data_set_stepsremoved = -1;
580 static int hf_ptp_mm_current_data_set_offsetfrommaster = -1;
581 static int hf_ptp_mm_current_data_set_offsetfrommasterseconds = -1;
582 static int hf_ptp_mm_current_data_set_offsetfrommasternanoseconds = -1;
583 static int hf_ptp_mm_current_data_set_onewaydelay = -1;
584 static int hf_ptp_mm_current_data_set_onewaydelayseconds = -1;
585 static int hf_ptp_mm_current_data_set_onewaydelaynanoseconds = -1;
586
587         /*ptp_mm_parent_data_set (parameterlength = 90)*/
588 static int hf_ptp_mm_parent_data_set_parentcommunicationtechnology = -1;
589 static int hf_ptp_mm_parent_data_set_parentuuid = -1;
590 static int hf_ptp_mm_parent_data_set_parentportid = -1;
591 static int hf_ptp_mm_parent_data_set_parentlastsyncsequencenumber = -1;
592 static int hf_ptp_mm_parent_data_set_parentfollowupcapable = -1;
593 static int hf_ptp_mm_parent_data_set_parentexternaltiming = -1;
594 static int hf_ptp_mm_parent_data_set_parentvariance = -1;
595 static int hf_ptp_mm_parent_data_set_parentstats = -1;
596 static int hf_ptp_mm_parent_data_set_observedvariance = -1;
597 static int hf_ptp_mm_parent_data_set_observeddrift = -1;
598 static int hf_ptp_mm_parent_data_set_utcreasonable = -1;
599 static int hf_ptp_mm_parent_data_set_grandmastercommunicationtechnology = -1;
600 static int hf_ptp_mm_parent_data_set_grandmasteruuidfield = -1;
601 static int hf_ptp_mm_parent_data_set_grandmasterportidfield = -1;
602 static int hf_ptp_mm_parent_data_set_grandmasterstratum = -1;
603 static int hf_ptp_mm_parent_data_set_grandmasteridentifier = -1;
604 static int hf_ptp_mm_parent_data_set_grandmastervariance = -1;
605 static int hf_ptp_mm_parent_data_set_grandmasterpreferred = -1;
606 static int hf_ptp_mm_parent_data_set_grandmasterisboundaryclock = -1;
607 static int hf_ptp_mm_parent_data_set_grandmastersequencenumber = -1;
608
609         /*ptp_mm_port_data_set (parameterlength = 52)*/
610 static int hf_ptp_mm_port_data_set_returnedportnumber = -1;
611 static int hf_ptp_mm_port_data_set_portstate = -1;
612 static int hf_ptp_mm_port_data_set_lastsynceventsequencenumber = -1;
613 static int hf_ptp_mm_port_data_set_lastgeneraleventsequencenumber = -1;
614 static int hf_ptp_mm_port_data_set_portcommunicationtechnology = -1;
615 static int hf_ptp_mm_port_data_set_portuuidfield = -1;
616 static int hf_ptp_mm_port_data_set_portidfield = -1;
617 static int hf_ptp_mm_port_data_set_burstenabled = -1;
618 static int hf_ptp_mm_port_data_set_subdomainaddressoctets = -1;
619 static int hf_ptp_mm_port_data_set_eventportaddressoctets = -1;
620 static int hf_ptp_mm_port_data_set_generalportaddressoctets = -1;
621 static int hf_ptp_mm_port_data_set_subdomainaddress = -1;
622 static int hf_ptp_mm_port_data_set_eventportaddress = -1;
623 static int hf_ptp_mm_port_data_set_generalportaddress = -1;
624
625         /*ptp_mm_global_time_data_set (parameterlength = 24)*/
626 static int hf_ptp_mm_global_time_data_set_localtime = -1;
627 static int hf_ptp_mm_global_time_data_set_localtimeseconds = -1;
628 static int hf_ptp_mm_global_time_data_set_localtimenanoseconds = -1;
629 static int hf_ptp_mm_global_time_data_set_currentutcoffset = -1;
630 static int hf_ptp_mm_global_time_data_set_leap59 = -1;
631 static int hf_ptp_mm_global_time_data_set_leap61 = -1;
632 static int hf_ptp_mm_global_time_data_set_epochnumber = -1;
633
634         /*ptp_mm_update_global_time_properties (parameterlength = 16)*/
635 static int hf_ptp_mm_update_global_time_properties_currentutcoffset = -1;
636 static int hf_ptp_mm_update_global_time_properties_leap59 = -1;
637 static int hf_ptp_mm_update_global_time_properties_leap61 = -1;
638 static int hf_ptp_mm_update_global_time_properties_epochnumber = -1;
639
640         /*ptp_mm_get_foreign_data_set (parameterlength = 4)*/
641 static int hf_ptp_mm_get_foreign_data_set_recordkey = -1;
642
643         /*ptp_mm_foreign_data_set (parameterlength = 28)*/
644 static int hf_ptp_mm_foreign_data_set_returnedportnumber = -1;
645 static int hf_ptp_mm_foreign_data_set_returnedrecordnumber = -1;
646 static int hf_ptp_mm_foreign_data_set_foreignmastercommunicationtechnology = -1;
647 static int hf_ptp_mm_foreign_data_set_foreignmasteruuidfield = -1;
648 static int hf_ptp_mm_foreign_data_set_foreignmasterportidfield = -1;
649 static int hf_ptp_mm_foreign_data_set_foreignmastersyncs = -1;
650
651         /*ptp_mm_set_sync_interval (parameterlength = 4)*/
652 static int hf_ptp_mm_set_sync_interval_syncinterval = -1;
653
654         /*ptp_mm_set_time (parameterlength = 8)*/
655 static int hf_ptp_mm_set_time_localtime = -1;
656 static int hf_ptp_mm_set_time_localtimeseconds = -1;
657 static int hf_ptp_mm_set_time_localtimenanoseconds = -1;
658
659 /*END Initialize the protocol and registered fields */
660
661 /* Initialize the subtree pointers */
662 static gint ett_ptp = -1;
663 static gint ett_ptp_flags = -1;
664 static gint ett_ptp_time = -1;
665 static gint ett_ptp_time2 = -1;
666
667 /* END Definitions and fields for PTPv1 dissection. */
668
669
670
671
672
673 /***********************************************************************************/
674 /* Definitions and fields for PTPv2 dissection.                                    */
675 /***********************************************************************************/
676
677
678 /**********************************************************/
679 /* Offsets of fields within a PTPv2 packet.                               */
680 /**********************************************************/
681
682 /*Common offsets for all Messages (Sync, Delay_Req, Follow_Up, Delay_Resp ....)*/
683 #define PTP_V2_TRANSPORT_SPECIFIC_MESSAGE_ID_OFFSET                 0
684 #define PTP_V2_VERSIONPTP_OFFSET                                                1
685 #define PTP_V2_MESSAGE_LENGTH_OFFSET                                    2
686 #define PTP_V2_DOMAIN_NUMBER_OFFSET                                             4
687 #define PTP_V2_FLAGS_OFFSET                                         6
688 #define PTP_V2_CORRECTION_OFFSET                                    8
689 #define PTP_V2_CORRECTIONNS_OFFSET                                  8
690 #define PTP_V2_CORRECTIONSUBNS_OFFSET                               14
691 #define PTP_V2_CLOCKIDENTITY_OFFSET                                                                     20
692 #define PTP_V2_SOURCEPORTID_OFFSET                                  28
693 #define PTP_V2_SEQUENCEID_OFFSET                                    30
694 #define PTP_V2_CONTROL_OFFSET                                       32
695 #define PTP_V2_LOGMESSAGEPERIOD_OFFSET                              33
696
697
698 /*Offsets for PTP_Announce (=AN) messages*/
699 #define PTP_V2_AN_ORIGINTIMESTAMP_OFFSET                            34
700 #define PTP_V2_AN_ORIGINTIMESTAMPSECONDS_OFFSET                     34
701 #define PTP_V2_AN_ORIGINTIMESTAMPNANOSECONDS_OFFSET                 40
702 #define PTP_V2_AN_ORIGINCURRENTUTCOFFSET_OFFSET                     44
703 #define PTP_V2_AN_PRIORITY_1_OFFSET                                 47
704 #define PTP_V2_AN_GRANDMASTERCLOCKCLASS_OFFSET                          48
705 #define PTP_V2_AN_GRANDMASTERCLOCKACCURACY_OFFSET                       49
706 #define PTP_V2_AN_GRANDMASTERCLOCKVARIANCE_OFFSET                       50
707 #define PTP_V2_AN_PRIORITY_2_OFFSET                                 52
708 #define PTP_V2_AN_GRANDMASTERCLOCKIDENTITY_OFFSET                   53
709 #define PTP_V2_AN_LOCALSTEPSREMOVED_OFFSET                          61
710 #define PTP_V2_AN_TIMESOURCE_OFFSET                                     63
711 #define PTP_V2_AN_TLV_OFFSET                                        64
712 /* Announce TLV field offsets */
713 #define PTP_V2_AN_TLV_TYPE_OFFSET                                    0
714 #define PTP_V2_AN_TLV_LENGTHFIELD_OFFSET                             2
715 /* PTP_V2_TLV_TYPE_ALTERNATE_TIME_OFFSET_INDICATOR field offsets */
716 #define PTP_V2_AN_TLV_ATOI_KEYFIELD_OFFSET                           4
717 #define PTP_V2_AN_TLV_ATOI_CURRENTOFFSET_OFFSET                      5
718 #define PTP_V2_AN_TLV_ATOI_JUMPSECONDS_OFFSET                        9
719 #define PTP_V2_AN_TLV_ATOI_TIMEOFNEXTJUMP_OFFSET                    13
720 #define PTP_V2_AN_TLV_ATOI_DISPLAYNAME_OFFSET                       19
721 /* Undissected TLV field offset */
722 #define PTP_V2_AN_TLV_DATA_OFFSET                                    4
723
724 /*Offsets for PTP_Sync AND PTP_DelayRequest (=SDR) messages*/
725 #define PTP_V2_SDR_ORIGINTIMESTAMP_OFFSET                           34
726 #define PTP_V2_SDR_ORIGINTIMESTAMPSECONDS_OFFSET                    34
727 #define PTP_V2_SDR_ORIGINTIMESTAMPNANOSECONDS_OFFSET                40
728
729
730 /*Offsets for PTP_Follow_Up (=FU) messages*/
731 #define PTP_V2_FU_PRECISEORIGINTIMESTAMP_OFFSET                     34
732 #define PTP_V2_FU_PRECISEORIGINTIMESTAMPSECONDS_OFFSET              34
733 #define PTP_V2_FU_PRECISEORIGINTIMESTAMPNANOSECONDS_OFFSET          40
734
735 /*Offsets for PTP_DelayResponse (=DR) messages*/
736 #define PTP_V2_DR_RECEIVETIMESTAMP_OFFSET                           34
737 #define PTP_V2_DR_RECEIVETIMESTAMPSECONDS_OFFSET                    34
738 #define PTP_V2_DR_RECEIVETIMESTAMPNANOSECONDS_OFFSET                40
739 #define PTP_V2_DR_REQUESTINGPORTIDENTITY_OFFSET                     44
740 #define PTP_V2_DR_REQUESTINGSOURCEPORTID_OFFSET                     52
741
742
743 /*Offsets for PTP_PDelayRequest (=PDRQ) messages*/
744 #define PTP_V2_PDRQ_ORIGINTIMESTAMP_OFFSET                          34
745 #define PTP_V2_PDRQ_ORIGINTIMESTAMPSECONDS_OFFSET                   34
746 #define PTP_V2_PDRQ_ORIGINTIMESTAMPNANOSECONDS_OFFSET               40
747 #define PTP_V2_PDRQ_RESERVED_OFFSET                                             44
748
749
750 /*Offsets for PTP_PDelayResponse (=PDRS) messages*/
751 #define PTP_V2_PDRS_REQUESTRECEIPTTIMESTAMP_OFFSET                  34
752 #define PTP_V2_PDRS_REQUESTRECEIPTTIMESTAMPSECONDS_OFFSET           34
753 #define PTP_V2_PDRS_REQUESTRECEIPTTIMESTAMPNANOSECONDS_OFFSET       40
754 #define PTP_V2_PDRS_REQUESTINGPORTIDENTITY_OFFSET                   44 /* ++ */
755 #define PTP_V2_PDRS_REQUESTINGSOURCEPORTID_OFFSET                   52 /* ++ */
756
757
758 /*Offsets for PTP_PDelayResponseFollowUp (=PDFU) messages*/
759 #define PTP_V2_PDFU_RESPONSEORIGINTIMESTAMP_OFFSET                  34
760 #define PTP_V2_PDFU_RESPONSEORIGINTIMESTAMPSECONDS_OFFSET           34
761 #define PTP_V2_PDFU_RESPONSEORIGINTIMESTAMPNANOSECONDS_OFFSET       40
762 #define PTP_V2_PDFU_REQUESTINGPORTIDENTITY_OFFSET                   44 /* ++ */
763 #define PTP_V2_PDFU_REQUESTINGSOURCEPORTID_OFFSET                   52
764
765
766 /*Offsets for PTP_Signalling (=SIG) messages*/
767 #define PTP_V2_SIG_TARGETPORTIDENTITY_OFFSET                            34
768 #define PTP_V2_SIG_TARGETPORTID_OFFSET                                  42
769
770
771 /*Offsets for PTP_V2_Management (=MM) messages*/
772 #define PTP_V2_MM_TARGETPORTIDENTITY_OFFSET             34
773 #define PTP_V2_MM_TARGETPORTID_OFFSET                   42
774 #define PTP_V2_MM_STARTINGBOUNDARYHOPS_OFFSET           44
775 #define PTP_V2_MM_BOUNDARYHOPS_OFFSET                   45
776 #define PTP_V2_MM_ACTION_OFFSET                         46
777 #define PTP_V2_MM_RESERVED_OFFSET                       47
778
779 #define PTP_V2_MM_MANAGEMENTTLV_OFFSET                                  48
780 /* Management TLV */
781 #define PTP_V2_MM_TLV_TYPE_OFFSET                                               48
782 #define PTP_V2_MM_TLV_LENGTHFIELD_OFFSET                                50
783 #define PTP_V2_MM_TLV_MANAGEMENTID_OFFSET                               52
784 #define PTP_V2_MM_TLV_MANAGEMENTERRORID_OFFSET                  52
785 #define PTP_V2_MM_TLV_DATAFIELD_OFFSET                                  54
786
787 /* TLV Types */
788 #define PTP_V2_TLV_TYPE_RESERVED                                                0x0000
789 #define PTP_V2_TLV_TYPE_MANAGEMENT                                              0x0001
790 #define PTP_V2_TLV_TYPE_MANAGEMENT_ERROR_STATUS                 0x0002
791 #define PTP_V2_TLV_TYPE_ORGANIZATION_EXTENSION                  0x0003
792 #define PTP_V2_TLV_TYPE_REQUEST_UNICAST_TRANSMISSION    0x0004
793 #define PTP_V2_TLV_TYPE_GRANT_UNICAST_TRANSMISSION              0x0005
794 #define PTP_V2_TLV_TYPE_CANCEL_UNICAST_TRANSMISSION             0x0006
795 #define PTP_V2_TLV_TYPE_ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION 0x0007
796 #define PTP_V2_TLV_TYPE_PATH_TRACE                                              0x0008
797 #define PTP_V2_TLV_TYPE_ALTERNATE_TIME_OFFSET_INDICATOR 0x0009
798 #define PTP_V2_TLV_TYPE_AUTHENTICATION                                  0x2000
799 #define PTP_V2_TLV_TYPE_AUTHENTICATION_CHALLENGE                0x2001
800 #define PTP_V2_TLV_TYPE_SECURITY_ASSOCIATION_UPDATE             0x2002
801 #define PTP_V2_TLV_TYPE_CUM_FREQ_SCALE_FACTOR_OFFSET    0x2003
802
803 /* PTPv2 Management clockType Boolean[16] Bits mask */
804 #define CLOCKTYPE_ORDINARY_CLOCK                                                0x8000
805 #define CLOCKTYPE_BOUNDARY_CLOCK                                                0x4000
806 #define CLOCKTYPE_P2P_TC                                                                0x2000
807 #define CLOCKTYPE_E2E_TC                                                                0x1000
808 #define CLOCKTYPE_MANAGEMENT_NODE                                               0x0800
809 #define CLOCKTYPE_RESERVED                                                              0x07FF
810
811 /* PTPv2 Management IDs */
812 #define PTP_V2_MM_ID_NULL_MANAGEMENT                                    0x0000
813 #define PTP_V2_MM_ID_CLOCK_DESCRIPTION                                  0x0001
814 #define PTP_V2_MM_ID_USER_DESCRIPTION                                   0x0002
815 #define PTP_V2_MM_ID_SAVE_IN_NON_VOLATILE_STORAGE               0x0003
816 #define PTP_V2_MM_ID_RESET_NON_VOLATILE_STORAGE                 0x0004
817 #define PTP_V2_MM_ID_INITIALIZE                                                 0x0005
818 #define PTP_V2_MM_ID_FAULT_LOG                                                  0x0006
819 #define PTP_V2_MM_ID_FAULT_LOG_RESET                                    0x0007
820 #define PTP_V2_MM_ID_DEFAULT_DATA_SET                                   0x2000
821 #define PTP_V2_MM_ID_CURRENT_DATA_SET                                   0x2001
822 #define PTP_V2_MM_ID_PARENT_DATA_SET                                    0x2002
823 #define PTP_V2_MM_ID_TIME_PROPERTIES_DATA_SET                   0x2003
824 #define PTP_V2_MM_ID_PORT_DATA_SET                                              0x2004
825 #define PTP_V2_MM_ID_PRIORITY1                                                  0x2005
826 #define PTP_V2_MM_ID_PRIORITY2                                                  0x2006
827 #define PTP_V2_MM_ID_DOMAIN                                                             0x2007
828 #define PTP_V2_MM_ID_SLAVE_ONLY                                                 0x2008
829 #define PTP_V2_MM_ID_LOG_ANNOUNCE_INTERVAL                              0x2009
830 #define PTP_V2_MM_ID_ANNOUNCE_RECEIPT_TIMEOUT                   0x200A
831 #define PTP_V2_MM_ID_LOG_SYNC_INTERVAL                                  0x200B
832 #define PTP_V2_MM_ID_VERSION_NUMBER                                             0x200C
833 #define PTP_V2_MM_ID_ENABLE_PORT                                                0x200D
834 #define PTP_V2_MM_ID_DISABLE_PORT                                               0x200E
835 #define PTP_V2_MM_ID_TIME                                                               0x200F
836 #define PTP_V2_MM_ID_CLOCK_ACCURACY                                             0x2010
837 #define PTP_V2_MM_ID_UTC_PROPERTIES                                             0x2011
838 #define PTP_V2_MM_ID_TRACEABILITY_PROPERTIES                    0x2012
839 #define PTP_V2_MM_ID_TIMESCALE_PROPERTIES                               0x2013
840 #define PTP_V2_MM_ID_UNICAST_NEGOTIATION_ENABLE                 0x2014
841 #define PTP_V2_MM_ID_PATH_TRACE_LIST                                    0x2015
842 #define PTP_V2_MM_ID_PATH_TRACE_ENABLE                                  0x2016
843 #define PTP_V2_MM_ID_GRANDMASTER_CLUSTER_TABLE                  0x2017
844 #define PTP_V2_MM_ID_UNICAST_MASTER_TABLE                               0x2018
845 #define PTP_V2_MM_ID_UNICAST_MASTER_MAX_TABLE_SIZE              0x2019
846 #define PTP_V2_MM_ID_ACCEPTABLE_MASTER_TABLE                    0x201A
847 #define PTP_V2_MM_ID_ACCEPTABLE_MASTER_TABLE_ENABLED    0x201B
848 #define PTP_V2_MM_ID_ACCEPTABLE_MASTER_MAX_TABLE_SIZE   0x201C
849 #define PTP_V2_MM_ID_ALTERNATE_MASTER                                   0x201D
850 #define PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_ENABLE               0x201E
851 #define PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_NAME                 0x201F
852 #define PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_MAX_KEY              0x2020
853 #define PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_PROPERTIES   0x2021
854 #define PTP_V2_MM_ID_TC_DEFAULT_DATA_SET                                0x4000
855 #define PTP_V2_MM_ID_TC_PORT_DATA_SET                                   0x4001
856 #define PTP_V2_MM_ID_PRIMARY_DOMAIN                                             0x4002
857 #define PTP_V2_MM_ID_DELAY_MECHANISM                                    0x6000
858 #define PTP_V2_MM_ID_LOG_MIN_PDELAY_REQ_INTERVAL                0x6001
859
860 /* Management DataField for DefaultDS */
861 #define PTP_V2_MM_RESERVED1                                                             PTP_V2_MM_TLV_DATAFIELD_OFFSET + 1
862 #define PTP_V2_MM_NUMBERPORTS                                                   PTP_V2_MM_TLV_DATAFIELD_OFFSET + 2
863 #define PTP_V2_MM_PRIORITY1                                                             PTP_V2_MM_TLV_DATAFIELD_OFFSET + 4
864 #define PTP_V2_MM_CLOCKQUALITY                                                  PTP_V2_MM_TLV_DATAFIELD_OFFSET + 5
865 #define PTP_V2_MM_PRIORITY2                                                             PTP_V2_MM_TLV_DATAFIELD_OFFSET + 9
866 #define PTP_V2_MM_CLOCKIDENTITY                                                 PTP_V2_MM_TLV_DATAFIELD_OFFSET + 10
867 #define PTP_V2_MM_DOMAINNUMBER                                                  PTP_V2_MM_TLV_DATAFIELD_OFFSET + 18
868 #define PTP_V2_MM_RESERVED2                                                             PTP_V2_MM_TLV_DATAFIELD_OFFSET + 19
869
870 #define PTP_V2_TRANSPORTSPECIFIC_V1COMPATIBILITY_BITMASK                        0x10
871
872
873
874 /**********************************************************/
875 /* flag-field-mask-definitions                                                    */
876 /**********************************************************/
877 #define PTP_V2_FLAGS_LI61_BITMASK                                                               0x0001
878 #define PTP_V2_FLAGS_LI59_BITMASK                                                               0x0002
879 #define PTP_V2_FLAGS_UTC_OFFSET_VALID_BITMASK                                   0x0004
880 #define PTP_V2_FLAGS_PTP_TIMESCALE_BITMASK                                              0x0008
881 #define PTP_V2_FLAGS_TIME_TRACEABLE_BITMASK                                             0x0010
882 #define PTP_V2_FLAGS_FREQUENCY_TRACEABLE_BITMASK                                    0x0020
883 #define PTP_V2_FLAGS_ALTERNATE_BITMASK                                                  0x0100
884 #define PTP_V2_FLAGS_TWO_STEP_BITMASK                                                   0x0200
885 #define PTP_V2_FLAGS_UNICAST_BITMASK                                                    0x0400
886 #define PTP_V2_FLAGS_SPECIFIC1_BITMASK                                                  0x2000
887 #define PTP_V2_FLAGS_SPECIFIC2_BITMASK                                                  0x4000
888 #define PTP_V2_FLAGS_SECURITY_BITMASK                                                   0x8000
889
890
891
892 /**********************************************************/
893 /* PTP v2 message ids   (ptp messageid field)                 */
894 /**********************************************************/
895 #define PTP_V2_SYNC_MESSAGE                     0x00
896 #define PTP_V2_DELAY_REQ_MESSAGE                0x01
897 #define PTP_V2_PATH_DELAY_REQ_MESSAGE           0x02
898 #define PTP_V2_PATH_DELAY_RESP_MESSAGE          0x03
899 #define PTP_V2_FOLLOWUP_MESSAGE                 0x08
900 #define PTP_V2_DELAY_RESP_MESSAGE               0x09
901 #define PTP_V2_PATH_DELAY_FOLLOWUP_MESSAGE      0x0A
902 #define PTP_V2_ANNOUNCE_MESSAGE                 0x0B
903 #define PTP_V2_SIGNALLING_MESSAGE               0x0C
904 #define PTP_V2_MANAGEMENT_MESSAGE               0x0D
905
906
907 static const value_string ptp_v2_managementID_vals[] = {
908         {PTP_V2_MM_ID_NULL_MANAGEMENT                                   ,"NULL_MANAGEMENT"},
909         {PTP_V2_MM_ID_CLOCK_DESCRIPTION                                 ,"CLOCK_DESCRIPTION"},
910         {PTP_V2_MM_ID_USER_DESCRIPTION                                  ,"USER_DESCRIPTION"},
911         {PTP_V2_MM_ID_SAVE_IN_NON_VOLATILE_STORAGE              ,"SAVE_IN_NON_VOLATILE_STORAGE"},
912         {PTP_V2_MM_ID_RESET_NON_VOLATILE_STORAGE                ,"RESET_NON_VOLATILE_STORAGE"},
913         {PTP_V2_MM_ID_INITIALIZE                                                ,"INITIALIZE"},
914         {PTP_V2_MM_ID_FAULT_LOG                                                 ,"FAULT_LOG"},
915         {PTP_V2_MM_ID_FAULT_LOG_RESET                                   ,"FAULT_LOG_RESET"},
916         {PTP_V2_MM_ID_DEFAULT_DATA_SET                                  ,"DEFAULT_DATA_SET"},
917         {PTP_V2_MM_ID_CURRENT_DATA_SET                                  ,"CURRENT_DATA_SET"},
918         {PTP_V2_MM_ID_PARENT_DATA_SET                                   ,"PARENT_DATA_SET"},
919         {PTP_V2_MM_ID_TIME_PROPERTIES_DATA_SET                  ,"TIME_PROPERTIES_DATA_SET"},
920         {PTP_V2_MM_ID_PORT_DATA_SET                                             ,"PORT_DATA_SET"},
921         {PTP_V2_MM_ID_PRIORITY1                                                 ,"PRIORITY1"},
922         {PTP_V2_MM_ID_PRIORITY2                                                 ,"PRIORITY2"},
923         {PTP_V2_MM_ID_DOMAIN                                                    ,"DOMAIN"},
924         {PTP_V2_MM_ID_SLAVE_ONLY                                                ,"SLAVE_ONLY"},
925         {PTP_V2_MM_ID_LOG_ANNOUNCE_INTERVAL                             ,"LOG_ANNOUNCE_INTERVAL"},
926         {PTP_V2_MM_ID_ANNOUNCE_RECEIPT_TIMEOUT                  ,"ANNOUNCE_RECEIPT_TIMEOUT"},
927         {PTP_V2_MM_ID_LOG_SYNC_INTERVAL                                 ,"LOG_SYNC_INTERVAL"},
928         {PTP_V2_MM_ID_VERSION_NUMBER                                    ,"VERSION_NUMBER"},
929         {PTP_V2_MM_ID_ENABLE_PORT                                               ,"ENABLE_PORT"},
930         {PTP_V2_MM_ID_DISABLE_PORT                                              ,"DISABLE_PORT"},
931         {PTP_V2_MM_ID_TIME                                                              ,"TIME"},
932         {PTP_V2_MM_ID_CLOCK_ACCURACY                                    ,"CLOCK_ACCURACY"},
933         {PTP_V2_MM_ID_UTC_PROPERTIES                                    ,"UTC_PROPERTIES"},
934         {PTP_V2_MM_ID_TRACEABILITY_PROPERTIES                   ,"TRACEABILITY_PROPERTIES"},
935         {PTP_V2_MM_ID_TIMESCALE_PROPERTIES                              ,"TIMESCALE_PROPERTIES"},
936         {PTP_V2_MM_ID_UNICAST_NEGOTIATION_ENABLE                ,"UNICAST_NEGOTIATION_ENABLE"},
937         {PTP_V2_MM_ID_PATH_TRACE_LIST                                   ,"PATH_TRACE_LIST"},
938         {PTP_V2_MM_ID_PATH_TRACE_ENABLE                                 ,"PATH_TRACE_ENABLE"},
939         {PTP_V2_MM_ID_GRANDMASTER_CLUSTER_TABLE                 ,"GRANDMASTER_CLUSTER_TABLE"},
940         {PTP_V2_MM_ID_UNICAST_MASTER_TABLE                              ,"UNICAST_MASTER_TABLE"},
941         {PTP_V2_MM_ID_UNICAST_MASTER_MAX_TABLE_SIZE             ,"UNICAST_MASTER_MAX_TABLE_SIZE"},
942         {PTP_V2_MM_ID_ACCEPTABLE_MASTER_TABLE                   ,"ACCEPTABLE_MASTER_TABLE"},
943         {PTP_V2_MM_ID_ACCEPTABLE_MASTER_TABLE_ENABLED   ,"ACCEPTABLE_MASTER_TABLE_ENABLED"},
944         {PTP_V2_MM_ID_ACCEPTABLE_MASTER_MAX_TABLE_SIZE  ,"ACCEPTABLE_MASTER_MAX_TABLE_SIZE"},
945         {PTP_V2_MM_ID_ALTERNATE_MASTER                                  ,"ALTERNATE_MASTER"},
946         {PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_ENABLE              ,"ALTERNATE_TIME_OFFSET_ENABLE"},
947         {PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_NAME                ,"ALTERNATE_TIME_OFFSET_NAME"},
948         {PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_MAX_KEY             ,"ALTERNATE_TIME_OFFSET_MAX_KEY"},
949         {PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_PROPERTIES  ,"ALTERNATE_TIME_OFFSET_PROPERTIES"},
950         {PTP_V2_MM_ID_TC_DEFAULT_DATA_SET                               ,"TC_DEFAULT_DATA_SET"},
951         {PTP_V2_MM_ID_TC_PORT_DATA_SET                                  ,"TC_PORT_DATA_SET"},
952         {PTP_V2_MM_ID_PRIMARY_DOMAIN                                    ,"PRIMARY_DOMAIN"},
953         {PTP_V2_MM_ID_DELAY_MECHANISM                                   ,"DELAY_MECHANISM"},
954         {PTP_V2_MM_ID_LOG_MIN_PDELAY_REQ_INTERVAL               ,"LOG_MIN_PDELAY_REQ_INTERVAL"},
955     {0                                                                                          ,NULL} };
956
957 /*same again but better readable text for info column*/
958 static const value_string ptp_v2_managementID_infocolumn_vals[] = {
959         {PTP_V2_MM_ID_NULL_MANAGEMENT                                   ,"Null management"},
960         {PTP_V2_MM_ID_CLOCK_DESCRIPTION                                 ,"Clock description"},
961         {PTP_V2_MM_ID_USER_DESCRIPTION                                  ,"User description"},
962         {PTP_V2_MM_ID_SAVE_IN_NON_VOLATILE_STORAGE              ,"Save in non volatile storage"},
963         {PTP_V2_MM_ID_RESET_NON_VOLATILE_STORAGE                ,"Reset non volatile storage"},
964         {PTP_V2_MM_ID_INITIALIZE                                                ,"Initialize"},
965         {PTP_V2_MM_ID_FAULT_LOG                                                 ,"Fault log"},
966         {PTP_V2_MM_ID_FAULT_LOG_RESET                                   ,"Fault log reset"},
967         {PTP_V2_MM_ID_DEFAULT_DATA_SET                                  ,"Default dataset"},
968         {PTP_V2_MM_ID_CURRENT_DATA_SET                                  ,"Current dataset"},
969         {PTP_V2_MM_ID_PARENT_DATA_SET                                   ,"Parent dataset"},
970         {PTP_V2_MM_ID_TIME_PROPERTIES_DATA_SET                  ,"Time properties dataset"},
971         {PTP_V2_MM_ID_PORT_DATA_SET                                             ,"Port dataset"},
972         {PTP_V2_MM_ID_PRIORITY1                                                 ,"Priority 1"},
973         {PTP_V2_MM_ID_PRIORITY2                                                 ,"Priority 2"},
974         {PTP_V2_MM_ID_DOMAIN                                                    ,"Domain"},
975         {PTP_V2_MM_ID_SLAVE_ONLY                                                ,"Slave only"},
976         {PTP_V2_MM_ID_LOG_ANNOUNCE_INTERVAL                             ,"Log announce interval"},
977         {PTP_V2_MM_ID_ANNOUNCE_RECEIPT_TIMEOUT                  ,"Announce receipt timeout"},
978         {PTP_V2_MM_ID_LOG_SYNC_INTERVAL                                 ,"Log sync interval"},
979         {PTP_V2_MM_ID_VERSION_NUMBER                                    ,"Version number"},
980         {PTP_V2_MM_ID_ENABLE_PORT                                               ,"Enable port"},
981         {PTP_V2_MM_ID_DISABLE_PORT                                              ,"Disable port"},
982         {PTP_V2_MM_ID_TIME                                                              ,"Time"},
983         {PTP_V2_MM_ID_CLOCK_ACCURACY                                    ,"Clock accuracy"},
984         {PTP_V2_MM_ID_UTC_PROPERTIES                                    ,"UTC properties"},
985         {PTP_V2_MM_ID_TRACEABILITY_PROPERTIES                   ,"Traceability properties"},
986         {PTP_V2_MM_ID_TIMESCALE_PROPERTIES                              ,"Timescale properties"},
987         {PTP_V2_MM_ID_UNICAST_NEGOTIATION_ENABLE                ,"Unicast negotiation enable"},
988         {PTP_V2_MM_ID_PATH_TRACE_LIST                                   ,"Path trace list"},
989         {PTP_V2_MM_ID_PATH_TRACE_ENABLE                                 ,"Path trace enable"},
990         {PTP_V2_MM_ID_GRANDMASTER_CLUSTER_TABLE                 ,"Grandmaster cluster table"},
991         {PTP_V2_MM_ID_UNICAST_MASTER_TABLE                              ,"Unicast master table"},
992         {PTP_V2_MM_ID_UNICAST_MASTER_MAX_TABLE_SIZE             ,"Unicast master max table size"},
993         {PTP_V2_MM_ID_ACCEPTABLE_MASTER_TABLE                   ,"Acceptable master table"},
994         {PTP_V2_MM_ID_ACCEPTABLE_MASTER_TABLE_ENABLED   ,"Acceptable master table enabled"},
995         {PTP_V2_MM_ID_ACCEPTABLE_MASTER_MAX_TABLE_SIZE  ,"Acceptable master max table size"},
996         {PTP_V2_MM_ID_ALTERNATE_MASTER                                  ,"Alternate master"},
997         {PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_ENABLE              ,"Alternate time offset enable"},
998         {PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_NAME                ,"Alternate time offset name"},
999         {PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_MAX_KEY             ,"Alternate time offset max key"},
1000         {PTP_V2_MM_ID_ALTERNATE_TIME_OFFSET_PROPERTIES  ,"Alternate time offset properties"},
1001         {PTP_V2_MM_ID_TC_DEFAULT_DATA_SET                               ,"Transparent clock default dataset"},
1002         {PTP_V2_MM_ID_TC_PORT_DATA_SET                                  ,"Transparent clock port dataset"},
1003         {PTP_V2_MM_ID_PRIMARY_DOMAIN                                    ,"Primary domain"},
1004         {PTP_V2_MM_ID_DELAY_MECHANISM                                   ,"Delay mechanism"},
1005         {PTP_V2_MM_ID_LOG_MIN_PDELAY_REQ_INTERVAL               ,"Log min pdelay req. interval"},
1006     {0                                                                                          , NULL} };
1007
1008 static const value_string ptp_v2_TLV_type_vals[] = {
1009         {PTP_V2_TLV_TYPE_RESERVED                                               ,"Reserved"},
1010         {PTP_V2_TLV_TYPE_MANAGEMENT                                             ,"Management"},
1011         {PTP_V2_TLV_TYPE_MANAGEMENT_ERROR_STATUS                ,"Management error status"},
1012         {PTP_V2_TLV_TYPE_ORGANIZATION_EXTENSION                 ,"Organization extension"},
1013         {PTP_V2_TLV_TYPE_REQUEST_UNICAST_TRANSMISSION   ,"Request unicast transmission"},
1014         {PTP_V2_TLV_TYPE_GRANT_UNICAST_TRANSMISSION             ,"Grant unicast transmission"},
1015         {PTP_V2_TLV_TYPE_CANCEL_UNICAST_TRANSMISSION    ,"Cancel unicast transmission"},
1016         {PTP_V2_TLV_TYPE_ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION        ,"Acknowledge cancel unicast transmission"},
1017         {PTP_V2_TLV_TYPE_PATH_TRACE                                             ,"Path trace"},
1018         {PTP_V2_TLV_TYPE_ALTERNATE_TIME_OFFSET_INDICATOR,"Alternate time offset indicator"},
1019         {PTP_V2_TLV_TYPE_AUTHENTICATION                                 ,"Authentication"},
1020         {PTP_V2_TLV_TYPE_AUTHENTICATION_CHALLENGE               ,"Authentication challenge"},
1021         {PTP_V2_TLV_TYPE_SECURITY_ASSOCIATION_UPDATE    ,"Security association update"},
1022         {PTP_V2_TLV_TYPE_CUM_FREQ_SCALE_FACTOR_OFFSET   ,"Cum. freq. scale factor offset"},
1023     {0                                                                                          , NULL} };
1024
1025
1026 static const value_string ptp2_networkProtocol_vals[] = {
1027   {0x0000,  "Reserved"},
1028   {0x0001,  "UDP/IPv4"},
1029   {0x0002,  "UDP/IPv6"},
1030   {0x0003,  "IEEE 802.3"},
1031   {0x0004,  "DeviceNet"},
1032   {0x0005,  "ControlNet"},
1033   {0x0006,  "PROFINET"},
1034   {0x0007,  "Reserved"},
1035   {0xFFFE,  "Unknown Protocol"},
1036   {0xFFFF,  "Reserved"},
1037   {0,              NULL          } };
1038
1039
1040 static const value_string ptp_v2_messageid_vals[] = {
1041     {PTP_V2_SYNC_MESSAGE,                               "Sync Message"},
1042     {PTP_V2_DELAY_REQ_MESSAGE,                  "Delay_Req Message"},
1043     {PTP_V2_PATH_DELAY_REQ_MESSAGE,             "Path_Delay_Req Message"},
1044     {PTP_V2_PATH_DELAY_RESP_MESSAGE,    "Path_Delay_Resp Message"},
1045     {PTP_V2_FOLLOWUP_MESSAGE,                   "Follow_Up Message"},
1046     {PTP_V2_DELAY_RESP_MESSAGE,                 "Delay_Resp Message"},
1047     {PTP_V2_PATH_DELAY_FOLLOWUP_MESSAGE,"Path_Delay_Resp_Follow_Up Message"},
1048     {PTP_V2_ANNOUNCE_MESSAGE,                   "Announce Message"},
1049     {PTP_V2_SIGNALLING_MESSAGE,                 "Signalling Message"},
1050     {PTP_V2_MANAGEMENT_MESSAGE,                 "Management Message"},
1051     {0,                                                                  NULL }
1052 };
1053
1054 static const value_string ptp_v2_clockaccuracy_vals[] = {
1055     {0x20,  "The time is accurate to within 25 ns"},
1056         {0x21,  "The time is accurate to within 100 ns"},
1057         {0x22,  "The time is accurate to within 250 ns"},
1058         {0x23,  "The time is accurate to within 1 us"},
1059         {0x24,  "The time is accurate to within 2,5 us"},
1060         {0x25,  "The time is accurate to within 10 us"},
1061         {0x26,  "The time is accurate to within 25 us"},
1062         {0x27,  "The time is accurate to within 100 us"},
1063         {0x28,  "The time is accurate to within 250 us"},
1064         {0x29,  "The time is accurate to within 1 ms"},
1065         {0x2A,  "The time is accurate to within 2,5 ms"},
1066         {0x2B,  "The time is accurate to within 10 ms"},
1067         {0x2C,  "The time is accurate to within 25 ms"},
1068         {0x2D,  "The time is accurate to within 100 ms"},
1069         {0x2E,  "The time is accurate to within 250 ms"},
1070         {0x2F,  "The time is accurate to within 1 s"},
1071         {0x30,  "The time is accurate to within 10 s"},
1072         {0x31,  "The time is accurate to >10 s"},
1073         {0x32,  "reserved"},
1074         {0x80,  "For use by alternate PTP profiles"},
1075         {0xFE,  "Accuracy Unknown"},
1076         {0xFF,  "reserved"},
1077         {0,              NULL          }
1078 };
1079
1080 static const value_string ptp_v2_timesource_vals[] = {
1081     {0x10,  "ATOMIC_CLOCK"},
1082         {0x20,  "GPS"},
1083         {0x30,  "TERRESTRIAL_RADIO"},
1084         {0x40,  "PTP"},
1085         {0x50,  "NTP"},
1086         {0x60,  "HAND_SET"},
1087         {0x90,  "OTHER"},
1088         {0xA0,  "INTERNAL_OSCILLATOR"},
1089         {0xFF,  "reserved"},
1090         {0,              NULL          }
1091 };
1092
1093 static const value_string ptp_v2_mm_action_vals[] = {
1094     {0x0,  "GET"},
1095         {0x1,  "SET"},
1096         {0x2,  "RESPONSE"},
1097         {0x3,  "COMMAND"},
1098         {0x4,  "ACKNOWLEDGE"},
1099         {0,              NULL          }
1100 };
1101
1102 static const value_string ptp2_severityCode_vals[] = {
1103   {0x00,  "Emergency: system is unusable"},
1104   {0x01,  "Alert: immediate action needed"},
1105   {0x02,  "Critical: critical conditions"},
1106   {0x03,  "Error: error conditions"},
1107   {0x04,  "Warning: warning conditions"},
1108   {0x05,  "Notice: normal but significant condition"},
1109   {0x06,  "Informational: informational messages"},
1110   {0x07,  "Debug: debug-level messages"},
1111   {0x08,  "Reserved"},
1112   {0xFF,  "Reserved"},
1113   {0,      NULL}
1114 };
1115
1116 static const value_string ptp2_portState_vals[] = {
1117   {0x01,  "INITIALIZING"},
1118   {0x02,  "FAULTY"},
1119   {0x03,  "DISABLED"},
1120   {0x04,  "LISTENING"},
1121   {0x05,  "PRE_MASTER"},
1122   {0x06,  "MASTER"},
1123   {0x07,  "PASSIVE"},
1124   {0x08,  "UNCALIBRATED"},
1125   {0x09,  "SLAVE"},
1126   {0,     NULL}
1127 };
1128
1129 static const value_string ptp2_delayMechanism_vals[] = {
1130   {0x01,  "E2E"},
1131   {0x02,  "P2P"},
1132   {0xFE,  "DISABLED"},
1133   {0,     NULL}
1134 };
1135
1136 static const value_string ptp2_managementErrorId_vals[] = {
1137   {0x0000,  "Reserved"},
1138   {0x0001,  "RESPONSE_TOO_BIG"},
1139   {0x0002,  "NO_SUCH_ID"},
1140   {0x0003,  "WRONG_LENGTH"},
1141   {0x0004,  "WRONG_VALUE"},
1142   {0x0005,  "NOT_SETABLE"},
1143   {0x0006,  "NOT_SUPPORTED"},
1144   {0x0007,  "Reserved"},
1145   {0xFFFE,  "GENERAL_ERROR"},
1146   {0xFFFF,  "Reserved"},
1147   {0,     NULL}
1148 };
1149
1150 /**********************************************************/
1151 /* Initialize the protocol and registered fields                  */
1152 /**********************************************************/
1153
1154 static int hf_ptp_v2_transportspecific = -1;
1155 static int hf_ptp_v2_transportspecific_v1_compatibility = -1; /* over UDP */
1156 static int hf_ptp_v2_transportspecific_802as_conform = -1; /* over Ethernet */
1157 static int hf_ptp_v2_messageid = -1;
1158 static int hf_ptp_v2_versionptp = -1;
1159 static int hf_ptp_v2_messagelength = -1;
1160 static int hf_ptp_v2_domainnumber = -1;
1161 static int hf_ptp_v2_flags = -1;
1162 static int hf_ptp_v2_flags_alternatemaster = -1;
1163 static int hf_ptp_v2_flags_twostep = -1;
1164 static int hf_ptp_v2_flags_unicast = -1;
1165 static int hf_ptp_v2_flags_specific1 = -1;
1166 static int hf_ptp_v2_flags_specific2 = -1;
1167 static int hf_ptp_v2_flags_security = -1;
1168 static int hf_ptp_v2_flags_li61 = -1;
1169 static int hf_ptp_v2_flags_li59 = -1;
1170 static int hf_ptp_v2_flags_utcoffsetvalid = -1;
1171 static int hf_ptp_v2_flags_ptptimescale = -1;
1172 static int hf_ptp_v2_flags_timetraceable = -1;
1173 static int hf_ptp_v2_flags_frequencytraceable = -1;
1174 static int hf_ptp_v2_correction = -1;
1175 static int hf_ptp_v2_correctionsubns = -1;
1176 static int hf_ptp_v2_clockidentity = -1;
1177 static int hf_ptp_v2_sourceportid = -1;
1178 static int hf_ptp_v2_sequenceid = -1;
1179 static int hf_ptp_v2_control = -1;
1180 static int hf_ptp_v2_logmessageperiod = -1;
1181
1182
1183 /*Fields for PTP_Announce (=an) messages*/
1184 static int hf_ptp_v2_an_origintimestamp = -1;   /*Field for seconds & nanoseconds*/
1185 static int hf_ptp_v2_an_origintimestamp_seconds = -1;
1186 static int hf_ptp_v2_an_origintimestamp_nanoseconds = -1;
1187 static int hf_ptp_v2_an_origincurrentutcoffset = -1;
1188 static int hf_ptp_v2_an_timesource = -1;
1189 static int hf_ptp_v2_an_localstepsremoved = -1;
1190 static int hf_ptp_v2_an_grandmasterclockidentity = -1;
1191 static int hf_ptp_v2_an_grandmasterclockclass = -1;
1192 static int hf_ptp_v2_an_grandmasterclockaccuracy = -1;
1193 static int hf_ptp_v2_an_grandmasterclockvariance = -1;
1194 static int hf_ptp_v2_an_priority1 = -1;
1195 static int hf_ptp_v2_an_priority2 = -1;
1196
1197 /* Fields for PTP_Announce TLVs */
1198 static int hf_ptp_v2_an_tlv_tlvtype = -1;
1199 static int hf_ptp_v2_an_tlv_lengthfield = -1;
1200 /* Fields for the ALTERNATE_TIME_OFFSET_INDICATOR TLV */
1201 static int hf_ptp_v2_atoi_tlv_keyfield = -1;
1202 static int hf_ptp_v2_atoi_tlv_currentoffset = -1;
1203 static int hf_ptp_v2_atoi_tlv_jumpseconds = -1;
1204 static int hf_ptp_v2_atoi_tlv_timeofnextjump = -1;
1205 static int hf_ptp_v2_atoi_tlv_displayname = -1;
1206 static int hf_ptp_v2_atoi_tlv_displayname_length = -1;
1207
1208 /* Fields for an undissected TLV */
1209 static int hf_ptp_v2_an_tlv_data = -1;
1210
1211 /*Fields for PTP_Sync AND PTP_DelayRequest (=sdr) messages*/
1212 static int hf_ptp_v2_sdr_origintimestamp = -1;  /*Field for seconds & nanoseconds*/
1213 static int hf_ptp_v2_sdr_origintimestamp_seconds = -1;
1214 static int hf_ptp_v2_sdr_origintimestamp_nanoseconds = -1;
1215
1216
1217 /*Fields for PTP_Follow_Up (=fu) messages*/
1218 static int hf_ptp_v2_fu_preciseorigintimestamp = -1;    /*Field for seconds & nanoseconds*/
1219 static int hf_ptp_v2_fu_preciseorigintimestamp_seconds = -1;
1220 static int hf_ptp_v2_fu_preciseorigintimestamp_nanoseconds = -1;
1221
1222
1223 /*Fields for PTP_DelayResponse (=dr) messages*/
1224 static int hf_ptp_v2_dr_receivetimestamp = -1;  /*Field for seconds & nanoseconds*/
1225 static int hf_ptp_v2_dr_receivetimestamp_seconds = -1;
1226 static int hf_ptp_v2_dr_receivetimestamp_nanoseconds = -1;
1227 static int hf_ptp_v2_dr_requestingportidentity = -1;
1228 static int hf_ptp_v2_dr_requestingsourceportid = -1;
1229
1230
1231 /*Fields for PTP_PDelayRequest (=pdrq) messages*/
1232 static int hf_ptp_v2_pdrq_origintimestamp = -1; /*Field for seconds & nanoseconds*/
1233 static int hf_ptp_v2_pdrq_origintimestamp_seconds = -1;
1234 static int hf_ptp_v2_pdrq_origintimestamp_nanoseconds = -1;
1235
1236
1237 /*Fields for PTP_PDelayResponse (=pdrs) messages*/
1238 static int hf_ptp_v2_pdrs_requestreceipttimestamp = -1; /*Field for seconds & nanoseconds*/
1239 static int hf_ptp_v2_pdrs_requestreceipttimestamp_seconds = -1;
1240 static int hf_ptp_v2_pdrs_requestreceipttimestamp_nanoseconds = -1;
1241 static int hf_ptp_v2_pdrs_requestingportidentity = -1;
1242 static int hf_ptp_v2_pdrs_requestingsourceportid = -1;
1243
1244
1245 /*Fields for PTP_PDelayResponseFollowUp (=pdfu) messages*/
1246 static int hf_ptp_v2_pdfu_responseorigintimestamp = -1; /*Field for seconds & nanoseconds*/
1247 static int hf_ptp_v2_pdfu_responseorigintimestamp_seconds = -1;
1248 static int hf_ptp_v2_pdfu_responseorigintimestamp_nanoseconds = -1;
1249 static int hf_ptp_v2_pdfu_requestingportidentity = -1;
1250 static int hf_ptp_v2_pdfu_requestingsourceportid = -1;
1251
1252
1253 /*Fields for PTP_Signalling (=sig) messages*/
1254 static int hf_ptp_v2_sig_targetportidentity = -1;
1255 static int hf_ptp_v2_sig_targetportid = -1;
1256
1257
1258 /*Fields for PTP_Management (=mm) messages*/
1259 static int hf_ptp_v2_mm_targetportidentity = -1;
1260 static int hf_ptp_v2_mm_targetportid = -1;
1261 static int hf_ptp_v2_mm_startingboundaryhops = -1;
1262 static int hf_ptp_v2_mm_boundaryhops = -1;
1263 static int hf_ptp_v2_mm_action = -1;
1264
1265 /* management TLV */
1266 static int hf_ptp_v2_mm_tlvType = -1;
1267 static int hf_ptp_v2_mm_lengthField = -1;
1268 static int hf_ptp_v2_mm_managementId = -1;
1269 static int hf_ptp_v2_mm_data = -1;
1270 /* Management dataField  */
1271
1272 static int hf_ptp_v2_mm_clockType = -1;
1273 static int hf_ptp_v2_mm_clockType_ordinaryClock = -1;
1274 static int hf_ptp_v2_mm_clockType_boundaryClock = -1;
1275 static int hf_ptp_v2_mm_clockType_p2p_transparentClock = -1;
1276 static int hf_ptp_v2_mm_clockType_e2e_transparentClock = -1;
1277 static int hf_ptp_v2_mm_clockType_managementNode = -1;
1278 static int hf_ptp_v2_mm_clockType_reserved = -1;
1279 static int hf_ptp_v2_mm_physicalLayerProtocol = -1;
1280 static int hf_ptp_v2_mm_physicalLayerProtocol_length = -1;
1281 static int hf_ptp_v2_mm_physicalAddressLength = -1;
1282 static int hf_ptp_v2_mm_physicalAddress = -1;
1283 static int hf_ptp_v2_mm_protocolAddress = -1;
1284 static int hf_ptp_v2_mm_protocolAddress_networkProtocol = -1;
1285 static int hf_ptp_v2_mm_protocolAddress_length = -1;
1286 static int hf_ptp_v2_mm_manufacturerIdentity = -1;
1287
1288 static int hf_ptp_v2_mm_reserved = -1;
1289 static int hf_ptp_v2_mm_productDescription = -1;
1290 static int hf_ptp_v2_mm_productDescription_length = -1;
1291 static int hf_ptp_v2_mm_revisionData = -1;
1292 static int hf_ptp_v2_mm_revisionData_length = -1;
1293 static int hf_ptp_v2_mm_userDescription = -1;
1294 static int hf_ptp_v2_mm_userDescription_length = -1;
1295 static int hf_ptp_v2_mm_profileIdentity = -1;
1296 static int hf_ptp_v2_mm_pad = -1;
1297
1298 static int hf_ptp_v2_mm_numberOfFaultRecords = -1;
1299 static int hf_ptp_v2_mm_faultRecord = -1;
1300
1301 static int hf_ptp_v2_mm_initializationKey = -1;
1302 static int hf_ptp_v2_mm_severityCode = -1;
1303 static int hf_ptp_v2_mm_faultRecordLength = -1;
1304 static int hf_ptp_v2_mm_faultTime = -1;
1305 static int hf_ptp_v2_mm_faultTime_s = -1;
1306 static int hf_ptp_v2_mm_faultTime_ns = -1;
1307 static int hf_ptp_v2_mm_faultValue = -1;
1308 static int hf_ptp_v2_mm_faultName = -1;
1309 static int hf_ptp_v2_mm_faultName_length = -1;
1310 static int hf_ptp_v2_mm_faultValue_length = -1;
1311 static int hf_ptp_v2_mm_faultDescription = -1;
1312 static int hf_ptp_v2_mm_faultDescription_length = -1;
1313 static int hf_ptp_v2_mm_currentTime_s = -1;
1314 static int hf_ptp_v2_mm_currentTime_ns = -1;
1315 static int hf_ptp_v2_mm_clockAccuracy = -1;
1316 static int hf_ptp_v2_mm_priority1 = -1;
1317 static int hf_ptp_v2_mm_priority2 = -1;
1318 static int hf_ptp_v2_mm_dds_SO = -1;
1319 static int hf_ptp_v2_mm_TSC = -1;
1320 static int hf_ptp_v2_mm_numberPorts = -1;
1321 static int hf_ptp_v2_mm_clockclass = -1;
1322 static int hf_ptp_v2_mm_clockaccuracy = -1;
1323 static int hf_ptp_v2_mm_clockvariance = -1;
1324 static int hf_ptp_v2_mm_clockidentity = -1;
1325 static int hf_ptp_v2_mm_domainNumber = -1;
1326 static int hf_ptp_v2_mm_SO = -1;
1327 static int hf_ptp_v2_mm_stepsRemoved = -1;
1328 static int hf_ptp_v2_mm_parentIdentity = -1;
1329 static int hf_ptp_v2_mm_parentPort = -1;
1330 static int hf_ptp_v2_mm_parentStats = -1;
1331 static int hf_ptp_v2_mm_observedParentOffsetScaledLogVariance = -1;
1332 static int hf_ptp_v2_mm_observedParentClockPhaseChangeRate = -1;
1333 static int hf_ptp_v2_mm_grandmasterPriority1 = -1;
1334 static int hf_ptp_v2_mm_grandmasterPriority2 = -1;
1335 static int hf_ptp_v2_mm_grandmasterclockclass = -1;
1336 static int hf_ptp_v2_mm_grandmasterclockaccuracy = -1;
1337 static int hf_ptp_v2_mm_grandmasterclockvariance = -1;
1338 static int hf_ptp_v2_mm_grandmasterIdentity = -1;
1339 static int hf_ptp_v2_mm_currentUtcOffset = -1;
1340 static int hf_ptp_v2_mm_LI_61 = -1;
1341 static int hf_ptp_v2_mm_LI_59 = -1;
1342 static int hf_ptp_v2_mm_UTCV = -1;
1343 static int hf_ptp_v2_mm_PTP = -1;
1344 static int hf_ptp_v2_mm_TTRA = -1;
1345 static int hf_ptp_v2_mm_FTRA = -1;
1346 static int hf_ptp_v2_mm_timesource = -1;
1347 static int hf_ptp_v2_mm_offset_ns = -1;
1348 static int hf_ptp_v2_mm_pathDelay_ns = -1;
1349 static int hf_ptp_v2_mm_offset_subns = -1;
1350 static int hf_ptp_v2_mm_pathDelay_subns = -1;
1351 static int hf_ptp_v2_mm_PortNumber = -1;
1352 static int hf_ptp_v2_mm_portState = -1;
1353 static int hf_ptp_v2_mm_logMinDelayReqInterval = -1;
1354 static int hf_ptp_v2_mm_peerMeanPathDelay_ns = -1;
1355 static int hf_ptp_v2_mm_peerMeanPathDelay_subns = -1;
1356 static int hf_ptp_v2_mm_logAnnounceInterval = -1;
1357 static int hf_ptp_v2_mm_announceReceiptTimeout = -1;
1358 static int hf_ptp_v2_mm_logSyncInterval = -1;
1359 static int hf_ptp_v2_mm_delayMechanism = -1;
1360 static int hf_ptp_v2_mm_logMinPdelayReqInterval = -1;
1361 static int hf_ptp_v2_mm_versionNumber = -1;
1362 static int hf_ptp_v2_mm_primaryDomain = -1;
1363 static int hf_ptp_v2_mm_faultyFlag = -1;
1364 static int hf_ptp_v2_mm_managementErrorId = -1;
1365 static int hf_ptp_v2_mm_displayData = -1;
1366 static int hf_ptp_v2_mm_displayData_length = -1;
1367 static int hf_ptp_v2_mm_ucEN = -1;
1368 static int hf_ptp_v2_mm_ptEN = -1;
1369 static int hf_ptp_v2_mm_atEN = -1;
1370 static int hf_ptp_v2_mm_keyField = -1;
1371 static int hf_ptp_v2_mm_displayName = -1;
1372 static int hf_ptp_v2_mm_displayName_length = -1;
1373 static int hf_ptp_v2_mm_maxKey = -1;
1374 static int hf_ptp_v2_mm_currentOffset = -1;
1375 static int hf_ptp_v2_mm_jumpSeconds = -1;
1376 static int hf_ptp_v2_mm_logAlternateMulticastSyncInterval = -1;
1377 static int hf_ptp_v2_mm_numberOfAlternateMasters = -1;
1378 static int hf_ptp_v2_mm_transmitAlternateMulticastSync = -1;
1379
1380 /* Initialize the subtree pointers */
1381 static gint ett_ptp_v2 = -1;
1382 static gint ett_ptp_v2_flags = -1;
1383 static gint ett_ptp_v2_correction = -1;
1384 static gint ett_ptp_v2_time = -1;
1385 static gint ett_ptp_v2_time2 = -1;
1386 static gint ett_ptp_v2_managementData = -1;
1387 static gint ett_ptp_v2_clockType = -1;
1388 static gint ett_ptp_v2_physicalLayerProtocol = -1;
1389 static gint ett_ptp_v2_protocolAddress = -1;
1390 static gint ett_ptp_v2_faultRecord = -1;
1391 static gint ett_ptp_v2_ptptext = -1;
1392 static gint ett_ptp_v2_timeInterval = -1;
1393 static gint ett_ptp_v2_tlv = -1;
1394
1395 /* static gint ett_ptp_v2_timesource = -1;
1396 static gint ett_ptp_v2_priority = -1; */
1397 static gint ett_ptp_v2_transportspecific = -1;
1398
1399 /* For tronsport specific field  Ethernet or UDP */
1400 static gboolean ptpv2_oE = FALSE;
1401 /* END Definitions and fields for PTPv2 dissection. */
1402
1403
1404 /* forward declaration of local functions for v1 and v2 */
1405
1406 static void
1407 dissect_ptp_oE(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
1408
1409 static int
1410 is_ptp_v1(tvbuff_t *tvb);
1411
1412 static void
1413 dissect_ptp_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
1414
1415 static gboolean
1416 is_ptp_v2(tvbuff_t *tvb);
1417
1418 static void
1419 dissect_ptp_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
1420
1421 /**********************************************************/
1422 /* Implementation of the functions                                */
1423 /**********************************************************/
1424
1425
1426 /* Code to dissect the packet */
1427
1428 static void
1429 dissect_ptp_oE(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1430 {
1431         ptpv2_oE = TRUE;
1432         /* PTP over Ethernet only available with PTPv2 */
1433         dissect_ptp_v2(tvb, pinfo, tree);
1434 }
1435
1436 static void
1437 dissect_ptp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1438 {
1439         ptpv2_oE = FALSE;
1440         if(is_ptp_v1(tvb))
1441         dissect_ptp_v1(tvb, pinfo, tree);
1442     else if(is_ptp_v2(tvb))
1443         dissect_ptp_v2(tvb, pinfo, tree);
1444 }
1445
1446
1447 /* Code to check if packet is PTPv1 */
1448
1449 static gboolean
1450 is_ptp_v1(tvbuff_t *tvb)
1451 {
1452     guint16 version_ptp;
1453
1454     version_ptp = tvb_get_ntohs(tvb, PTP_VERSIONPTP_OFFSET);
1455
1456     if( version_ptp == 1) return TRUE;
1457     else return FALSE;
1458 }
1459
1460
1461 /* Code to check if packet is PTPv2 */
1462
1463 static gboolean
1464 is_ptp_v2(tvbuff_t *tvb)
1465 {
1466     guint8 version_ptp;
1467
1468     version_ptp = 0x0F & tvb_get_guint8(tvb, PTP_V2_VERSIONPTP_OFFSET);
1469
1470     if( version_ptp == 2) return TRUE;
1471     else return FALSE;
1472 }
1473
1474
1475 /* Code to actually dissect the PTPv1 packets */
1476
1477 static void
1478 dissect_ptp_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1479 {
1480     guint8      ptp_control, ptp_mm_messagekey = 0;
1481         nstime_t ts;    /*time structure with seconds and nanoseconds*/
1482
1483 /* Set up structures needed to add the protocol subtree and manage it */
1484         proto_item *ti, *flags_ti, *time_ti, *time2_ti;
1485         proto_tree *ptp_tree, *ptp_flags_tree, *ptp_time_tree, *ptp_time2_tree;
1486
1487 /* Make entries in Protocol column and Info column on summary display */
1488         col_set_str(pinfo->cinfo, COL_PROTOCOL, "PTPv1");
1489
1490
1491 /* Get control field (what kind of message is this? (Sync, DelayReq, ...) */
1492
1493         ptp_control = tvb_get_guint8 (tvb, PTP_CONTROL_OFFSET);
1494         /* MGMT packet? */
1495         if ( ptp_control == PTP_MANAGEMENT_MESSAGE ){
1496                 /* Get the managementMessageKey */
1497                         ptp_mm_messagekey = tvb_get_guint8(tvb, PTP_MM_MANAGEMENTMESSAGEKEY_OFFSET);
1498         }
1499
1500 /* Create and set the string for "Info" column */
1501         switch(ptp_control){
1502                 case PTP_SYNC_MESSAGE:{
1503                         col_set_str(pinfo->cinfo, COL_INFO, "Sync Message");
1504                         break;
1505                 }
1506                 case PTP_DELAY_REQ_MESSAGE:{
1507                         col_set_str(pinfo->cinfo, COL_INFO, "Delay_Request Message");
1508                         break;
1509                 }
1510                 case PTP_FOLLOWUP_MESSAGE:{
1511                         col_set_str(pinfo->cinfo, COL_INFO, "Follow_Up Message");
1512                         break;
1513                 }
1514                 case PTP_DELAY_RESP_MESSAGE:{
1515                         col_set_str(pinfo->cinfo, COL_INFO, "Delay_Response Message");
1516                         break;
1517                 }
1518                 case PTP_MANAGEMENT_MESSAGE:{
1519                         if (check_col(pinfo->cinfo, COL_INFO)){
1520                                 col_add_fstr(pinfo->cinfo, COL_INFO, "Management Message (%s)",
1521                                     val_to_str(ptp_mm_messagekey,
1522                                         ptp_managementMessageKey_infocolumn_vals,
1523                                         "Unknown message key %u"));
1524                         }
1525                         break;
1526                 }
1527                 default:{
1528                         col_set_str(pinfo->cinfo, COL_INFO, "Unknown Message");
1529                         break;
1530                 }
1531         }
1532
1533         if (tree) {
1534
1535                 /* create display subtree for the protocol */
1536                 ti = proto_tree_add_item(tree, proto_ptp, tvb, 0, -1, FALSE);
1537
1538                 ptp_tree = proto_item_add_subtree(ti, ett_ptp);
1539
1540                 proto_tree_add_item(ptp_tree,
1541                     hf_ptp_versionptp, tvb, PTP_VERSIONPTP_OFFSET, 2, FALSE);
1542
1543                 proto_tree_add_item(ptp_tree,
1544                     hf_ptp_versionnetwork, tvb, PTP_VERSIONNETWORK_OFFSET, 2, FALSE);
1545
1546                 proto_tree_add_item(ptp_tree,
1547                     hf_ptp_subdomain, tvb, PTP_SUBDOMAIN_OFFSET, 16, FALSE);
1548
1549                 proto_tree_add_item(ptp_tree,
1550                     hf_ptp_messagetype, tvb, PTP_MESSAGETYPE_OFFSET, 1, FALSE);
1551
1552                 proto_tree_add_item(ptp_tree,
1553                     hf_ptp_sourcecommunicationtechnology, tvb, PTP_SOURCECOMMUNICATIONTECHNOLOGY_OFFSET, 1, FALSE);
1554
1555                 proto_tree_add_item(ptp_tree,
1556                     hf_ptp_sourceuuid, tvb, PTP_SOURCEUUID_OFFSET, 6, FALSE);
1557
1558                 proto_tree_add_item(ptp_tree,
1559                     hf_ptp_sourceportid, tvb, PTP_SOURCEPORTID_OFFSET, 2, FALSE);
1560
1561                 proto_tree_add_item(ptp_tree,
1562                     hf_ptp_sequenceid, tvb, PTP_SEQUENCEID_OFFSET, 2, FALSE);
1563
1564                 proto_tree_add_item(ptp_tree,
1565                     hf_ptp_control, tvb, PTP_CONTROL_OFFSET, 1, FALSE);
1566
1567                 /*Subtree for the flag-field*/
1568                 if(tree){
1569                         flags_ti = proto_tree_add_item(ptp_tree,
1570                         hf_ptp_flags, tvb, PTP_FLAGS_OFFSET, 2, FALSE);
1571
1572                         ptp_flags_tree = proto_item_add_subtree(flags_ti, ett_ptp_flags);
1573
1574                         proto_tree_add_item(ptp_flags_tree,
1575                         hf_ptp_flags_li61, tvb, PTP_FLAGS_LI61_OFFSET, 2, FALSE);
1576
1577                         proto_tree_add_item(ptp_flags_tree,
1578                         hf_ptp_flags_li59, tvb, PTP_FLAGS_LI59_OFFSET, 2, FALSE);
1579
1580                         proto_tree_add_item(ptp_flags_tree,
1581                         hf_ptp_flags_boundary_clock, tvb, PTP_FLAGS_BOUNDARY_CLOCK_OFFSET, 2, FALSE);
1582
1583                         proto_tree_add_item(ptp_flags_tree,
1584                         hf_ptp_flags_assist, tvb, PTP_FLAGS_ASSIST_OFFSET, 2, FALSE);
1585
1586                         proto_tree_add_item(ptp_flags_tree,
1587                                 hf_ptp_flags_ext_sync, tvb, PTP_FLAGS_EXT_SYNC_OFFSET, 2, FALSE);
1588
1589                         proto_tree_add_item(ptp_flags_tree,
1590                         hf_ptp_flags_parent, tvb, PTP_FLAGS_PARENT_STATS_OFFSET, 2, FALSE);
1591
1592                         proto_tree_add_item(ptp_flags_tree,
1593                         hf_ptp_flags_sync_burst, tvb, PTP_FLAGS_SYNC_BURST_OFFSET, 2, FALSE);
1594                 }
1595
1596                 /* The rest of the ptp-dissector depends on the control-field  */
1597
1598                 switch(ptp_control){
1599                         case PTP_SYNC_MESSAGE:
1600                         case PTP_DELAY_REQ_MESSAGE:{
1601
1602                         /*Subtree for the timestamp-field*/
1603                         ts.secs = tvb_get_ntohl(tvb, PTP_SDR_ORIGINTIMESTAMP_SECONDS_OFFSET);
1604                         ts.nsecs =  tvb_get_ntohl(tvb, PTP_SDR_ORIGINTIMESTAMP_NANOSECONDS_OFFSET);
1605                         if(tree){
1606                                 time_ti = proto_tree_add_time(ptp_tree,
1607                                 hf_ptp_sdr_origintimestamp, tvb, PTP_SDR_ORIGINTIMESTAMP_OFFSET, 8, &ts);
1608
1609                                 ptp_time_tree = proto_item_add_subtree(time_ti, ett_ptp_time);
1610
1611                                 proto_tree_add_item(ptp_time_tree,
1612                                                 hf_ptp_sdr_origintimestamp_seconds, tvb,
1613                                                 PTP_SDR_ORIGINTIMESTAMP_SECONDS_OFFSET, 4, FALSE);
1614
1615                                         proto_tree_add_item(ptp_time_tree, hf_ptp_sdr_origintimestamp_nanoseconds, tvb,
1616                                                         PTP_SDR_ORIGINTIMESTAMP_NANOSECONDS_OFFSET, 4, FALSE);
1617                                 }
1618
1619                                 proto_tree_add_item(ptp_tree,
1620                                                 hf_ptp_sdr_epochnumber, tvb, PTP_SDR_EPOCHNUMBER_OFFSET, 2, FALSE);
1621
1622                                 proto_tree_add_item(ptp_tree,
1623                                     hf_ptp_sdr_currentutcoffset, tvb, PTP_SDR_CURRENTUTCOFFSET_OFFSET, 2, FALSE);
1624
1625                                 proto_tree_add_item(ptp_tree, hf_ptp_sdr_grandmastercommunicationtechnology, tvb,
1626                                                 PTP_SDR_GRANDMASTERCOMMUNICATIONTECHNOLOGY_OFFSET, 1, FALSE);
1627
1628                                 proto_tree_add_item(ptp_tree,
1629                                     hf_ptp_sdr_grandmasterclockuuid, tvb, PTP_SDR_GRANDMASTERCLOCKUUID_OFFSET, 6, FALSE);
1630
1631                                 proto_tree_add_item(ptp_tree,
1632                                     hf_ptp_sdr_grandmasterportid, tvb, PTP_SDR_GRANDMASTERPORTID_OFFSET, 2, FALSE);
1633
1634                                 proto_tree_add_item(ptp_tree,
1635                                     hf_ptp_sdr_grandmastersequenceid, tvb, PTP_SDR_GRANDMASTERSEQUENCEID_OFFSET, 2, FALSE);
1636
1637                                 proto_tree_add_item(ptp_tree,
1638                                     hf_ptp_sdr_grandmasterclockstratum, tvb,
1639                                                 PTP_SDR_GRANDMASTERCLOCKSTRATUM_OFFSET, 1, FALSE);
1640
1641                                 proto_tree_add_item(ptp_tree, hf_ptp_sdr_grandmasterclockidentifier, tvb,
1642                                                 PTP_SDR_GRANDMASTERCLOCKIDENTIFIER_OFFSET, 4, FALSE);
1643
1644                                 proto_tree_add_item(ptp_tree,
1645                                     hf_ptp_sdr_grandmasterclockvariance, tvb,
1646                                                 PTP_SDR_GRANDMASTERCLOCKVARIANCE_OFFSET, 2, FALSE);
1647
1648                                 proto_tree_add_item(ptp_tree,
1649                                     hf_ptp_sdr_grandmasterpreferred, tvb, PTP_SDR_GRANDMASTERPREFERRED_OFFSET, 1, FALSE);
1650
1651                                 proto_tree_add_item(ptp_tree, hf_ptp_sdr_grandmasterisboundaryclock, tvb,
1652                                                 PTP_SDR_GRANDMASTERISBOUNDARYCLOCK_OFFSET, 1, FALSE);
1653
1654                                 proto_tree_add_item(ptp_tree,
1655                                     hf_ptp_sdr_syncinterval, tvb, PTP_SDR_SYNCINTERVAL_OFFSET, 1, FALSE);
1656
1657                                 proto_tree_add_item(ptp_tree,
1658                                     hf_ptp_sdr_localclockvariance, tvb, PTP_SDR_LOCALCLOCKVARIANCE_OFFSET, 2, FALSE);
1659
1660                                 proto_tree_add_item(ptp_tree,
1661                                     hf_ptp_sdr_localstepsremoved, tvb, PTP_SDR_LOCALSTEPSREMOVED_OFFSET, 2, FALSE);
1662
1663                                 proto_tree_add_item(ptp_tree,
1664                                     hf_ptp_sdr_localclockstratum, tvb, PTP_SDR_LOCALCLOCKSTRATUM_OFFSET, 1, FALSE);
1665
1666                                 proto_tree_add_item(ptp_tree,
1667                                     hf_ptp_sdr_localclockidentifier, tvb, PTP_SDR_LOCALCLOCKIDENTIFIER_OFFSET, 4, FALSE);
1668
1669                                 proto_tree_add_item(ptp_tree, hf_ptp_sdr_parentcommunicationtechnology, tvb,
1670                                                 PTP_SDR_PARENTCOMMUNICATIONTECHNOLOGY_OFFSET, 1, FALSE);
1671
1672                                 proto_tree_add_item(ptp_tree,
1673                                     hf_ptp_sdr_parentuuid, tvb, PTP_SDR_PARENTUUID_OFFSET, 6, FALSE);
1674
1675                                 proto_tree_add_item(ptp_tree,
1676                                     hf_ptp_sdr_parentportfield, tvb, PTP_SDR_PARENTPORTFIELD_OFFSET, 2, FALSE);
1677
1678                                 proto_tree_add_item(ptp_tree,
1679                                     hf_ptp_sdr_estimatedmastervariance, tvb,
1680                                                 PTP_SDR_ESTIMATEDMASTERVARIANCE_OFFSET, 2, FALSE);
1681
1682                                 proto_tree_add_item(ptp_tree,
1683                                     hf_ptp_sdr_estimatedmasterdrift, tvb, PTP_SDR_ESTIMATEDMASTERDRIFT_OFFSET, 4, FALSE);
1684
1685                                 proto_tree_add_item(ptp_tree,
1686                                     hf_ptp_sdr_utcreasonable, tvb, PTP_SDR_UTCREASONABLE_OFFSET, 1, FALSE);
1687                                 break;
1688                         }
1689                         case PTP_FOLLOWUP_MESSAGE:{
1690                                 proto_tree_add_item(ptp_tree,
1691                                     hf_ptp_fu_associatedsequenceid, tvb, PTP_FU_ASSOCIATEDSEQUENCEID_OFFSET, 2, FALSE);
1692
1693                                 /*Subtree for the timestamp-field*/
1694                                 ts.secs = tvb_get_ntohl(tvb, PTP_FU_PRECISEORIGINTIMESTAMP_SECONDS_OFFSET);
1695                                 ts.nsecs = tvb_get_ntohl(tvb, PTP_FU_PRECISEORIGINTIMESTAMP_NANOSECONDS_OFFSET);
1696                                 if(tree){
1697                                         time_ti = proto_tree_add_time(ptp_tree,
1698                                                 hf_ptp_fu_preciseorigintimestamp, tvb,
1699                                                         PTP_FU_PRECISEORIGINTIMESTAMP_OFFSET, 8, &ts);
1700
1701                                         ptp_time_tree = proto_item_add_subtree(time_ti, ett_ptp_time);
1702
1703                                         proto_tree_add_item(ptp_time_tree, hf_ptp_fu_preciseorigintimestamp_seconds, tvb,
1704                                                         PTP_FU_PRECISEORIGINTIMESTAMP_SECONDS_OFFSET, 4, FALSE);
1705
1706                                         proto_tree_add_item(ptp_time_tree, hf_ptp_fu_preciseorigintimestamp_nanoseconds, tvb,
1707                                                         PTP_FU_PRECISEORIGINTIMESTAMP_NANOSECONDS_OFFSET, 4, FALSE);
1708                                 }
1709                                 break;
1710                         }
1711                         case PTP_DELAY_RESP_MESSAGE:{
1712                                 /*Subtree for the timestamp-field*/
1713                                 ts.secs = tvb_get_ntohl(tvb, PTP_DR_DELAYRECEIPTTIMESTAMP_SECONDS_OFFSET);
1714                                 ts.nsecs = tvb_get_ntohl(tvb, PTP_DR_DELAYRECEIPTTIMESTAMP_NANOSECONDS_OFFSET);
1715                                 if(tree){
1716                                         time_ti = proto_tree_add_time(ptp_tree,
1717                                                 hf_ptp_dr_delayreceipttimestamp, tvb,
1718                                                         PTP_DR_DELAYRECEIPTTIMESTAMP_OFFSET, 8, &ts);
1719
1720                                         ptp_time_tree = proto_item_add_subtree(time_ti, ett_ptp_time);
1721
1722                                         proto_tree_add_item(ptp_time_tree, hf_ptp_dr_delayreceipttimestamp_seconds, tvb,
1723                                                         PTP_DR_DELAYRECEIPTTIMESTAMP_SECONDS_OFFSET, 4, FALSE);
1724
1725                                         proto_tree_add_item(ptp_time_tree, hf_ptp_dr_delayreceipttimestamp_nanoseconds, tvb,
1726                                                         PTP_DR_DELAYRECEIPTTIMESTAMP_NANOSECONDS_OFFSET, 4, FALSE);
1727                                 }
1728
1729                                 proto_tree_add_item(ptp_tree, hf_ptp_dr_requestingsourcecommunicationtechnology, tvb,
1730                                         PTP_DR_REQUESTINGSOURCECOMMUNICATIONTECHNOLOGY_OFFSET, 1, FALSE);
1731
1732                                 proto_tree_add_item(ptp_tree,
1733                                     hf_ptp_dr_requestingsourceuuid, tvb, PTP_DR_REQUESTINGSOURCEUUID_OFFSET, 6, FALSE);
1734
1735                                 proto_tree_add_item(ptp_tree,
1736                                     hf_ptp_dr_requestingsourceportid, tvb, PTP_DR_REQUESTINGSOURCEPORTID_OFFSET, 2, FALSE);
1737
1738                                 proto_tree_add_item(ptp_tree,
1739                                     hf_ptp_dr_requestingsourcesequenceid, tvb,
1740                                                 PTP_DR_REQUESTINGSOURCESEQUENCEID_OFFSET, 2, FALSE);
1741                                 break;
1742                         }
1743                         case PTP_MANAGEMENT_MESSAGE:{
1744                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_targetcommunicationtechnology, tvb,
1745                                                 PTP_MM_TARGETCOMMUNICATIONTECHNOLOGY_OFFSET, 1, FALSE);
1746
1747                                 proto_tree_add_item(ptp_tree,
1748                                     hf_ptp_mm_targetuuid, tvb, PTP_MM_TARGETUUID_OFFSET, 6, FALSE);
1749
1750                                 proto_tree_add_item(ptp_tree,
1751                                     hf_ptp_mm_targetportid, tvb, PTP_MM_TARGETPORTID_OFFSET, 2, FALSE);
1752
1753                                 proto_tree_add_item(ptp_tree,
1754                                     hf_ptp_mm_startingboundaryhops, tvb, PTP_MM_STARTINGBOUNDARYHOPS_OFFSET, 2, FALSE);
1755
1756                                 proto_tree_add_item(ptp_tree,
1757                                     hf_ptp_mm_boundaryhops, tvb, PTP_MM_BOUNDARYHOPS_OFFSET, 2, FALSE);
1758
1759
1760                                 proto_tree_add_item(ptp_tree,
1761                                     hf_ptp_mm_managementmessagekey, tvb, PTP_MM_MANAGEMENTMESSAGEKEY_OFFSET, 1, FALSE);
1762
1763                                 proto_tree_add_item(ptp_tree,
1764                                     hf_ptp_mm_parameterlength, tvb, PTP_MM_PARAMETERLENGTH_OFFSET, 2, FALSE);
1765
1766                                 switch(ptp_mm_messagekey){
1767                                         case PTP_MM_CLOCK_IDENTITY:{
1768                                                 proto_tree_add_item(ptp_tree,
1769                                                                 hf_ptp_mm_clock_identity_clockcommunicationtechnology, tvb,
1770                                                                 PTP_MM_CLOCK_IDENTITY_CLOCKCOMMUNICATIONTECHNOLOGY_OFFSET, 1, FALSE);
1771
1772                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_clock_identity_clockuuidfield, tvb,
1773                                                                 PTP_MM_CLOCK_IDENTITY_CLOCKUUIDFIELD_OFFSET, 6, FALSE);
1774
1775                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_clock_identity_clockportfield, tvb,
1776                                                                 PTP_MM_CLOCK_IDENTITY_CLOCKPORTFIELD_OFFSET, 2, FALSE);
1777
1778                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_clock_identity_manufactureridentity, tvb,
1779                                                                 PTP_MM_CLOCK_IDENTITY_MANUFACTURERIDENTITY_OFFSET, 48, FALSE);
1780                                                 break;
1781                                         }
1782                                         case PTP_MM_INITIALIZE_CLOCK:{
1783                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_initialize_clock_initialisationkey, tvb,
1784                                                         PTP_MM_INITIALIZE_CLOCK_INITIALISATIONKEY_OFFSET, 2, FALSE);
1785                                                 break;
1786                                         }
1787                                         case PTP_MM_SET_SUBDOMAIN:{
1788                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_set_subdomain_subdomainname, tvb,
1789                                                                 PTP_MM_SET_SUBDOMAIN_SUBDOMAINNAME_OFFSET, 16, FALSE);
1790                                                 break;
1791                                         }
1792                                         case PTP_MM_DEFAULT_DATA_SET:{
1793                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_clockcommunicationtechnology,
1794                                                                 tvb, PTP_MM_DEFAULT_DATA_SET_CLOCKCOMMUNICATIONTECHNOLOGY_OFFSET,
1795                                                                  1, FALSE);
1796
1797                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_clockuuidfield, tvb,
1798                                                                 PTP_MM_DEFAULT_DATA_SET_CLOCKUUIDFIELD_OFFSET, 6, FALSE);
1799
1800                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_clockportfield, tvb,
1801                                                                 PTP_MM_DEFAULT_DATA_SET_CLOCKPORTFIELD_OFFSET, 2, FALSE);
1802
1803                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_clockstratum, tvb,
1804                                                                 PTP_MM_DEFAULT_DATA_SET_CLOCKSTRATUM_OFFSET, 1, FALSE);
1805
1806                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_clockidentifier, tvb,
1807                                                                 PTP_MM_DEFAULT_DATA_SET_CLOCKIDENTIFIER_OFFSET, 4, FALSE);
1808
1809                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_clockvariance, tvb,
1810                                                                 PTP_MM_DEFAULT_DATA_SET_CLOCKVARIANCE_OFFSET, 2, FALSE);
1811
1812                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_clockfollowupcapable, tvb,
1813                                                                 PTP_MM_DEFAULT_DATA_SET_CLOCKFOLLOWUPCAPABLE_OFFSET, 1, FALSE);
1814
1815                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_preferred, tvb,
1816                                                                 PTP_MM_DEFAULT_DATA_SET_PREFERRED_OFFSET, 1, FALSE);
1817
1818                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_initializable, tvb,
1819                                                                 PTP_MM_DEFAULT_DATA_SET_INITIALIZABLE_OFFSET, 1, FALSE);
1820
1821                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_externaltiming, tvb,
1822                                                                 PTP_MM_DEFAULT_DATA_SET_EXTERNALTIMING_OFFSET, 1, FALSE);
1823
1824                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_isboundaryclock, tvb,
1825                                                                 PTP_MM_DEFAULT_DATA_SET_ISBOUNDARYCLOCK_OFFSET, 1, FALSE);
1826
1827                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_syncinterval, tvb,
1828                                                                 PTP_MM_DEFAULT_DATA_SET_SYNCINTERVAL_OFFSET, 1, FALSE);
1829
1830                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_subdomainname, tvb,
1831                                                                 PTP_MM_DEFAULT_DATA_SET_SUBDOMAINNAME_OFFSET, 16, FALSE);
1832
1833                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_numberports, tvb,
1834                                                                 PTP_MM_DEFAULT_DATA_SET_NUMBERPORTS_OFFSET, 2, FALSE);
1835
1836                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_default_data_set_numberforeignrecords, tvb,
1837                                                                 PTP_MM_DEFAULT_DATA_SET_NUMBERFOREIGNRECORDS_OFFSET, 2, FALSE);
1838                                                 break;
1839                                         }
1840                                         case PTP_MM_UPDATE_DEFAULT_DATA_SET:{
1841                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_update_default_data_set_clockstratum, tvb,
1842                                                                 PTP_MM_UPDATE_DEFAULT_DATA_SET_CLOCKSTRATUM_OFFSET, 1, FALSE);
1843
1844                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_update_default_data_set_clockidentifier, tvb,
1845                                                                 PTP_MM_UPDATE_DEFAULT_DATA_SET_CLOCKIDENTIFIER_OFFSET, 4, FALSE);
1846
1847                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_update_default_data_set_clockvariance, tvb,
1848                                                                 PTP_MM_UPDATE_DEFAULT_DATA_SET_CLOCKVARIANCE_OFFSET, 2, FALSE);
1849
1850                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_update_default_data_set_preferred, tvb,
1851                                                                 PTP_MM_UPDATE_DEFAULT_DATA_SET_PREFERRED_OFFSET, 1, FALSE);
1852
1853                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_update_default_data_set_syncinterval, tvb,
1854                                                                 PTP_MM_UPDATE_DEFAULT_DATA_SET_SYNCINTERVAL_OFFSET, 1, FALSE);
1855
1856                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_update_default_data_set_subdomainname, tvb,
1857                                                                 PTP_MM_UPDATE_DEFAULT_DATA_SET_SUBDOMAINNAME_OFFSET, 16, FALSE);
1858                                                 break;
1859                                         }
1860                                         case PTP_MM_CURRENT_DATA_SET:{
1861                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_current_data_set_stepsremoved, tvb,
1862                                                                 PTP_MM_CURRENT_DATA_SET_STEPSREMOVED_OFFSET, 2, FALSE);
1863
1864                                                 /* Subtree for offset from master*/
1865                                                 ts.secs = tvb_get_ntohl(tvb, PTP_MM_CURRENT_DATA_SET_OFFSETFROMMASTERSECONDS_OFFSET);
1866
1867                                                 ts.nsecs = tvb_get_ntohl(tvb,
1868                                                                 PTP_MM_CURRENT_DATA_SET_OFFSETFROMMASTERNANOSECONDS_OFFSET);
1869
1870                                                 if (ts.nsecs & 0x80000000) ts.nsecs = ts.nsecs & 0x7FFFFFFF;
1871
1872                                                 if(tree){
1873                                                         time_ti = proto_tree_add_time(ptp_tree,
1874                                                                         hf_ptp_mm_current_data_set_offsetfrommaster, tvb,
1875                                                                         PTP_MM_CURRENT_DATA_SET_OFFSETFROMMASTER_OFFSET, 8, &ts);
1876
1877                                                         ptp_time_tree = proto_item_add_subtree(time_ti, ett_ptp_time);
1878
1879                                                         proto_tree_add_item(ptp_time_tree,
1880                                                                         hf_ptp_mm_current_data_set_offsetfrommasterseconds, tvb,
1881                                                                         PTP_MM_CURRENT_DATA_SET_OFFSETFROMMASTERSECONDS_OFFSET, 4, FALSE);
1882
1883                                                         proto_tree_add_item(ptp_time_tree,
1884                                                                         hf_ptp_mm_current_data_set_offsetfrommasternanoseconds, tvb,
1885                                                                         PTP_MM_CURRENT_DATA_SET_OFFSETFROMMASTERNANOSECONDS_OFFSET, 4, FALSE);
1886                                                 }
1887
1888                                                 /* Subtree for offset from master*/
1889                                                 ts.secs = tvb_get_ntohl(tvb, PTP_MM_CURRENT_DATA_SET_ONEWAYDELAYSECONDS_OFFSET);
1890
1891                                                 ts.nsecs = tvb_get_ntohl(tvb, PTP_MM_CURRENT_DATA_SET_ONEWAYDELAYNANOSECONDS_OFFSET);
1892
1893                                                 if(tree){
1894                                                         time2_ti = proto_tree_add_time(ptp_tree,
1895                                                                         hf_ptp_mm_current_data_set_onewaydelay, tvb,
1896                                                                         PTP_MM_CURRENT_DATA_SET_ONEWAYDELAY_OFFSET, 8, &ts);
1897
1898                                                         ptp_time2_tree = proto_item_add_subtree(time2_ti, ett_ptp_time2);
1899
1900                                                         proto_tree_add_item(ptp_time2_tree, hf_ptp_mm_current_data_set_onewaydelayseconds,
1901                                                                         tvb, PTP_MM_CURRENT_DATA_SET_ONEWAYDELAYSECONDS_OFFSET, 4, FALSE);
1902
1903                                                         proto_tree_add_item(ptp_time2_tree,
1904                                                                         hf_ptp_mm_current_data_set_onewaydelaynanoseconds,
1905                                                                         tvb, PTP_MM_CURRENT_DATA_SET_ONEWAYDELAYNANOSECONDS_OFFSET, 4, FALSE);
1906                                                 }
1907                                                 break;
1908                                         }
1909                                         case PTP_MM_PARENT_DATA_SET:{
1910                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_parentcommunicationtechnology,
1911                                                                 tvb, PTP_MM_PARENT_DATA_SET_PARENTCOMMUNICATIONTECHNOLOGY_OFFSET,
1912                                                                 1, FALSE);
1913
1914                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_parentuuid, tvb,
1915                                                                 PTP_MM_PARENT_DATA_SET_PARENTUUID_OFFSET, 6, FALSE);
1916
1917                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_parentportid, tvb,
1918                                                                 PTP_MM_PARENT_DATA_SET_PARENTPORTID_OFFSET, 2, FALSE);
1919
1920                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_parentlastsyncsequencenumber,
1921                                                                 tvb, PTP_MM_PARENT_DATA_SET_PARENTLASTSYNCSEQUENCENUMBER_OFFSET,
1922                                                                 2, FALSE);
1923
1924                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_parentfollowupcapable, tvb,
1925                                                                 PTP_MM_PARENT_DATA_SET_PARENTFOLLOWUPCAPABLE_OFFSET, 1, FALSE);
1926
1927                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_parentexternaltiming, tvb,
1928                                                                 PTP_MM_PARENT_DATA_SET_PARENTEXTERNALTIMING_OFFSET, 1, FALSE);
1929
1930                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_parentvariance, tvb,
1931                                                                 PTP_MM_PARENT_DATA_SET_PARENTVARIANCE_OFFSET, 2, FALSE);
1932
1933                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_parentstats, tvb,
1934                                                                 PTP_MM_PARENT_DATA_SET_PARENTSTATS_OFFSET, 1, FALSE);
1935
1936                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_observedvariance, tvb,
1937                                                                 PTP_MM_PARENT_DATA_SET_OBSERVEDVARIANCE_OFFSET, 2, FALSE);
1938
1939                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_observeddrift, tvb,
1940                                                                 PTP_MM_PARENT_DATA_SET_OBSERVEDDRIFT_OFFSET, 4, FALSE);
1941
1942                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_utcreasonable, tvb,
1943                                                                 PTP_MM_PARENT_DATA_SET_UTCREASONABLE_OFFSET, 1, FALSE);
1944
1945                                                 proto_tree_add_item(ptp_tree,
1946                                                                 hf_ptp_mm_parent_data_set_grandmastercommunicationtechnology,
1947                                                                 tvb, PTP_MM_PARENT_DATA_SET_GRANDMASTERCOMMUNICATIONTECHNOLOGY_OFFSET, 1,
1948                                                                 FALSE);
1949
1950                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_grandmasteruuidfield, tvb,
1951                                                                 PTP_MM_PARENT_DATA_SET_GRANDMASTERUUIDFIELD_OFFSET, 6, FALSE);
1952
1953                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_grandmasterportidfield, tvb,
1954                                                                 PTP_MM_PARENT_DATA_SET_GRANDMASTERPORTIDFIELD_OFFSET, 2, FALSE);
1955
1956                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_grandmasterstratum, tvb,
1957                                                                 PTP_MM_PARENT_DATA_SET_GRANDMASTERSTRATUM_OFFSET, 1, FALSE);
1958
1959                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_grandmasteridentifier, tvb,
1960                                                                 PTP_MM_PARENT_DATA_SET_GRANDMASTERIDENTIFIER_OFFSET, 4, FALSE);
1961
1962                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_grandmastervariance, tvb,
1963                                                                 PTP_MM_PARENT_DATA_SET_GRANDMASTERVARIANCE_OFFSET, 2, FALSE);
1964
1965                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_grandmasterpreferred, tvb,
1966                                                                 PTP_MM_PARENT_DATA_SET_GRANDMASTERPREFERRED_OFFSET, 1, FALSE);
1967
1968                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_grandmasterisboundaryclock, tvb,
1969                                                                 PTP_MM_PARENT_DATA_SET_GRANDMASTERISBOUNDARYCLOCK_OFFSET, 1, FALSE);
1970
1971                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_parent_data_set_grandmastersequencenumber, tvb,
1972                                                                 PTP_MM_PARENT_DATA_SET_GRANDMASTERSEQUENCENUMBER_OFFSET, 2, FALSE);
1973                                                 break;
1974                                         }
1975                                         case PTP_MM_PORT_DATA_SET:{
1976                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_returnedportnumber, tvb,
1977                                                                 PTP_MM_PORT_DATA_SET_RETURNEDPORTNUMBER_OFFSET, 2, FALSE);
1978
1979                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_portstate, tvb,
1980                                                                 PTP_MM_PORT_DATA_SET_PORTSTATE_OFFSET, 1, FALSE);
1981
1982                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_lastsynceventsequencenumber, tvb,
1983                                                                 PTP_MM_PORT_DATA_SET_LASTSYNCEVENTSEQUENCENUMBER_OFFSET, 2, FALSE);
1984
1985                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_lastgeneraleventsequencenumber,
1986                                                                 tvb, PTP_MM_PORT_DATA_SET_LASTGENERALEVENTSEQUENCENUMBER_OFFSET,
1987                                                                 2, FALSE);
1988
1989                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_portcommunicationtechnology, tvb,
1990                                                                 PTP_MM_PORT_DATA_SET_PORTCOMMUNICATIONTECHNOLOGY_OFFSET, 1, FALSE);
1991
1992                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_portuuidfield, tvb,
1993                                                                 PTP_MM_PORT_DATA_SET_PORTUUIDFIELD_OFFSET, 6, FALSE);
1994
1995                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_portidfield, tvb,
1996                                                                 PTP_MM_PORT_DATA_SET_PORTIDFIELD_OFFSET, 2, FALSE);
1997
1998                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_burstenabled, tvb,
1999                                                                 PTP_MM_PORT_DATA_SET_BURSTENABLED_OFFSET, 1, FALSE);
2000
2001                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_subdomainaddressoctets, tvb,
2002                                                                 PTP_MM_PORT_DATA_SET_SUBDOMAINADDRESSOCTETS_OFFSET, 1, FALSE);
2003
2004                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_eventportaddressoctets, tvb,
2005                                                                 PTP_MM_PORT_DATA_SET_EVENTPORTADDRESSOCTETS_OFFSET, 1, FALSE);
2006
2007                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_generalportaddressoctets, tvb,
2008                                                                 PTP_MM_PORT_DATA_SET_GENERALPORTADDRESSOCTETS_OFFSET, 1, FALSE);
2009
2010                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_subdomainaddress, tvb,
2011                                                                 PTP_MM_PORT_DATA_SET_SUBDOMAINADDRESS_OFFSET, 4, FALSE);
2012
2013                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_eventportaddress, tvb,
2014                                                                 PTP_MM_PORT_DATA_SET_EVENTPORTADDRESS_OFFSET, 2, FALSE);
2015
2016                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_port_data_set_generalportaddress, tvb,
2017                                                                 PTP_MM_PORT_DATA_SET_GENERALPORTADDRESS_OFFSET, 2, FALSE);
2018                                                 break;
2019                                         }
2020                                         case PTP_MM_GLOBAL_TIME_DATA_SET:{
2021                                                 /* Subtree for local time*/
2022                                                 ts.secs = tvb_get_ntohl(tvb, PTP_MM_GLOBAL_TIME_DATA_SET_LOCALTIMESECONDS_OFFSET);
2023
2024                                                 ts.nsecs = tvb_get_ntohl(tvb,
2025                                                                 PTP_MM_GLOBAL_TIME_DATA_SET_LOCALTIMENANOSECONDS_OFFSET);
2026
2027                                                 if(tree){
2028                                                         time_ti = proto_tree_add_time(ptp_tree,
2029                                                                         hf_ptp_mm_global_time_data_set_localtime, tvb,
2030                                                                         PTP_MM_GLOBAL_TIME_DATA_SET_LOCALTIME_OFFSET, 8, &ts);
2031
2032                                                         ptp_time_tree = proto_item_add_subtree(time_ti, ett_ptp_time);
2033
2034                                                         proto_tree_add_item(ptp_time_tree,
2035                                                                         hf_ptp_mm_global_time_data_set_localtimeseconds, tvb,
2036                                                                         PTP_MM_GLOBAL_TIME_DATA_SET_LOCALTIMESECONDS_OFFSET, 4, FALSE);
2037
2038                                                         proto_tree_add_item(ptp_time_tree,
2039                                                                         hf_ptp_mm_global_time_data_set_localtimenanoseconds,
2040                                                                         tvb, PTP_MM_GLOBAL_TIME_DATA_SET_LOCALTIMENANOSECONDS_OFFSET, 4, FALSE);
2041                                                 }
2042
2043                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_global_time_data_set_currentutcoffset, tvb,
2044                                                                 PTP_MM_GLOBAL_TIME_DATA_SET_CURRENTUTCOFFSET_OFFSET, 2, FALSE);
2045
2046                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_global_time_data_set_leap59, tvb,
2047                                                                 PTP_MM_GLOBAL_TIME_DATA_SET_LEAP59_OFFSET, 1, FALSE);
2048
2049                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_global_time_data_set_leap61, tvb,
2050                                                                 PTP_MM_GLOBAL_TIME_DATA_SET_LEAP61_OFFSET, 1, FALSE);
2051
2052                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_global_time_data_set_epochnumber, tvb,
2053                                                                 PTP_MM_GLOBAL_TIME_DATA_SET_EPOCHNUMBER_OFFSET, 2, FALSE);
2054                                                 break;
2055                                         }
2056                                         case PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES:{
2057                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_update_global_time_properties_currentutcoffset,
2058                                                                 tvb, PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES_CURRENTUTCOFFSET_OFFSET,
2059                                                                 2, FALSE);
2060
2061                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_update_global_time_properties_leap59, tvb,
2062                                                                 PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES_LEAP59_OFFSET, 1, FALSE);
2063
2064                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_update_global_time_properties_leap61, tvb,
2065                                                                 PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES_LEAP61_OFFSET, 1, FALSE);
2066
2067                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_get_foreign_data_set_recordkey, tvb,
2068                                                                 PTP_MM_UPDATE_GLOBAL_TIME_PROPERTIES_EPOCHNUMBER_OFFSET, 2, FALSE);
2069                                                 break;
2070                                         }
2071                                         case PTP_MM_GET_FOREIGN_DATA_SET:{
2072                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_get_foreign_data_set_recordkey, tvb,
2073                                                                 PTP_MM_GET_FOREIGN_DATA_SET_RECORDKEY_OFFSET, 2, FALSE);
2074                                                 break;
2075                                         }
2076                                         case PTP_MM_FOREIGN_DATA_SET:{
2077                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_foreign_data_set_returnedportnumber, tvb,
2078                                                                 PTP_MM_FOREIGN_DATA_SET_RETURNEDPORTNUMBER_OFFSET, 2, FALSE);
2079
2080                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_foreign_data_set_returnedrecordnumber, tvb,
2081                                                                 PTP_MM_FOREIGN_DATA_SET_RETURNEDRECORDNUMBER_OFFSET, 2, FALSE);
2082
2083                                                 proto_tree_add_item(ptp_tree,
2084                                                                 hf_ptp_mm_foreign_data_set_foreignmastercommunicationtechnology,
2085                                                                 tvb, PTP_MM_FOREIGN_DATA_SET_FOREIGNMASTERCOMMUNICATIONTECHNOLOGY_OFFSET, 1,
2086                                                                 FALSE);
2087
2088                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_foreign_data_set_foreignmasteruuidfield, tvb,
2089                                                                 PTP_MM_FOREIGN_DATA_SET_FOREIGNMASTERUUIDFIELD_OFFSET, 6, FALSE);
2090
2091                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_foreign_data_set_foreignmasterportidfield, tvb,
2092                                                                 PTP_MM_FOREIGN_DATA_SET_FOREIGNMASTERPORTIDFIELD_OFFSET, 2, FALSE);
2093
2094                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_foreign_data_set_foreignmastersyncs, tvb,
2095                                                                 PTP_MM_FOREIGN_DATA_SET_FOREIGNMASTERSYNCS_OFFSET, 2, FALSE);
2096                                                 break;
2097                                         }
2098                                         case PTP_MM_SET_SYNC_INTERVAL:{
2099                                                 proto_tree_add_item(ptp_tree, hf_ptp_mm_set_sync_interval_syncinterval, tvb,
2100                                                                 PTP_MM_SET_SYNC_INTERVAL_SYNCINTERVAL_OFFSET, 2, FALSE);
2101                                                 break;
2102                                         }
2103                                         case PTP_MM_SET_TIME:{
2104                                                 /* Subtree for local time*/
2105                                                 ts.secs = tvb_get_ntohl(tvb, PTP_MM_SET_TIME_LOCALTIMESECONDS_OFFSET);
2106
2107                                                 ts.nsecs = tvb_get_ntohl(tvb, PTP_MM_SET_TIME_LOCALTIMENANOSECONDS_OFFSET);
2108
2109                                                 if(tree){
2110                                                         time_ti = proto_tree_add_time(ptp_tree, hf_ptp_mm_set_time_localtime, tvb,
2111                                                                         PTP_MM_SET_TIME_LOCALTIME_OFFSET, 8, &ts);
2112
2113                                                         ptp_time_tree = proto_item_add_subtree(time_ti, ett_ptp_time);
2114
2115                                                         proto_tree_add_item(ptp_time_tree, hf_ptp_mm_set_time_localtimeseconds, tvb,
2116                                                                         PTP_MM_SET_TIME_LOCALTIMESECONDS_OFFSET, 4, FALSE);
2117
2118                                                         proto_tree_add_item(ptp_time_tree, hf_ptp_mm_set_time_localtimenanoseconds,
2119                                                                         tvb, PTP_MM_SET_TIME_LOCALTIMENANOSECONDS_OFFSET, 4, FALSE);
2120                                                 }
2121                                                 break;
2122                                         }
2123                                         default :{
2124                                                 /*- don't dissect any further. */
2125                                                 break;
2126                                         }
2127                                 }
2128                                 break;
2129                         }
2130                         default :{
2131                                 /* Not a valid MessageType - can't dissect. */
2132                                 break;
2133                         }
2134                 }
2135         }
2136 }
2137
2138
2139 /* Code to dissect PTPText */
2140 static void
2141 dissect_ptp_v2_text(tvbuff_t *tvb, guint16 *cur_offset, proto_tree *tree, int hf_ptp_v2_mm_ptptext, int hf_ptp_v2_mm_ptptext_length)
2142 {
2143         guint8  length = 0;
2144         proto_item      *ptptext_ti;
2145         proto_tree      *ptptext_subtree;
2146
2147         length = tvb_get_guint8 (tvb, *cur_offset);
2148
2149         if (tree)
2150         {
2151                 ptptext_ti = proto_tree_add_item(tree, hf_ptp_v2_mm_ptptext, tvb,
2152                         *cur_offset+1, length, FALSE);
2153
2154                 ptptext_subtree = proto_item_add_subtree(ptptext_ti, ett_ptp_v2_ptptext);
2155                         /* subtree */
2156                         proto_tree_add_item(ptptext_subtree, hf_ptp_v2_mm_ptptext_length, tvb,
2157                                 *cur_offset, 1, FALSE);
2158                         proto_tree_add_item(ptptext_subtree, hf_ptp_v2_mm_ptptext, tvb,
2159                                 *cur_offset+1, length, FALSE);
2160
2161                 *cur_offset = *cur_offset + length + 1;
2162         }
2163 }
2164
2165 static void
2166 dissect_ptp_v2_timeInterval(tvbuff_t *tvb, guint16 *cur_offset, proto_tree *tree, char* name, int hf_ptp_v2_timeInterval_ns, int hf_ptp_v2_timeInterval_subns)
2167 {
2168
2169         double time_double;
2170         gint64 time_ns;
2171         guint16 time_subns;
2172         proto_item      *ptptimeInterval_ti;
2173         proto_tree      *ptptimeInterval_subtree;
2174
2175         time_ns = tvb_get_ntohl(tvb, *cur_offset);
2176
2177         time_subns = tvb_get_ntohs(tvb, *cur_offset+6);
2178
2179         time_ns = time_ns << 16;
2180
2181         if(time_ns & 0x800000){
2182                 time_ns = time_ns | G_GINT64_CONSTANT(0xFFFFFFFFFF000000);
2183                 time_ns = time_ns | tvb_get_ntohs(tvb, *cur_offset+4);
2184
2185                 time_double = ((1.0*time_ns) + (time_subns/65536.0));
2186         }
2187         else
2188         {
2189                 time_ns = time_ns | tvb_get_ntohs(tvb, *cur_offset+4);
2190                 time_double = time_ns + (time_subns/65536.0);
2191         }
2192
2193         ptptimeInterval_ti = proto_tree_add_text(tree, tvb, *cur_offset, 8,
2194                 "%s: %f nanoseconds", name, time_double);
2195
2196         ptptimeInterval_subtree = proto_item_add_subtree(ptptimeInterval_ti, ett_ptp_v2_timeInterval);
2197
2198         proto_tree_add_uint64_format_value(ptptimeInterval_subtree,
2199                 hf_ptp_v2_timeInterval_ns, tvb, *cur_offset, 6, time_ns, "Ns: %" G_GINT64_MODIFIER "d nanoseconds", time_ns);
2200
2201         proto_tree_add_double_format(ptptimeInterval_subtree,
2202                 hf_ptp_v2_timeInterval_subns, tvb, *cur_offset+6, 2, (time_subns/65536.0),
2203                 "SubNs: %f nanoseconds", (time_subns/65536.0));
2204
2205         *cur_offset = *cur_offset + 8;
2206 }
2207
2208 /* Code to actually dissect the PTPv2 packets */
2209
2210 static void
2211 dissect_ptp_v2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2212 {
2213     guint8 ptp_v2_messageid = 0;
2214         guint16 ptp_v2_mm_managementId = 0;
2215         guint8 ptp_v2_management_action = 0;
2216     guint64 timeStamp;
2217     guint16 temp;
2218
2219
2220     /* Set up structures needed to add the protocol subtree and manage it */
2221     proto_item  *ti, *transportspecific_ti, *flags_ti, *managementData_ti, *clockType_ti, *protocolAddress_ti;
2222     proto_tree  *ptp_tree, *ptp_transportspecific_tree, *ptp_flags_tree, *ptp_managementData_tree,
2223                                 *ptp_clockType_tree, *ptp_protocolAddress_tree;
2224
2225     /* Make entries in Protocol column and Info column on summary display */
2226     col_set_str(pinfo->cinfo, COL_PROTOCOL, "PTPv2");
2227
2228     /* Get control field (what kind of message is this? (Sync, DelayReq, ...) */
2229
2230     ptp_v2_messageid = 0x0F & tvb_get_guint8 (tvb, PTP_V2_TRANSPORT_SPECIFIC_MESSAGE_ID_OFFSET);
2231
2232         /* Extend  Info column with managementId */
2233         if (check_col(pinfo->cinfo, COL_INFO))
2234         {
2235                 /* Create and set the string for "Info" column */
2236                 if ( ptp_v2_messageid == PTP_V2_MANAGEMENT_MESSAGE )
2237                 {
2238                         guint16 tlv_type;
2239                         /* Get TLV Type */
2240                         tlv_type = tvb_get_ntohs (tvb, PTP_V2_MM_TLV_TYPE_OFFSET);
2241                         /* For management there are PTP_V2_TLV_TYPE_MANAGEMENT and PTP_V2_TLV_TYPE_MANAGEMENT_ERROR_STATUS TLVs */
2242                         switch(tlv_type)
2243                         {
2244                                 case PTP_V2_TLV_TYPE_MANAGEMENT:
2245                                         /* Get the managementId */
2246                                         ptp_v2_mm_managementId = tvb_get_ntohs(tvb, PTP_V2_MM_TLV_MANAGEMENTID_OFFSET);
2247                                         ptp_v2_management_action = 0x0F & tvb_get_guint8(tvb, PTP_V2_MM_ACTION_OFFSET);
2248                                         col_add_fstr(pinfo->cinfo, COL_INFO, "Management (%s) %s", 
2249                                                 val_to_str(ptp_v2_mm_managementId, ptp_v2_managementID_infocolumn_vals, "Unknown management Id %u"),
2250                                                 val_to_str(ptp_v2_management_action, ptp_v2_mm_action_vals, "Unknown Action %u"));
2251                                         break;
2252                                 case PTP_V2_TLV_TYPE_MANAGEMENT_ERROR_STATUS:
2253                                         /* Get the managementErrorId */
2254                                         ptp_v2_mm_managementId = tvb_get_ntohs(tvb, PTP_V2_MM_TLV_MANAGEMENTERRORID_OFFSET);
2255                                         col_add_fstr(pinfo->cinfo, COL_INFO, "Management Error Message (%s)", val_to_str(ptp_v2_mm_managementId,
2256                                                  ptp2_managementErrorId_vals, "Unknown Error Id %u"));
2257                                         break;
2258                                 default:
2259                                         col_add_str(pinfo->cinfo, COL_INFO, val_to_str(ptp_v2_messageid, ptp_v2_messageid_vals, "Unknown PTP Message (%u)"));
2260                                         break;
2261                         }
2262                 }
2263                 else
2264                 {
2265                     col_add_str(pinfo->cinfo, COL_INFO, val_to_str(ptp_v2_messageid, ptp_v2_messageid_vals, "Unknown PTP Message (%u)"));
2266                 }
2267         }
2268
2269    if (tree) {
2270
2271         ti = proto_tree_add_item(tree, proto_ptp, tvb, 0, -1, FALSE);
2272
2273         ptp_tree = proto_item_add_subtree(ti, ett_ptp_v2);
2274
2275         transportspecific_ti = proto_tree_add_item(ptp_tree,
2276             hf_ptp_v2_transportspecific, tvb, PTP_V2_TRANSPORT_SPECIFIC_MESSAGE_ID_OFFSET, 1, FALSE);
2277
2278         ptp_transportspecific_tree = proto_item_add_subtree(transportspecific_ti, ett_ptp_v2_transportspecific);
2279
2280         if (ptpv2_oE == TRUE)
2281         {
2282             proto_tree_add_item(ptp_transportspecific_tree,
2283                 hf_ptp_v2_transportspecific_802as_conform, tvb, PTP_V2_TRANSPORT_SPECIFIC_MESSAGE_ID_OFFSET, 1, FALSE);
2284         }
2285         else
2286         {
2287             proto_tree_add_item(ptp_transportspecific_tree,
2288                 hf_ptp_v2_transportspecific_v1_compatibility, tvb, PTP_V2_TRANSPORT_SPECIFIC_MESSAGE_ID_OFFSET, 1, FALSE);
2289         }
2290
2291         proto_tree_add_item(ptp_tree,
2292             hf_ptp_v2_messageid, tvb, PTP_V2_TRANSPORT_SPECIFIC_MESSAGE_ID_OFFSET, 1, FALSE);
2293
2294         proto_tree_add_item(ptp_tree,
2295             hf_ptp_v2_versionptp, tvb, PTP_V2_VERSIONPTP_OFFSET, 1, FALSE);
2296
2297         proto_tree_add_item(ptp_tree,
2298             hf_ptp_v2_messagelength, tvb, PTP_V2_MESSAGE_LENGTH_OFFSET, 2, FALSE);
2299
2300         proto_tree_add_item(ptp_tree,
2301             hf_ptp_v2_domainnumber, tvb, PTP_V2_DOMAIN_NUMBER_OFFSET, 1, FALSE);
2302
2303
2304         flags_ti = proto_tree_add_item(ptp_tree,
2305             hf_ptp_v2_flags, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2306
2307         ptp_flags_tree = proto_item_add_subtree(flags_ti, ett_ptp_v2_flags);
2308
2309         proto_tree_add_item(ptp_flags_tree,
2310             hf_ptp_v2_flags_security, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2311
2312         proto_tree_add_item(ptp_flags_tree,
2313             hf_ptp_v2_flags_specific2, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2314
2315         proto_tree_add_item(ptp_flags_tree,
2316             hf_ptp_v2_flags_specific1, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2317
2318         proto_tree_add_item(ptp_flags_tree,
2319             hf_ptp_v2_flags_unicast, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2320
2321         proto_tree_add_item(ptp_flags_tree,
2322             hf_ptp_v2_flags_twostep, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2323
2324         proto_tree_add_item(ptp_flags_tree,
2325             hf_ptp_v2_flags_alternatemaster, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2326
2327         proto_tree_add_item(ptp_flags_tree,
2328             hf_ptp_v2_flags_frequencytraceable, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2329
2330         proto_tree_add_item(ptp_flags_tree,
2331             hf_ptp_v2_flags_timetraceable, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2332
2333         proto_tree_add_item(ptp_flags_tree,
2334             hf_ptp_v2_flags_ptptimescale, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2335
2336         proto_tree_add_item(ptp_flags_tree,
2337             hf_ptp_v2_flags_utcoffsetvalid, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2338
2339         proto_tree_add_item(ptp_flags_tree,
2340             hf_ptp_v2_flags_li59, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2341
2342         proto_tree_add_item(ptp_flags_tree,
2343             hf_ptp_v2_flags_li61, tvb, PTP_V2_FLAGS_OFFSET, 2, FALSE);
2344
2345         temp = PTP_V2_CORRECTIONNS_OFFSET;
2346
2347         dissect_ptp_v2_timeInterval(tvb, &temp, ptp_tree, "correction", hf_ptp_v2_correction, hf_ptp_v2_correctionsubns);
2348
2349         proto_tree_add_item(ptp_tree,
2350             hf_ptp_v2_clockidentity, tvb, PTP_V2_CLOCKIDENTITY_OFFSET, 8, FALSE);
2351
2352         proto_tree_add_item(ptp_tree,
2353             hf_ptp_v2_sourceportid, tvb, PTP_V2_SOURCEPORTID_OFFSET, 2, FALSE);
2354
2355         proto_tree_add_item(ptp_tree,
2356             hf_ptp_v2_sequenceid, tvb, PTP_V2_SEQUENCEID_OFFSET, 2, FALSE);
2357
2358         proto_tree_add_item(ptp_tree,
2359             hf_ptp_v2_control, tvb, PTP_V2_CONTROL_OFFSET, 1, FALSE);
2360
2361         proto_tree_add_item(ptp_tree,
2362             hf_ptp_v2_logmessageperiod, tvb, PTP_V2_LOGMESSAGEPERIOD_OFFSET, 1, FALSE);
2363
2364         switch(ptp_v2_messageid){
2365             case PTP_V2_ANNOUNCE_MESSAGE:{
2366                 guint16     Offset;
2367                 guint16     tlv_type;
2368                 guint16     tlv_length;
2369                 guint16     tlv_total_length;
2370                 proto_item *tlv_ti;
2371                 proto_tree *ptp_tlv_tree;
2372
2373                 timeStamp = tvb_get_ntohl(tvb, PTP_V2_AN_ORIGINTIMESTAMPSECONDS_OFFSET);
2374                 timeStamp = timeStamp << 16;
2375                 timeStamp = timeStamp | tvb_get_ntohs(tvb, PTP_V2_AN_ORIGINTIMESTAMPSECONDS_OFFSET+4);
2376
2377                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_origintimestamp_seconds, tvb,
2378                             PTP_V2_AN_ORIGINTIMESTAMPSECONDS_OFFSET, 6, FALSE);
2379                                         
2380                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_origintimestamp_nanoseconds, tvb,
2381                             PTP_V2_AN_ORIGINTIMESTAMPNANOSECONDS_OFFSET, 4, FALSE);
2382
2383                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_origincurrentutcoffset, tvb,
2384                     PTP_V2_AN_ORIGINCURRENTUTCOFFSET_OFFSET, 2, FALSE);
2385
2386                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_priority1, tvb,
2387                     PTP_V2_AN_PRIORITY_1_OFFSET, 1, FALSE);
2388
2389                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_grandmasterclockclass, tvb,
2390                     PTP_V2_AN_GRANDMASTERCLOCKCLASS_OFFSET, 1, FALSE);
2391
2392                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_grandmasterclockaccuracy, tvb,
2393                     PTP_V2_AN_GRANDMASTERCLOCKACCURACY_OFFSET, 1, FALSE);
2394
2395                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_grandmasterclockvariance, tvb,
2396                     PTP_V2_AN_GRANDMASTERCLOCKVARIANCE_OFFSET, 2, FALSE);
2397
2398                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_priority2, tvb,
2399                     PTP_V2_AN_PRIORITY_2_OFFSET, 1, FALSE);
2400
2401                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_grandmasterclockidentity, tvb,
2402                     PTP_V2_AN_GRANDMASTERCLOCKIDENTITY_OFFSET, 8, FALSE);
2403
2404                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_an_localstepsremoved, tvb,
2405                         PTP_V2_AN_LOCALSTEPSREMOVED_OFFSET, 2, FALSE);
2406
2407                                 proto_tree_add_item(ptp_tree,
2408                     hf_ptp_v2_an_timesource, tvb, PTP_V2_AN_TIMESOURCE_OFFSET, 1, FALSE);
2409
2410                                 tlv_total_length = 0;
2411                                 while (tvb_reported_length_remaining(tvb, PTP_V2_AN_TLV_OFFSET + tlv_total_length) >= 2)
2412                                 {
2413                                         /* There are TLV's to be processed */
2414                                         tlv_type = tvb_get_ntohs (tvb, PTP_V2_AN_TLV_OFFSET+tlv_total_length+PTP_V2_AN_TLV_TYPE_OFFSET);
2415                                         tlv_length = tvb_get_ntohs (tvb, PTP_V2_AN_TLV_OFFSET+tlv_total_length+PTP_V2_AN_TLV_LENGTHFIELD_OFFSET);
2416
2417                                         tlv_ti = proto_tree_add_text(
2418                                                 ptp_tree,
2419                                                 tvb,
2420                                                 PTP_V2_AN_TLV_OFFSET + tlv_total_length,
2421                                                 tlv_length + PTP_V2_AN_TLV_DATA_OFFSET,
2422                                                 "%s TLV",
2423                                                 val_to_str(tlv_type,
2424                                                                    ptp_v2_TLV_type_vals,
2425                                                                    "Unknown (%u)"));
2426
2427                                         ptp_tlv_tree = proto_item_add_subtree(tlv_ti, ett_ptp_v2_tlv);
2428
2429                                         proto_tree_add_item(ptp_tlv_tree,
2430                                                                                 hf_ptp_v2_an_tlv_tlvtype,
2431                                                                                 tvb,
2432                                                                                 PTP_V2_AN_TLV_OFFSET + tlv_total_length + PTP_V2_AN_TLV_TYPE_OFFSET,
2433                                                                                 2,
2434                                                                                 FALSE);
2435
2436                                         proto_tree_add_item(ptp_tlv_tree,
2437                                                                                 hf_ptp_v2_an_tlv_lengthfield,
2438                                                                                 tvb,
2439                                                                                 PTP_V2_AN_TLV_OFFSET + tlv_total_length + PTP_V2_AN_TLV_LENGTHFIELD_OFFSET,
2440                                                                                 2,
2441                                                                                 FALSE);
2442
2443                                         switch (tlv_type)
2444                                         {
2445                                                 case PTP_V2_TLV_TYPE_ALTERNATE_TIME_OFFSET_INDICATOR:
2446                                                 {
2447                                                         proto_tree_add_item(ptp_tlv_tree,
2448                                                                                                 hf_ptp_v2_atoi_tlv_keyfield,
2449                                                                                                 tvb,
2450                                                                                                 PTP_V2_AN_TLV_OFFSET + tlv_total_length + PTP_V2_AN_TLV_ATOI_KEYFIELD_OFFSET,
2451                                                                                                 1,
2452                                                                                                 FALSE);
2453
2454                                                         proto_tree_add_item(ptp_tlv_tree,
2455                                                                                                 hf_ptp_v2_atoi_tlv_currentoffset,
2456                                                                                                 tvb,
2457                                                                                                 PTP_V2_AN_TLV_OFFSET + tlv_total_length + PTP_V2_AN_TLV_ATOI_CURRENTOFFSET_OFFSET,
2458                                                                                                 4,
2459                                                                                                 FALSE);
2460
2461                                                         proto_tree_add_item(ptp_tlv_tree,
2462                                                                                                 hf_ptp_v2_atoi_tlv_jumpseconds,
2463                                                                                                 tvb,
2464                                                                                                 PTP_V2_AN_TLV_OFFSET + tlv_total_length + PTP_V2_AN_TLV_ATOI_JUMPSECONDS_OFFSET,
2465                                                                                                 4,
2466                                                                                                 FALSE);
2467
2468                                                         proto_tree_add_item(ptp_tlv_tree,
2469                                                                                                 hf_ptp_v2_atoi_tlv_timeofnextjump,
2470                                                                                                 tvb,
2471                                                                                                 PTP_V2_AN_TLV_OFFSET + tlv_total_length + PTP_V2_AN_TLV_ATOI_TIMEOFNEXTJUMP_OFFSET,
2472                                                                                                 6,
2473                                                                                                 FALSE);
2474
2475                                                         Offset = PTP_V2_AN_TLV_OFFSET + tlv_total_length + PTP_V2_AN_TLV_ATOI_DISPLAYNAME_OFFSET;
2476                                                         dissect_ptp_v2_text(tvb,
2477                                                                                             &Offset,
2478                                                                                             ptp_tlv_tree,
2479                                                                                             hf_ptp_v2_atoi_tlv_displayname,
2480                                                                                             hf_ptp_v2_atoi_tlv_displayname_length);
2481
2482                                                         break;
2483                                                 }
2484                                                 default:
2485                                                 {
2486                                                         proto_tree_add_item(ptp_tlv_tree,
2487                                                                                                 hf_ptp_v2_an_tlv_data,
2488                                                                                                 tvb,
2489                                                                                                 PTP_V2_AN_TLV_OFFSET + tlv_total_length + PTP_V2_AN_TLV_DATA_OFFSET,
2490                                                                                                 tlv_length,
2491                                                                                                 FALSE);
2492                                                         break;
2493                                                 }
2494                                         }
2495
2496                                         tlv_total_length += (tlv_length + PTP_V2_AN_TLV_DATA_OFFSET);
2497                                 }
2498
2499                 break;
2500             }
2501
2502             case PTP_V2_SYNC_MESSAGE:
2503             case PTP_V2_DELAY_REQ_MESSAGE:{
2504                 timeStamp = tvb_get_ntohl(tvb, PTP_V2_SDR_ORIGINTIMESTAMPSECONDS_OFFSET);
2505                 timeStamp = timeStamp << 16;
2506                 timeStamp = timeStamp | tvb_get_ntohs(tvb, PTP_V2_SDR_ORIGINTIMESTAMPSECONDS_OFFSET+4);
2507
2508                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_sdr_origintimestamp_seconds, tvb,
2509                     PTP_V2_SDR_ORIGINTIMESTAMPSECONDS_OFFSET, 6, FALSE);
2510                     
2511                 proto_tree_add_item(ptp_tree, hf_ptp_v2_sdr_origintimestamp_nanoseconds, tvb,
2512                     PTP_V2_SDR_ORIGINTIMESTAMPNANOSECONDS_OFFSET, 4, FALSE);
2513
2514                 break;
2515             }
2516
2517             case PTP_V2_FOLLOWUP_MESSAGE:{
2518                 timeStamp = tvb_get_ntohl(tvb, PTP_V2_FU_PRECISEORIGINTIMESTAMPSECONDS_OFFSET);
2519                 timeStamp = timeStamp << 16;
2520                 timeStamp = timeStamp | tvb_get_ntohs(tvb, PTP_V2_FU_PRECISEORIGINTIMESTAMPSECONDS_OFFSET+4);
2521                 
2522                 proto_tree_add_item(ptp_tree, hf_ptp_v2_fu_preciseorigintimestamp_seconds, tvb,
2523                     PTP_V2_FU_PRECISEORIGINTIMESTAMPSECONDS_OFFSET, 6, FALSE);
2524
2525                 proto_tree_add_item(ptp_tree, hf_ptp_v2_fu_preciseorigintimestamp_nanoseconds, tvb,
2526                     PTP_V2_FU_PRECISEORIGINTIMESTAMPNANOSECONDS_OFFSET, 4, FALSE);
2527
2528                 break;
2529             }
2530
2531             case PTP_V2_DELAY_RESP_MESSAGE:{
2532                 timeStamp = tvb_get_ntohl(tvb, PTP_V2_DR_RECEIVETIMESTAMPSECONDS_OFFSET);
2533                 timeStamp = timeStamp << 16;
2534                 timeStamp = timeStamp | tvb_get_ntohs(tvb, PTP_V2_DR_RECEIVETIMESTAMPSECONDS_OFFSET+4);
2535
2536                 proto_tree_add_item(ptp_tree, hf_ptp_v2_dr_receivetimestamp_seconds, tvb,
2537                     PTP_V2_DR_RECEIVETIMESTAMPSECONDS_OFFSET, 6, FALSE);
2538                                         
2539                 proto_tree_add_item(ptp_tree, hf_ptp_v2_dr_receivetimestamp_nanoseconds, tvb,
2540                     PTP_V2_DR_RECEIVETIMESTAMPNANOSECONDS_OFFSET, 4, FALSE);
2541
2542                 proto_tree_add_item(ptp_tree, hf_ptp_v2_dr_requestingportidentity, tvb,
2543                     PTP_V2_DR_REQUESTINGPORTIDENTITY_OFFSET, 8, FALSE);
2544
2545                 proto_tree_add_item(ptp_tree, hf_ptp_v2_dr_requestingsourceportid, tvb,
2546                     PTP_V2_DR_REQUESTINGSOURCEPORTID_OFFSET, 2, FALSE);
2547
2548                 break;
2549             }
2550
2551             case PTP_V2_PATH_DELAY_REQ_MESSAGE:{
2552                 timeStamp = tvb_get_ntohl(tvb, PTP_V2_PDRQ_ORIGINTIMESTAMPSECONDS_OFFSET);
2553                 timeStamp = timeStamp << 16;
2554                 timeStamp = timeStamp | tvb_get_ntohs(tvb, PTP_V2_PDRQ_ORIGINTIMESTAMPSECONDS_OFFSET+4);
2555
2556                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdrq_origintimestamp_seconds, tvb,
2557                     PTP_V2_PDRQ_ORIGINTIMESTAMPSECONDS_OFFSET, 6, FALSE);
2558
2559                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdrq_origintimestamp_nanoseconds, tvb,
2560                     PTP_V2_PDRQ_ORIGINTIMESTAMPNANOSECONDS_OFFSET, 4, FALSE);
2561
2562                 break;
2563             }
2564
2565             case PTP_V2_PATH_DELAY_RESP_MESSAGE:{
2566                 timeStamp = tvb_get_ntohl(tvb, PTP_V2_PDRS_REQUESTRECEIPTTIMESTAMPSECONDS_OFFSET);
2567                 timeStamp = timeStamp << 16;
2568                 timeStamp = timeStamp | tvb_get_ntohs(tvb, PTP_V2_PDRS_REQUESTRECEIPTTIMESTAMPSECONDS_OFFSET+4);
2569
2570                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdrs_requestreceipttimestamp_seconds, tvb,
2571                     PTP_V2_PDRS_REQUESTRECEIPTTIMESTAMPSECONDS_OFFSET, 6, FALSE);
2572
2573                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdrs_requestreceipttimestamp_nanoseconds, tvb,
2574                     PTP_V2_PDRS_REQUESTRECEIPTTIMESTAMPNANOSECONDS_OFFSET, 4, FALSE);
2575
2576                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdrs_requestingportidentity, tvb,
2577                     PTP_V2_PDRS_REQUESTINGPORTIDENTITY_OFFSET, 8, FALSE);
2578
2579                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdrs_requestingsourceportid, tvb,
2580                     PTP_V2_PDRS_REQUESTINGSOURCEPORTID_OFFSET, 2, FALSE);
2581
2582                 break;
2583             }
2584
2585             case PTP_V2_PATH_DELAY_FOLLOWUP_MESSAGE:{
2586                 timeStamp = tvb_get_ntohl(tvb, PTP_V2_PDFU_RESPONSEORIGINTIMESTAMPSECONDS_OFFSET);
2587                 timeStamp = timeStamp << 16;
2588                 timeStamp = timeStamp | tvb_get_ntohs(tvb, PTP_V2_PDFU_RESPONSEORIGINTIMESTAMPSECONDS_OFFSET+4);
2589
2590                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdfu_responseorigintimestamp_seconds, tvb,
2591                     PTP_V2_PDFU_RESPONSEORIGINTIMESTAMPSECONDS_OFFSET, 6, FALSE);
2592
2593                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdfu_responseorigintimestamp_nanoseconds, tvb,
2594                     PTP_V2_PDFU_RESPONSEORIGINTIMESTAMPNANOSECONDS_OFFSET, 4, FALSE);
2595
2596
2597                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdfu_requestingportidentity, tvb,
2598                     PTP_V2_PDFU_REQUESTINGPORTIDENTITY_OFFSET, 8, FALSE);
2599
2600                 proto_tree_add_item(ptp_tree, hf_ptp_v2_pdfu_requestingsourceportid, tvb,
2601                     PTP_V2_PDFU_REQUESTINGSOURCEPORTID_OFFSET, 2, FALSE);
2602
2603                 break;
2604             }
2605
2606             case PTP_V2_SIGNALLING_MESSAGE:{
2607
2608                                 guint16 tlv_type, tlv_length;
2609
2610                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_sig_targetportidentity, tvb,
2611                     PTP_V2_SIG_TARGETPORTIDENTITY_OFFSET, 8, FALSE);
2612
2613                 proto_tree_add_item(ptp_tree, hf_ptp_v2_sig_targetportid, tvb,
2614                     PTP_V2_SIG_TARGETPORTID_OFFSET, 2, FALSE);
2615
2616                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_tlvType, tvb,
2617                                 PTP_V2_SIG_TARGETPORTID_OFFSET+2, 2, FALSE);
2618
2619                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_lengthField, tvb,
2620                                 PTP_V2_SIG_TARGETPORTID_OFFSET+4, 2, FALSE);
2621
2622                                 tlv_type = tvb_get_ntohs (tvb, PTP_V2_MM_TLV_TYPE_OFFSET);
2623                                 tlv_length = tvb_get_ntohs (tvb, PTP_V2_MM_TLV_LENGTHFIELD_OFFSET);
2624
2625                                 if (tlv_length <= 2)
2626                                 {
2627                                         /* no data */
2628                                         break;
2629                                 }
2630                                 /* ToDO: Add dissector for TLVs and allow multiple TLVs */
2631                                 proto_tree_add_text(ptp_tree, tvb, PTP_V2_SIG_TARGETPORTID_OFFSET+6, tlv_length, "Data");
2632                                 break;
2633             }
2634
2635             case PTP_V2_MANAGEMENT_MESSAGE:
2636                         {
2637                                 guint16 tlv_type, tlv_length;
2638
2639                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_targetportidentity, tvb,
2640                                 PTP_V2_MM_TARGETPORTIDENTITY_OFFSET, 8, FALSE);
2641
2642                             proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_targetportid, tvb,
2643                                 PTP_V2_MM_TARGETPORTID_OFFSET, 2, FALSE);
2644
2645                             proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_startingboundaryhops, tvb,
2646                                 PTP_V2_MM_STARTINGBOUNDARYHOPS_OFFSET, 1, FALSE);
2647
2648                             proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_boundaryhops, tvb,
2649                                 PTP_V2_MM_BOUNDARYHOPS_OFFSET, 1, FALSE);
2650
2651                             proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_action, tvb,
2652                                 PTP_V2_MM_ACTION_OFFSET, 1, FALSE);
2653
2654                                 /* management TLV */
2655                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_tlvType, tvb,
2656                                 PTP_V2_MM_TLV_TYPE_OFFSET, 2, FALSE);
2657
2658                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_lengthField, tvb,
2659                                 PTP_V2_MM_TLV_LENGTHFIELD_OFFSET, 2, FALSE);
2660
2661                                 tlv_type = tvb_get_ntohs (tvb, PTP_V2_MM_TLV_TYPE_OFFSET);
2662                                 tlv_length = tvb_get_ntohs (tvb, PTP_V2_MM_TLV_LENGTHFIELD_OFFSET);
2663
2664                                 /* For management there are PTP_V2_TLV_TYPE_MANAGEMENT and PTP_V2_TLV_TYPE_MANAGEMENT_ERROR_STATUS TLVs */
2665                                 switch(tlv_type) {
2666                                         case PTP_V2_TLV_TYPE_MANAGEMENT:
2667                                         {
2668                                                 guint16 ptp_v2_managementId;
2669                                                 guint16 Offset = PTP_V2_MM_TLV_DATAFIELD_OFFSET;
2670
2671                                                 proto_tree_add_item(ptp_tree, hf_ptp_v2_mm_managementId, tvb,
2672                                                 PTP_V2_MM_TLV_MANAGEMENTID_OFFSET, 2, FALSE);
2673
2674                                                 ptp_v2_managementId = tvb_get_ntohs (tvb, PTP_V2_MM_TLV_MANAGEMENTID_OFFSET);
2675
2676                                                 if (tlv_length <= 2)
2677                                                 {
2678                                                         /* no data */
2679                                                         break;
2680                                                 }
2681
2682                                                 managementData_ti = proto_tree_add_text(ptp_tree, tvb, Offset, tlv_length, "Data");
2683
2684                                                 /* data field of the management message (subtree)*/
2685                                                 ptp_managementData_tree = proto_item_add_subtree(managementData_ti, ett_ptp_v2_managementData);
2686
2687                                                 switch(ptp_v2_managementId) {
2688                                                         case PTP_V2_MM_ID_NULL_MANAGEMENT:
2689                                                         {
2690                                                                 /* no data in NULL management */
2691                                                                 break;
2692                                                         }
2693                                                         case PTP_V2_MM_ID_CLOCK_DESCRIPTION:
2694                                                         {
2695                                                                 guint16 N = 0, S = 0;
2696                                                                 clockType_ti = proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_clockType, tvb,
2697                                                                         Offset, 2, FALSE);
2698
2699                                                                 ptp_clockType_tree = proto_item_add_subtree(clockType_ti, ett_ptp_v2_clockType);
2700                                                                         /* ClockType Subtree */
2701                                                                         proto_tree_add_item(ptp_clockType_tree, hf_ptp_v2_mm_clockType_ordinaryClock, tvb,
2702                                                                                 Offset, 2, FALSE);
2703
2704                                                                         proto_tree_add_item(ptp_clockType_tree, hf_ptp_v2_mm_clockType_boundaryClock, tvb,
2705                                                                                 Offset, 2, FALSE);
2706
2707                                                                         proto_tree_add_item(ptp_clockType_tree, hf_ptp_v2_mm_clockType_p2p_transparentClock, tvb,
2708                                                                                 Offset, 2, FALSE);
2709
2710                                                                         proto_tree_add_item(ptp_clockType_tree, hf_ptp_v2_mm_clockType_e2e_transparentClock, tvb,
2711                                                                                 Offset, 2, FALSE);
2712
2713                                                                         proto_tree_add_item(ptp_clockType_tree, hf_ptp_v2_mm_clockType_managementNode, tvb,
2714                                                                                 Offset, 2, FALSE);
2715
2716                                                                         proto_tree_add_item(ptp_clockType_tree, hf_ptp_v2_mm_clockType_reserved, tvb,
2717                                                                                 Offset, 2, FALSE);
2718                                                                 Offset +=2;
2719
2720                                                                 dissect_ptp_v2_text     (tvb, &Offset, ptp_managementData_tree,
2721                                                                                                          hf_ptp_v2_mm_physicalLayerProtocol, hf_ptp_v2_mm_physicalLayerProtocol_length);
2722
2723                                                                 proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_physicalAddressLength, tvb,
2724                                                                         Offset, 2, FALSE);
2725
2726                                                                 S = tvb_get_ntohs (tvb, Offset);
2727                                                                 Offset +=2;
2728
2729                                                                 proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_physicalAddress, tvb,
2730                                                                         Offset, S, FALSE);
2731                                                                 Offset += S;
2732
2733                                                                 N = tvb_get_ntohs (tvb, Offset+2);
2734
2735                                                                 protocolAddress_ti = proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_protocolAddress, tvb,
2736                                                                         Offset+4, N, FALSE);
2737
2738                                                                 ptp_protocolAddress_tree = proto_item_add_subtree(protocolAddress_ti, ett_ptp_v2_protocolAddress);
2739                                                                         /* physicalLayerProtocol subtree */
2740                                                                         proto_tree_add_item(ptp_protocolAddress_tree, hf_ptp_v2_mm_protocolAddress_networkProtocol, tvb,
2741                                                                                 Offset, 2, FALSE);
2742
2743                                                                         proto_tree_add_item(ptp_protocolAddress_tree, hf_ptp_v2_mm_protocolAddress_length, tvb,
2744                                                                                 Offset+2, 2, FALSE);
2745
2746                                                                         proto_tree_add_item(ptp_protocolAddress_tree, hf_ptp_v2_mm_protocolAddress, tvb,
2747                                                                                 Offset+4, N, FALSE);
2748                                                                 N = N + 4;
2749                                                                 Offset += N;
2750
2751                                                                 proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_manufacturerIdentity, tvb,
2752                                                                         Offset, 3, FALSE);
2753
2754                                                                 Offset += 3;
2755
2756                                                                 proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_reserved, tvb,
2757                                                                         Offset, 1, FALSE);
2758                                                                 Offset += 1;
2759
2760                                                                 dissect_ptp_v2_text     (tvb, &Offset, ptp_managementData_tree,
2761                                                                                                          hf_ptp_v2_mm_productDescription, hf_ptp_v2_mm_productDescription_length);
2762                                                                 dissect_ptp_v2_text     (tvb, &Offset, ptp_managementData_tree,
2763                                                                                                          hf_ptp_v2_mm_revisionData, hf_ptp_v2_mm_revisionData_length);
2764                                                                 dissect_ptp_v2_text     (tvb, &Offset, ptp_managementData_tree,
2765                                                                                                          hf_ptp_v2_mm_userDescription, hf_ptp_v2_mm_userDescription_length);
2766
2767                                                                 proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_profileIdentity, tvb,
2768                                                                         Offset, 6, FALSE);
2769                                                                 Offset += 6;
2770
2771                                                                 /* Wenn Offset nicht gerade folgt noch ein pad Bit */
2772                                                                 if ( (Offset - PTP_V2_MM_TLV_DATAFIELD_OFFSET) % 2 )
2773                                                                 {
2774                                                                         proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_pad, tvb,
2775                                                                         Offset, 1, FALSE);
2776                                                                 }
2777                                                                 break;
2778                                                         }
2779                                                         case PTP_V2_MM_ID_USER_DESCRIPTION:
2780                                                         {
2781
2782                                                                 dissect_ptp_v2_text     (tvb, &Offset, ptp_managementData_tree,
2783                                                                                                          hf_ptp_v2_mm_userDescription, hf_ptp_v2_mm_userDescription_length);
2784
2785                                                                 /* Wenn Offset nicht gerade folgt noch ein pad Bit */
2786                                                                 if ( (Offset - PTP_V2_MM_TLV_DATAFIELD_OFFSET) % 2 )
2787                                                                 {
2788                                                                         proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_pad, tvb,
2789                                                                         Offset, 1, FALSE);
2790                                                                 }
2791                                                                 break;
2792                                                         }
2793                                                         case PTP_V2_MM_ID_SAVE_IN_NON_VOLATILE_STORAGE:
2794                                                         {
2795                                                                 /* no data */
2796                                                                 break;
2797                                                         }
2798                                                         case PTP_V2_MM_ID_RESET_NON_VOLATILE_STORAGE:
2799                                                         {
2800                                                                 /* no data */
2801                                                                 break;
2802                                                         }
2803                                                         case PTP_V2_MM_ID_INITIALIZE:
2804                                                         {
2805                                                                 proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_initializationKey, tvb,
2806                                                                         Offset, 2, FALSE);
2807                                                                 break;
2808                                                         }
2809                                                         case PTP_V2_MM_ID_FAULT_LOG:
2810                                                         {
2811                                                                 guint16 i, num = 0;
2812                                                                 proto_item      *ptpError_ti;
2813                                                                 proto_tree      *ptpError_subtree;
2814
2815                                                                 num = tvb_get_ntohs (tvb, Offset);
2816
2817                                                                 proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_numberOfFaultRecords, tvb,
2818                                                                         Offset, 2, FALSE);
2819                                                                 Offset +=2;
2820
2821                                                                 for (i = 1; i <= num; i++)
2822                                                                 {
2823                                                                         ptpError_ti = proto_tree_add_text(ptp_managementData_tree, tvb, Offset, tvb_get_ntohs (tvb, Offset), "Fault record");
2824
2825                                                                         /*  (subtree)*/
2826                                                                         ptpError_subtree = proto_item_add_subtree(ptpError_ti, ett_ptp_v2_faultRecord);
2827
2828                                                                         proto_tree_add_item(ptpError_subtree, hf_ptp_v2_mm_faultRecordLength, tvb,
2829                                                                                 Offset, 2, FALSE);
2830                                                                         Offset +=2;
2831
2832                                                                         timeStamp = tvb_get_ntohl(tvb, Offset);
2833                                                         timeStamp = timeStamp << 16;
2834                                                         timeStamp = timeStamp | tvb_get_ntohs(tvb, Offset+4);
2835
2836                                                                         proto_tree_add_item(ptpError_subtree, hf_ptp_v2_mm_faultTime_s, tvb,
2837                                                                     Offset, 6, FALSE);
2838
2839                                                                         Offset +=6;
2840                                                         proto_tree_add_item(ptpError_subtree, hf_ptp_v2_mm_faultTime_ns, tvb,
2841                                                                     Offset, 4, FALSE);
2842                                                                         Offset +=4;
2843                                                                         proto_tree_add_item(ptpError_subtree, hf_ptp_v2_mm_severityCode, tvb,
2844                                                                     Offset, 1, FALSE);
2845                                                                         Offset +=1;
2846
2847                                                                         dissect_ptp_v2_text     (tvb, &Offset, ptpError_subtree,
2848                                                                                                                  hf_ptp_v2_mm_faultName, hf_ptp_v2_mm_faultName_length);
2849
2850                                                                         dissect_ptp_v2_text     (tvb, &Offset, ptpError_subtree,
2851                                                                                                                  hf_ptp_v2_mm_faultValue, hf_ptp_v2_mm_faultValue_length);
2852
2853                                                                         dissect_ptp_v2_text     (tvb, &Offset, ptpError_subtree,
2854                                                                                                                  hf_ptp_v2_mm_faultDescription, hf_ptp_v2_mm_faultDescription_length);
2855                                                                 }
2856
2857                                                                 /* Wenn Offset nicht gerade folgt noch ein pad Bit */
2858                                                                 if ( (Offset - PTP_V2_MM_TLV_DATAFIELD_OFFSET) % 2 )
2859                                                                 {
2860                                                                         proto_tree_add_item(ptp_managementData_tree, hf_ptp_v2_mm_pad, tvb,
2861