MSWSP: add ids for another unknown Property Set
[wireshark-wip.git] / epan / dissectors / packet-vssmonitoring.c
blob4ab7c6e72eb03cf097d83b9fc25ff30708b817fd
1 /* packet-vssmonitoring.c
2 * Routines for dissection of VSS-monitoring timestamp and portstamp
4 * Copyright VSS-Monitoring 2011
6 * 20111205 - First edition by Sake Blok (sake.blok@SYN-bit.nl)
8 * $Id$
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "config.h"
31 #include <epan/packet.h>
32 #include <epan/prefs.h>
35 #define VSS_NS_MASK 0x3fffffff
36 #define CLKSRC_SHIFT 30
38 #define CLKSRC_LOCAL 0
39 #define CLKSRC_NTP 1
40 #define CLKSRC_GPS 2
41 #define CLKSRC_PTP 3
43 static const value_string clksrc_vals[] = {
44 { CLKSRC_LOCAL, "Not Synced" },
45 { CLKSRC_NTP, "NTP" },
46 { CLKSRC_GPS, "GPS" },
47 { CLKSRC_PTP, "PTP" },
48 { 0, NULL }
52 static int proto_vssmonitoring = -1;
54 static int hf_vssmonitoring_time = -1;
55 static int hf_vssmonitoring_clksrc = -1;
56 static int hf_vssmonitoring_srcport = -1;
58 static gint ett_vssmonitoring = -1;
60 static gboolean vssmonitoring_use_heuristics = TRUE;
62 static int
63 dissect_vssmonitoring(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
65 proto_tree *ti = NULL;
66 proto_tree *vssmonitoring_tree = NULL;
67 guint offset = 0;
69 guint trailer_len;
70 nstime_t vssmonitoring_time;
71 guint8 vssmonitoring_clksrc = 0;
72 guint16 vssmonitoring_srcport = 0;
74 struct tm *tmp;
77 /* First get the length of the trailer */
78 trailer_len = tvb_reported_length(tvb);
80 /* The trailer length is a sum (of any combination) of:
81 * timestamp (8 bytes)
82 * port stamp (1 or 2 bytes)
83 * fcs (4 bytes)
85 * The FCS is dissected by our caller, so we check for a trailer
86 * with a length that includes one or more of a time stamp and
87 * a 1-byte or 2-byte port stamp.
89 * See
91 * http://www.vssmonitoring.com/portals/application_note/Port%20and%20Time%20Stamping.pdf
93 * (although that speaks of 2-byte port stamps as being for a "future
94 * release").
96 * This means a trailer length must not be more than 14 bytes,
97 * and:
99 * must not be 3 modulo 3 (as it can't have both a 1-byte
100 * and a 2-byte port stamp);
102 * if it's less than 8 bytes, must not be 0 modulo 3 (as
103 * it must have a 1-byte or 2-byte port stamp, given that
104 * it has no timestamp).
106 if ( trailer_len > 14 )
107 return 0;
109 /* ... and also a 1-byte port stamp can not co-exist with a 2-byte
110 * portstamp
112 if ( (trailer_len & 3) == 3 )
113 return 0;
115 /* ... and if you have neither a time stamp nor a port stamp,
116 * you don't have a trailer
118 if ( (trailer_len & 3) == 0 && trailer_len < 8 )
119 return 0;
121 if ( trailer_len >= 8 ) {
122 vssmonitoring_time.secs = tvb_get_ntohl(tvb, offset);
123 vssmonitoring_time.nsecs = tvb_get_ntohl(tvb, offset + 4);
124 vssmonitoring_clksrc = (guint8)(((guint32)vssmonitoring_time.nsecs) >> CLKSRC_SHIFT);
125 vssmonitoring_time.nsecs &= VSS_NS_MASK;
127 /* There are only heuristics for timestamps, the port stamp can be any value */
128 if ( vssmonitoring_use_heuristics ) {
130 /* The timestamp will be based on the uptime until the TAP is completely booted,
131 * this takes about 60s, but use 1 hour to be sure
134 /* Probably just null data to fill up a short frame.
135 * FIXME: Should be made even stricter.
137 if (vssmonitoring_time.secs == 0)
138 return 0;
139 if (vssmonitoring_time.secs > 3600) {
141 /* Check whether the timestamp in the PCAP header and the VSS-Monitoring
142 * differ less than 30 days, otherwise, this might not be a VSS-Monitoring
143 * timestamp
145 if ( vssmonitoring_time.secs > pinfo->fd->abs_ts.secs ) {
146 if ( vssmonitoring_time.secs - pinfo->fd->abs_ts.secs > 2592000 ) /* 30 days */
147 return 0;
148 } else {
149 if ( pinfo->fd->abs_ts.secs - vssmonitoring_time.secs > 2592000 ) /* 30 days */
150 return 0;
154 /* The nanoseconds field should be less than 1000000000
156 if ( vssmonitoring_time.nsecs >= 1000000000 )
157 return 0;
161 /* All systems are go, lets dissect the VSS-Monitoring trailer */
162 if (tree) {
163 ti = proto_tree_add_item(tree, proto_vssmonitoring,
164 tvb, 0, (trailer_len & 0xb), ENC_NA);
165 vssmonitoring_tree = proto_item_add_subtree(ti, ett_vssmonitoring);
168 /* Do we have a timestamp? */
169 if ( trailer_len >= 8 ) {
170 if (tree) {
171 proto_tree_add_time(vssmonitoring_tree, hf_vssmonitoring_time, tvb, offset, 8, &vssmonitoring_time);
172 proto_tree_add_uint(vssmonitoring_tree, hf_vssmonitoring_clksrc, tvb, offset + 4, 1, vssmonitoring_clksrc);
174 tmp = localtime(&vssmonitoring_time.secs);
175 proto_item_append_text(ti, ", Timestamp: %02d:%02d:%02d.%09ld",
176 tmp->tm_hour, tmp->tm_min, tmp->tm_sec,(long)vssmonitoring_time.nsecs);
178 offset += 8;
181 /* Do we have a portstamp? */
182 if ( trailer_len & 3) {
183 if ( trailer_len & 1) {
184 vssmonitoring_srcport = (guint16)tvb_get_guint8(tvb, offset);
185 if (tree)
186 proto_tree_add_item(vssmonitoring_tree, hf_vssmonitoring_srcport, tvb, offset, 1, ENC_NA);
187 offset++;
188 } else if ( trailer_len & 2) {
189 vssmonitoring_srcport = tvb_get_ntohs(tvb, offset);
190 if (tree)
191 proto_tree_add_item(vssmonitoring_tree, hf_vssmonitoring_srcport, tvb, offset, 2, ENC_NA);
192 offset += 2;
194 if (tree)
195 proto_item_append_text(ti, ", Source Port: %d", vssmonitoring_srcport);
198 return offset;
201 void
202 proto_register_vssmonitoring(void)
204 static hf_register_info hf[] = {
205 { &hf_vssmonitoring_time, {
206 "Time Stamp", "vssmonitoring.time",
207 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0,
208 "VSS-Monitoring Time Stamp", HFILL }},
210 { &hf_vssmonitoring_clksrc, {
211 "Clock Source", "vssmonitoring.clksrc",
212 FT_UINT8, BASE_DEC, VALS(clksrc_vals), 0x0,
213 "VSS-Monitoring Clock Source", HFILL }},
215 { &hf_vssmonitoring_srcport, {
216 "Src Port", "vssmonitoring.srcport",
217 FT_UINT8, BASE_DEC, NULL, 0x0,
218 "VSS-Monitoring Source Port", HFILL }}
221 static gint *ett[] = {
222 &ett_vssmonitoring
225 module_t *vssmonitoring_module;
227 proto_vssmonitoring = proto_register_protocol("VSS-Monitoring ethernet trailer", "VSS-Monitoring", "vssmonitoring");
228 proto_register_field_array(proto_vssmonitoring, hf, array_length(hf));
229 proto_register_subtree_array(ett, array_length(ett));
231 vssmonitoring_module = prefs_register_protocol(proto_vssmonitoring, NULL);
233 prefs_register_bool_preference(vssmonitoring_module, "use_heuristics",
234 "Use heuristics to verify if trailer contains VSS-Monitoring data",
235 "When enabled, Wireshark will do a check on the trailer data to verify"
236 "whether it contains VSS-Monitoring time- and port-stamps.",
237 &vssmonitoring_use_heuristics);
240 void
241 proto_reg_handoff_vssmonitoring(void)
243 heur_dissector_add("eth.trailer", dissect_vssmonitoring, proto_vssmonitoring);