2 * Routines for Time Synchronization Protocol (TSP) packet dissection
4 * Uwe Girlich <Uwe.Girlich@philosys.de>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-quake.c
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
33 * For a full documentation of the Time Synchronization Protocol (TSP) see:
34 * http://docs.freebsd.org/44doc/smm/12.timed/paper.pdf
36 void proto_register_tsp(void);
37 void proto_reg_handoff_tsp(void);
39 static int proto_tsp = -1;
40 static int hf_tsp_type = -1;
41 static int hf_tsp_vers = -1;
42 static int hf_tsp_seq = -1;
43 static int hf_tsp_hopcnt = -1;
44 static int hf_tsp_time_sec = -1;
45 static int hf_tsp_time_usec = -1;
46 static int hf_tsp_name = -1;
48 static gint ett_tsp = -1;
50 /* timed port from /etc/services */
51 #define UDP_PORT_TIMED 525
54 static const value_string names_tsp_type[] = {
55 #define TSP_ANY 0 /* match any types */
57 #define TSP_ADJTIME 1 /* send adjtime */
58 { TSP_ADJTIME, "adjtime" },
59 #define TSP_ACK 2 /* generic acknowledgement */
61 #define TSP_MASTERREQ 3 /* ask for master's name */
62 { TSP_MASTERREQ, "masterreq" },
63 #define TSP_MASTERACK 4 /* acknowledge master request */
64 { TSP_MASTERACK, "masterack" },
65 #define TSP_SETTIME 5 /* send network time */
66 { TSP_SETTIME, "settime" },
67 #define TSP_MASTERUP 6 /* inform slaves that master is up */
68 { TSP_MASTERUP, "masterup" },
69 #define TSP_SLAVEUP 7 /* slave is up but not polled */
70 { TSP_SLAVEUP, "slaveup" },
71 #define TSP_ELECTION 8 /* advance candidature for master */
72 { TSP_ELECTION, "election" },
73 #define TSP_ACCEPT 9 /* support candidature of master */
74 { TSP_ACCEPT, "accept" },
75 #define TSP_REFUSE 10 /* reject candidature of master */
76 { TSP_REFUSE, "refuse" },
77 #define TSP_CONFLICT 11 /* two or more masters present */
78 { TSP_CONFLICT, "conflict" },
79 #define TSP_RESOLVE 12 /* masters' conflict resolution */
80 { TSP_RESOLVE, "resolve" },
81 #define TSP_QUIT 13 /* reject candidature if master is up */
83 #define TSP_DATE 14 /* reset the time (date command) */
85 #define TSP_DATEREQ 15 /* remote request to reset the time */
86 { TSP_DATEREQ, "datereq" },
87 #define TSP_DATEACK 16 /* acknowledge time setting */
88 { TSP_DATEACK, "dateack" },
89 #define TSP_TRACEON 17 /* turn tracing on */
90 { TSP_TRACEON, "traceon" },
91 #define TSP_TRACEOFF 18 /* turn tracing off */
92 { TSP_TRACEOFF, "traceoff" },
93 #define TSP_MSITE 19 /* find out master's site */
94 { TSP_MSITE, "msite" },
95 #define TSP_MSITEREQ 20 /* remote master's site request */
96 { TSP_MSITEREQ, "msitereq" },
97 #define TSP_TEST 21 /* for testing election algo */
99 #define TSP_SETDATE 22 /* New from date command */
100 { TSP_SETDATE, "setdate" },
101 #define TSP_SETDATEREQ 23 /* New remote for above */
102 { TSP_SETDATEREQ, "setdatereq" },
103 #define TSP_LOOP 24 /* loop detection packet */
104 { TSP_LOOP, "loop" },
110 dissect_tsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
112 proto_tree *tsp_tree = NULL;
113 proto_item *tsp_item = NULL;
117 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TSP");
118 col_clear(pinfo->cinfo, COL_INFO);
120 tsp_type = tvb_get_guint8(tvb, 0);
121 col_add_str(pinfo->cinfo, COL_INFO,
122 val_to_str(tsp_type, names_tsp_type, "Unknown message type (%u)"));
125 tsp_item = proto_tree_add_item(tree, proto_tsp,
128 tsp_tree = proto_item_add_subtree(tsp_item, ett_tsp);
132 proto_tree_add_uint(tsp_tree, hf_tsp_type,
133 tvb, 0, 1, tsp_type);
134 proto_tree_add_item(tsp_tree, hf_tsp_vers,
135 tvb, 1, 1, ENC_BIG_ENDIAN);
136 proto_tree_add_item(tsp_tree, hf_tsp_seq,
137 tvb, 2, 2, ENC_BIG_ENDIAN);
144 proto_tree_add_item(tsp_tree, hf_tsp_hopcnt,
145 tvb, 4, 1, ENC_BIG_ENDIAN);
153 proto_tree_add_item(tsp_tree, hf_tsp_time_sec,
154 tvb, 4, 4, ENC_BIG_ENDIAN);
155 proto_tree_add_item(tsp_tree, hf_tsp_time_usec,
156 tvb, 8, 4, ENC_BIG_ENDIAN);
162 proto_tree_add_item(tsp_tree, hf_tsp_name, tvb, 12,
163 -1, ENC_ASCII|ENC_NA);
169 proto_reg_handoff_tsp(void)
171 dissector_handle_t tsp_handle;
173 tsp_handle = create_dissector_handle(dissect_tsp, proto_tsp);
174 dissector_add_uint("udp.port", UDP_PORT_TIMED, tsp_handle);
179 proto_register_tsp(void)
181 static hf_register_info hf[] = {
183 { "Type", "tsp.type",
184 FT_UINT8, BASE_DEC, VALS(names_tsp_type), 0x0,
185 "Packet Type", HFILL }},
187 { "Version", "tsp.version",
188 FT_UINT8, BASE_DEC, NULL, 0x0,
189 "Protocol Version Number", HFILL }},
191 { "Sequence", "tsp.sequence",
192 FT_UINT16, BASE_DEC, NULL, 0x0,
193 "Sequence Number", HFILL }},
195 { "Hop Count", "tsp.hopcnt",
196 FT_UINT8, BASE_DEC, NULL, 0x0,
199 { "Seconds", "tsp.sec",
200 FT_UINT32, BASE_DEC, NULL, 0x0,
203 { "Microseconds", "tsp.usec",
204 FT_UINT32, BASE_DEC, NULL, 0x0,
207 { "Machine Name", "tsp.name",
208 FT_STRINGZ, BASE_NONE, NULL, 0x0,
209 "Sender Machine Name", HFILL }}
211 static gint *ett[] = {
215 proto_tsp = proto_register_protocol("Time Synchronization Protocol",
217 proto_register_field_array(proto_tsp, hf, array_length(hf));
218 proto_register_subtree_array(ett, array_length(ett));