Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-tsp.c
bloba09f9acb246a28d69838ba9a59f0882a30c62140
1 /* packet-tsp.c
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
15 #include "config.h"
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;
28 static int proto_tsp;
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;
37 static int ett_tsp;
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 */
45 { TSP_ANY, "any" },
46 #define TSP_ADJTIME 1 /* send adjtime */
47 { TSP_ADJTIME, "adjtime" },
48 #define TSP_ACK 2 /* generic acknowledgement */
49 { TSP_ACK, "ack" },
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 */
71 { TSP_QUIT, "quit" },
72 #define TSP_DATE 14 /* reset the time (date command) */
73 { TSP_DATE, "date" },
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 */
87 { TSP_TEST, "test" },
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 */
93 { TSP_LOOP, "loop" },
94 { 0, NULL }
98 static int
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;
104 uint8_t tsp_type;
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,
114 tvb, 0, -1, ENC_NA);
115 tsp_tree = proto_item_add_subtree(tsp_item, ett_tsp);
117 if (tsp_tree) {
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);
126 switch (tsp_type) {
128 case TSP_LOOP:
129 if (tsp_tree)
130 proto_tree_add_item(tsp_tree, hf_tsp_hopcnt,
131 tvb, 4, 1, ENC_BIG_ENDIAN);
132 break;
134 case TSP_SETTIME:
135 case TSP_ADJTIME:
136 case TSP_SETDATE:
137 case TSP_SETDATEREQ:
138 if (tsp_tree) {
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);
144 break;
147 if (tsp_tree) {
148 proto_tree_add_item(tsp_tree, hf_tsp_name, tvb, 12,
149 -1, ENC_ASCII);
151 return tvb_captured_length(tvb);
155 void
156 proto_reg_handoff_tsp(void)
158 dissector_add_uint_with_preference("udp.port", UDP_PORT_TIMED, tsp_handle);
162 void
163 proto_register_tsp(void)
165 static hf_register_info hf[] = {
166 { &hf_tsp_type,
167 { "Type", "tsp.type",
168 FT_UINT8, BASE_DEC, VALS(names_tsp_type), 0x0,
169 "Packet Type", HFILL }},
170 { &hf_tsp_vers,
171 { "Version", "tsp.version",
172 FT_UINT8, BASE_DEC, NULL, 0x0,
173 "Protocol Version Number", HFILL }},
174 { &hf_tsp_seq,
175 { "Sequence", "tsp.sequence",
176 FT_UINT16, BASE_DEC, NULL, 0x0,
177 "Sequence Number", HFILL }},
178 { &hf_tsp_hopcnt,
179 { "Hop Count", "tsp.hopcnt",
180 FT_UINT8, BASE_DEC, NULL, 0x0,
181 NULL, HFILL }},
182 { &hf_tsp_time_sec,
183 { "Seconds", "tsp.sec",
184 FT_UINT32, BASE_DEC, NULL, 0x0,
185 NULL, HFILL }},
186 { &hf_tsp_time_usec,
187 { "Microseconds", "tsp.usec",
188 FT_UINT32, BASE_DEC, NULL, 0x0,
189 NULL, HFILL }},
190 { &hf_tsp_name,
191 { "Machine Name", "tsp.name",
192 FT_STRINGZ, BASE_NONE, NULL, 0x0,
193 "Sender Machine Name", HFILL }}
195 static int *ett[] = {
196 &ett_tsp
199 proto_tsp = proto_register_protocol("Time Synchronization Protocol",
200 "TSP", "tsp");
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
209 * Local variables:
210 * c-basic-offset: 8
211 * tab-width: 8
212 * indent-tabs-mode: t
213 * End:
215 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
216 * :indentSize=8:tabSize=8:noTabs=false: