Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-lsc.c
blob14244b074af1c7d3cf64bba5145abfd9e5926831
1 /* packet-lsc.c
2 * Routines for Pegasus LSC packet disassembly
3 * Copyright 2006, Sean Sheedy <seansh@users.sourceforge.net>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
16 #include "packet-tcp.h"
18 void proto_register_lsc(void);
19 void proto_reg_handoff_lsc(void);
21 #define LSC_PAUSE 0x01
22 #define LSC_RESUME 0x02
23 #define LSC_STATUS 0x03
24 #define LSC_RESET 0x04
25 #define LSC_JUMP 0x05
26 #define LSC_PLAY 0x06
27 #define LSC_DONE 0x40
28 #define LSC_PAUSE_REPLY 0x81
29 #define LSC_RESUME_REPLY 0x82
30 #define LSC_STATUS_REPLY 0x83
31 #define LSC_RESET_REPLY 0x84
32 #define LSC_JUMP_REPLY 0x85
33 #define LSC_PLAY_REPLY 0x86
35 #define isReply(o) ((o) & 0x80)
37 static const value_string op_code_vals[] = {
38 { LSC_PAUSE, "LSC_PAUSE" },
39 { LSC_RESUME, "LSC_RESUME" },
40 { LSC_STATUS, "LSC_STATUS" },
41 { LSC_RESET, "LSC_RESET" },
42 { LSC_JUMP, "LSC_JUMP" },
43 { LSC_PLAY, "LSC_PLAY" },
44 { LSC_DONE, "LSC_DONE" },
45 { LSC_PAUSE_REPLY, "LSC_PAUSE_REPLY" },
46 { LSC_RESUME_REPLY, "LSC_RESUME_REPLY" },
47 { LSC_STATUS_REPLY, "LSC_STATUS_REPLY" },
48 { LSC_RESET_REPLY, "LSC_RESET_REPLY" },
49 { LSC_JUMP_REPLY, "LSC_JUMP_REPLY" },
50 { LSC_PLAY_REPLY, "LSC_PLAY_REPLY" },
51 { 0, NULL }
54 #define LSC_OPCODE_LEN 3 /* Length to find op code */
55 #define LSC_MIN_LEN 8 /* Minimum packet length */
56 /* Length of each packet type */
57 #define LSC_PAUSE_LEN 12
58 #define LSC_RESUME_LEN 16
59 #define LSC_STATUS_LEN 8
60 #define LSC_RESET_LEN 8
61 #define LSC_JUMP_LEN 20
62 #define LSC_PLAY_LEN 20
63 #define LSC_REPLY_LEN 17
65 static const value_string status_code_vals[] = {
66 { 0x00, "LSC_OK" },
67 { 0x01, "TRICK_PLAY_NO_LONGER_CONSTRAINED" },
68 { 0x04, "TRICK_PLAY_CONSTRAINED" },
69 { 0x05, "SKIPPED_PLAYLIST_ITEM" },
70 { 0x10, "LSC_BAD_REQUEST" },
71 { 0x11, "LSC_BAD_STREAM" },
72 { 0x12, "LSC_WRONG_STATE" },
73 { 0x13, "LSC_UNKNOWN" },
74 { 0x14, "LSC_NO_PERMISSION" },
75 { 0x15, "LSC_BAD_PARAM" },
76 { 0x16, "LSC_NO_IMPLEMENT" },
77 { 0x17, "LSC_NO_MEMORY" },
78 { 0x18, "LSC_IMP_LIMIT" },
79 { 0x19, "LSC_TRANSIENT" },
80 { 0x1a, "LSC_NO_RESOURCES" },
81 { 0x20, "LSC_SERVER_ERROR" },
82 { 0x21, "LSC_SERVER_FAILURE" },
83 { 0x30, "LSC_BAD_SCALE" },
84 { 0x31, "LSC_BAD_START" },
85 { 0x32, "LSC_BAD_STOP" },
86 { 0x40, "LSC_MPEG_DELIVERY" },
87 { 0, NULL }
90 static const value_string mode_vals[] = {
91 { 0x00, "O - Open Mode" },
92 { 0x01, "P - Pause Mode" },
93 { 0x02, "ST - Search Transport" },
94 { 0x03, "T - Transport" },
95 { 0x04, "TP - Transport Pause" },
96 { 0x05, "STP - Search Transport Pause" },
97 { 0x06, "PST - Pause Search Transport" },
98 { 0x07, "EOS - End of Stream" },
99 { 0, NULL }
102 /* Initialize the protocol and registered fields */
103 static int proto_lsc;
104 static int hf_lsc_version;
105 static int hf_lsc_trans_id;
106 static int hf_lsc_op_code;
107 static int hf_lsc_status_code;
108 static int hf_lsc_stream_handle;
109 static int hf_lsc_start_npt;
110 static int hf_lsc_stop_npt;
111 static int hf_lsc_current_npt;
112 static int hf_lsc_scale_num;
113 static int hf_lsc_scale_denom;
114 static int hf_lsc_mode;
116 /* Initialize the subtree pointers */
117 static int ett_lsc;
119 static dissector_handle_t lsc_udp_handle;
120 static dissector_handle_t lsc_tcp_handle;
122 /* Code to actually dissect the packets */
123 static int
124 dissect_lsc_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
126 proto_item *ti;
127 proto_tree *lsc_tree;
128 uint8_t op_code;
129 uint32_t stream;
130 unsigned expected_len;
132 /* Too little data? */
133 if (tvb_captured_length(tvb) < LSC_MIN_LEN)
134 return 0;
136 /* Protocol is LSC, packet summary is not yet known */
137 col_set_str(pinfo->cinfo, COL_PROTOCOL, "LSC");
138 col_clear(pinfo->cinfo, COL_INFO);
140 /* Get the op code */
141 op_code = tvb_get_uint8(tvb, 2);
142 /* And the stream handle */
143 stream = tvb_get_ntohl(tvb, 4);
145 /* Check the data length against what we actually received */
146 switch (op_code)
148 case LSC_PAUSE:
149 expected_len = LSC_PAUSE_LEN;
150 break;
151 case LSC_RESUME:
152 expected_len = LSC_RESUME_LEN;
153 break;
154 case LSC_STATUS:
155 expected_len = LSC_STATUS_LEN;
156 break;
157 case LSC_RESET:
158 expected_len = LSC_RESET_LEN;
159 break;
160 case LSC_JUMP:
161 expected_len = LSC_JUMP_LEN;
162 break;
163 case LSC_PLAY:
164 expected_len = LSC_PLAY_LEN;
165 break;
166 case LSC_DONE:
167 case LSC_PAUSE_REPLY:
168 case LSC_RESUME_REPLY:
169 case LSC_STATUS_REPLY:
170 case LSC_RESET_REPLY:
171 case LSC_JUMP_REPLY:
172 case LSC_PLAY_REPLY:
173 expected_len = LSC_REPLY_LEN;
174 break;
175 default:
176 /* Unrecognized op code */
177 expected_len = LSC_MIN_LEN;
178 break;
181 /* Display the op code in the summary */
182 col_add_fstr(pinfo->cinfo, COL_INFO, "%s, session %.8u",
183 val_to_str(op_code, op_code_vals, "Unknown op code (0x%x)"), stream);
185 if (tvb_reported_length(tvb) < expected_len)
186 col_append_str(pinfo->cinfo, COL_INFO, " [Too short]");
187 else if (tvb_reported_length(tvb) > expected_len)
188 col_append_str(pinfo->cinfo, COL_INFO, " [Too long]");
190 if (tree) {
191 /* Create display subtree for the protocol */
192 ti = proto_tree_add_item(tree, proto_lsc, tvb, 0, -1, ENC_NA);
193 lsc_tree = proto_item_add_subtree(ti, ett_lsc);
195 /* LSC Version */
196 proto_tree_add_item(lsc_tree, hf_lsc_version, tvb, 0, 1, ENC_BIG_ENDIAN);
198 /* Transaction ID */
199 proto_tree_add_item(lsc_tree, hf_lsc_trans_id, tvb, 1, 1, ENC_BIG_ENDIAN);
201 /* Op Code */
202 proto_tree_add_uint(lsc_tree, hf_lsc_op_code, tvb, 2, 1, op_code);
204 /* Only replies and LSC_DONE contain a status code */
205 if (isReply(op_code) || op_code==LSC_DONE)
206 proto_tree_add_item(lsc_tree, hf_lsc_status_code, tvb, 3, 1, ENC_BIG_ENDIAN);
208 /* Stream Handle */
209 proto_tree_add_uint_format_value(lsc_tree, hf_lsc_stream_handle, tvb, 4, 4, stream, "%.8u", stream);
211 /* Add op code specific parts */
212 switch (op_code)
214 case LSC_PAUSE:
215 proto_tree_add_item(lsc_tree, hf_lsc_stop_npt, tvb, 8, 4, ENC_BIG_ENDIAN);
216 break;
217 case LSC_RESUME:
218 proto_tree_add_item(lsc_tree, hf_lsc_start_npt, tvb, 8, 4, ENC_BIG_ENDIAN);
219 proto_tree_add_item(lsc_tree, hf_lsc_scale_num, tvb, 12, 2, ENC_BIG_ENDIAN);
220 proto_tree_add_item(lsc_tree, hf_lsc_scale_denom, tvb, 14, 2, ENC_BIG_ENDIAN);
221 break;
222 case LSC_JUMP:
223 case LSC_PLAY:
224 proto_tree_add_item(lsc_tree, hf_lsc_start_npt, tvb, 8, 4, ENC_BIG_ENDIAN);
225 proto_tree_add_item(lsc_tree, hf_lsc_stop_npt, tvb, 12, 4, ENC_BIG_ENDIAN);
226 proto_tree_add_item(lsc_tree, hf_lsc_scale_num, tvb, 16, 2, ENC_BIG_ENDIAN);
227 proto_tree_add_item(lsc_tree, hf_lsc_scale_denom, tvb, 18, 2, ENC_BIG_ENDIAN);
228 break;
229 case LSC_DONE:
230 case LSC_PAUSE_REPLY:
231 case LSC_RESUME_REPLY:
232 case LSC_STATUS_REPLY:
233 case LSC_RESET_REPLY:
234 case LSC_JUMP_REPLY:
235 case LSC_PLAY_REPLY:
236 proto_tree_add_item(lsc_tree, hf_lsc_current_npt, tvb, 8, 4, ENC_BIG_ENDIAN);
237 proto_tree_add_item(lsc_tree, hf_lsc_scale_num, tvb, 12, 2, ENC_BIG_ENDIAN);
238 proto_tree_add_item(lsc_tree, hf_lsc_scale_denom, tvb, 14, 2, ENC_BIG_ENDIAN);
239 proto_tree_add_item(lsc_tree, hf_lsc_mode, tvb, 16, 1, ENC_BIG_ENDIAN);
240 break;
241 default:
242 break;
246 return tvb_captured_length(tvb);
249 /* Decode LSC over UDP */
250 static int
251 dissect_lsc_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
253 return dissect_lsc_common(tvb, pinfo, tree, data);
256 /* Determine length of LSC message */
257 static unsigned
258 get_lsc_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
260 uint8_t op_code;
261 unsigned pdu_len;
263 /* Get the op code */
264 op_code = tvb_get_uint8(tvb, offset + 2);
266 switch (op_code)
268 case LSC_PAUSE:
269 pdu_len = LSC_PAUSE_LEN;
270 break;
271 case LSC_RESUME:
272 pdu_len = LSC_RESUME_LEN;
273 break;
274 case LSC_STATUS:
275 pdu_len = LSC_STATUS_LEN;
276 break;
277 case LSC_RESET:
278 pdu_len = LSC_RESET_LEN;
279 break;
280 case LSC_JUMP:
281 pdu_len = LSC_JUMP_LEN;
282 break;
283 case LSC_PLAY:
284 pdu_len = LSC_PLAY_LEN;
285 break;
286 case LSC_DONE:
287 case LSC_PAUSE_REPLY:
288 case LSC_RESUME_REPLY:
289 case LSC_STATUS_REPLY:
290 case LSC_RESET_REPLY:
291 case LSC_JUMP_REPLY:
292 case LSC_PLAY_REPLY:
293 pdu_len = LSC_REPLY_LEN;
294 break;
295 default:
296 /* Unrecognized op code */
297 pdu_len = LSC_OPCODE_LEN;
298 break;
301 return pdu_len;
304 /* Decode LSC over TCP */
305 static int
306 dissect_lsc_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
308 tcp_dissect_pdus(tvb, pinfo, tree, true, LSC_OPCODE_LEN, get_lsc_pdu_len,
309 dissect_lsc_common, data);
310 return tvb_captured_length(tvb);
313 /* Register the protocol with Wireshark */
314 void
315 proto_register_lsc(void)
317 /* Setup list of header fields */
318 static hf_register_info hf[] = {
319 { &hf_lsc_version,
320 { "Version", "lsc.version",
321 FT_UINT8, BASE_DEC, NULL, 0,
322 "Version of the Pegasus LSC protocol", HFILL }
324 { &hf_lsc_trans_id,
325 { "Transaction ID", "lsc.trans_id",
326 FT_UINT8, BASE_DEC, NULL, 0,
327 NULL, HFILL }
329 { &hf_lsc_op_code,
330 { "Op Code", "lsc.op_code",
331 FT_UINT8, BASE_HEX, VALS(op_code_vals), 0,
332 "Operation Code", HFILL }
334 { &hf_lsc_status_code,
335 { "Status Code", "lsc.status_code",
336 FT_UINT8, BASE_HEX, VALS(status_code_vals), 0,
337 NULL, HFILL }
339 { &hf_lsc_stream_handle,
340 { "Stream Handle", "lsc.stream_handle",
341 FT_UINT32, BASE_DEC, NULL, 0,
342 "Stream identification handle", HFILL }
344 { &hf_lsc_start_npt,
345 { "Start NPT", "lsc.start_npt",
346 FT_INT32, BASE_DEC, NULL, 0,
347 "Start Time (milliseconds)", HFILL }
349 { &hf_lsc_stop_npt,
350 { "Stop NPT", "lsc.stop_npt",
351 FT_INT32, BASE_DEC, NULL, 0,
352 "Stop Time (milliseconds)", HFILL }
354 { &hf_lsc_current_npt,
355 { "Current NPT", "lsc.current_npt",
356 FT_INT32, BASE_DEC, NULL, 0,
357 "Current Time (milliseconds)", HFILL }
359 { &hf_lsc_scale_num,
360 { "Scale Numerator", "lsc.scale_num",
361 FT_INT16, BASE_DEC, NULL, 0,
362 NULL, HFILL }
364 { &hf_lsc_scale_denom,
365 { "Scale Denominator", "lsc.scale_denum",
366 FT_UINT16, BASE_DEC, NULL, 0,
367 NULL, HFILL }
369 { &hf_lsc_mode,
370 { "Server Mode", "lsc.mode",
371 FT_UINT8, BASE_HEX, VALS(mode_vals), 0,
372 "Current Server Mode", HFILL }
376 /* Setup protocol subtree array */
377 static int *ett[] = {
378 &ett_lsc,
381 /* Register the protocol name and description */
382 proto_lsc = proto_register_protocol("Pegasus Lightweight Stream Control", "LSC", "lsc");
383 lsc_udp_handle = register_dissector("lsc_udp", dissect_lsc_udp, proto_lsc);
384 lsc_tcp_handle = register_dissector("lsc_tcp", dissect_lsc_tcp, proto_lsc);
386 /* Required function calls to register the header fields and subtrees used */
387 proto_register_field_array(proto_lsc, hf, array_length(hf));
388 proto_register_subtree_array(ett, array_length(ett));
391 void
392 proto_reg_handoff_lsc(void)
394 dissector_add_for_decode_as_with_preference("udp.port", lsc_udp_handle);
395 dissector_add_for_decode_as_with_preference("tcp.port", lsc_tcp_handle);
399 * Editor modelines - https://www.wireshark.org/tools/modelines.html
401 * Local Variables:
402 * c-basic-offset: 2
403 * tab-width: 8
404 * indent-tabs-mode: nil
405 * End:
407 * ex: set shiftwidth=2 tabstop=8 expandtab:
408 * :indentSize=2:tabSize=8:noTabs=true: