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 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include <epan/packet.h>
20 * For a full documentation of the Time Synchronization Protocol (TSP) see:
21 * http://docs.freebsd.org/44doc/smm/12.timed/paper.pdf
23 void proto_register_tsp(void);
24 void proto_reg_handoff_tsp(void);
26 static dissector_handle_t tsp_handle
;
29 static int hf_tsp_type
;
30 static int hf_tsp_vers
;
31 static int hf_tsp_seq
;
32 static int hf_tsp_hopcnt
;
33 static int hf_tsp_time_sec
;
34 static int hf_tsp_time_usec
;
35 static int hf_tsp_name
;
39 /* timed port from /etc/services */
40 #define UDP_PORT_TIMED 525
43 static const value_string names_tsp_type
[] = {
44 #define TSP_ANY 0 /* match any types */
46 #define TSP_ADJTIME 1 /* send adjtime */
47 { TSP_ADJTIME
, "adjtime" },
48 #define TSP_ACK 2 /* generic acknowledgement */
50 #define TSP_MASTERREQ 3 /* ask for master's name */
51 { TSP_MASTERREQ
, "masterreq" },
52 #define TSP_MASTERACK 4 /* acknowledge master request */
53 { TSP_MASTERACK
, "masterack" },
54 #define TSP_SETTIME 5 /* send network time */
55 { TSP_SETTIME
, "settime" },
56 #define TSP_MASTERUP 6 /* inform slaves that master is up */
57 { TSP_MASTERUP
, "masterup" },
58 #define TSP_SLAVEUP 7 /* slave is up but not polled */
59 { TSP_SLAVEUP
, "slaveup" },
60 #define TSP_ELECTION 8 /* advance candidature for master */
61 { TSP_ELECTION
, "election" },
62 #define TSP_ACCEPT 9 /* support candidature of master */
63 { TSP_ACCEPT
, "accept" },
64 #define TSP_REFUSE 10 /* reject candidature of master */
65 { TSP_REFUSE
, "refuse" },
66 #define TSP_CONFLICT 11 /* two or more masters present */
67 { TSP_CONFLICT
, "conflict" },
68 #define TSP_RESOLVE 12 /* masters' conflict resolution */
69 { TSP_RESOLVE
, "resolve" },
70 #define TSP_QUIT 13 /* reject candidature if master is up */
72 #define TSP_DATE 14 /* reset the time (date command) */
74 #define TSP_DATEREQ 15 /* remote request to reset the time */
75 { TSP_DATEREQ
, "datereq" },
76 #define TSP_DATEACK 16 /* acknowledge time setting */
77 { TSP_DATEACK
, "dateack" },
78 #define TSP_TRACEON 17 /* turn tracing on */
79 { TSP_TRACEON
, "traceon" },
80 #define TSP_TRACEOFF 18 /* turn tracing off */
81 { TSP_TRACEOFF
, "traceoff" },
82 #define TSP_MSITE 19 /* find out master's site */
83 { TSP_MSITE
, "msite" },
84 #define TSP_MSITEREQ 20 /* remote master's site request */
85 { TSP_MSITEREQ
, "msitereq" },
86 #define TSP_TEST 21 /* for testing election algo */
88 #define TSP_SETDATE 22 /* New from date command */
89 { TSP_SETDATE
, "setdate" },
90 #define TSP_SETDATEREQ 23 /* New remote for above */
91 { TSP_SETDATEREQ
, "setdatereq" },
92 #define TSP_LOOP 24 /* loop detection packet */
99 dissect_tsp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
101 proto_tree
*tsp_tree
;
102 proto_item
*tsp_item
;
106 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "TSP");
107 col_clear(pinfo
->cinfo
, COL_INFO
);
109 tsp_type
= tvb_get_uint8(tvb
, 0);
110 col_add_str(pinfo
->cinfo
, COL_INFO
,
111 val_to_str(tsp_type
, names_tsp_type
, "Unknown message type (%u)"));
113 tsp_item
= proto_tree_add_item(tree
, proto_tsp
,
115 tsp_tree
= proto_item_add_subtree(tsp_item
, ett_tsp
);
118 proto_tree_add_uint(tsp_tree
, hf_tsp_type
,
119 tvb
, 0, 1, tsp_type
);
120 proto_tree_add_item(tsp_tree
, hf_tsp_vers
,
121 tvb
, 1, 1, ENC_BIG_ENDIAN
);
122 proto_tree_add_item(tsp_tree
, hf_tsp_seq
,
123 tvb
, 2, 2, ENC_BIG_ENDIAN
);
130 proto_tree_add_item(tsp_tree
, hf_tsp_hopcnt
,
131 tvb
, 4, 1, ENC_BIG_ENDIAN
);
139 proto_tree_add_item(tsp_tree
, hf_tsp_time_sec
,
140 tvb
, 4, 4, ENC_BIG_ENDIAN
);
141 proto_tree_add_item(tsp_tree
, hf_tsp_time_usec
,
142 tvb
, 8, 4, ENC_BIG_ENDIAN
);
148 proto_tree_add_item(tsp_tree
, hf_tsp_name
, tvb
, 12,
151 return tvb_captured_length(tvb
);
156 proto_reg_handoff_tsp(void)
158 dissector_add_uint_with_preference("udp.port", UDP_PORT_TIMED
, tsp_handle
);
163 proto_register_tsp(void)
165 static hf_register_info hf
[] = {
167 { "Type", "tsp.type",
168 FT_UINT8
, BASE_DEC
, VALS(names_tsp_type
), 0x0,
169 "Packet Type", HFILL
}},
171 { "Version", "tsp.version",
172 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
173 "Protocol Version Number", HFILL
}},
175 { "Sequence", "tsp.sequence",
176 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
177 "Sequence Number", HFILL
}},
179 { "Hop Count", "tsp.hopcnt",
180 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
183 { "Seconds", "tsp.sec",
184 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
187 { "Microseconds", "tsp.usec",
188 FT_UINT32
, BASE_DEC
, NULL
, 0x0,
191 { "Machine Name", "tsp.name",
192 FT_STRINGZ
, BASE_NONE
, NULL
, 0x0,
193 "Sender Machine Name", HFILL
}}
195 static int *ett
[] = {
199 proto_tsp
= proto_register_protocol("Time Synchronization Protocol",
201 proto_register_field_array(proto_tsp
, hf
, array_length(hf
));
202 proto_register_subtree_array(ett
, array_length(ett
));
203 tsp_handle
= register_dissector("tsp", dissect_tsp
, proto_tsp
);
207 * Editor modelines - https://www.wireshark.org/tools/modelines.html
212 * indent-tabs-mode: t
215 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
216 * :indentSize=8:tabSize=8:noTabs=false: