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
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
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" },
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
[] = {
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" },
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" },
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 */
119 static dissector_handle_t lsc_udp_handle
;
120 static dissector_handle_t lsc_tcp_handle
;
122 /* Code to actually dissect the packets */
124 dissect_lsc_common(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
127 proto_tree
*lsc_tree
;
130 unsigned expected_len
;
132 /* Too little data? */
133 if (tvb_captured_length(tvb
) < LSC_MIN_LEN
)
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 */
149 expected_len
= LSC_PAUSE_LEN
;
152 expected_len
= LSC_RESUME_LEN
;
155 expected_len
= LSC_STATUS_LEN
;
158 expected_len
= LSC_RESET_LEN
;
161 expected_len
= LSC_JUMP_LEN
;
164 expected_len
= LSC_PLAY_LEN
;
167 case LSC_PAUSE_REPLY
:
168 case LSC_RESUME_REPLY
:
169 case LSC_STATUS_REPLY
:
170 case LSC_RESET_REPLY
:
173 expected_len
= LSC_REPLY_LEN
;
176 /* Unrecognized op code */
177 expected_len
= LSC_MIN_LEN
;
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]");
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
);
196 proto_tree_add_item(lsc_tree
, hf_lsc_version
, tvb
, 0, 1, ENC_BIG_ENDIAN
);
199 proto_tree_add_item(lsc_tree
, hf_lsc_trans_id
, tvb
, 1, 1, ENC_BIG_ENDIAN
);
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
);
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 */
215 proto_tree_add_item(lsc_tree
, hf_lsc_stop_npt
, tvb
, 8, 4, ENC_BIG_ENDIAN
);
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
);
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
);
230 case LSC_PAUSE_REPLY
:
231 case LSC_RESUME_REPLY
:
232 case LSC_STATUS_REPLY
:
233 case LSC_RESET_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
);
246 return tvb_captured_length(tvb
);
249 /* Decode LSC over UDP */
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 */
258 get_lsc_pdu_len(packet_info
*pinfo _U_
, tvbuff_t
*tvb
, int offset
, void *data _U_
)
263 /* Get the op code */
264 op_code
= tvb_get_uint8(tvb
, offset
+ 2);
269 pdu_len
= LSC_PAUSE_LEN
;
272 pdu_len
= LSC_RESUME_LEN
;
275 pdu_len
= LSC_STATUS_LEN
;
278 pdu_len
= LSC_RESET_LEN
;
281 pdu_len
= LSC_JUMP_LEN
;
284 pdu_len
= LSC_PLAY_LEN
;
287 case LSC_PAUSE_REPLY
:
288 case LSC_RESUME_REPLY
:
289 case LSC_STATUS_REPLY
:
290 case LSC_RESET_REPLY
:
293 pdu_len
= LSC_REPLY_LEN
;
296 /* Unrecognized op code */
297 pdu_len
= LSC_OPCODE_LEN
;
304 /* Decode LSC over TCP */
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 */
315 proto_register_lsc(void)
317 /* Setup list of header fields */
318 static hf_register_info hf
[] = {
320 { "Version", "lsc.version",
321 FT_UINT8
, BASE_DEC
, NULL
, 0,
322 "Version of the Pegasus LSC protocol", HFILL
}
325 { "Transaction ID", "lsc.trans_id",
326 FT_UINT8
, BASE_DEC
, NULL
, 0,
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,
339 { &hf_lsc_stream_handle
,
340 { "Stream Handle", "lsc.stream_handle",
341 FT_UINT32
, BASE_DEC
, NULL
, 0,
342 "Stream identification handle", HFILL
}
345 { "Start NPT", "lsc.start_npt",
346 FT_INT32
, BASE_DEC
, NULL
, 0,
347 "Start Time (milliseconds)", HFILL
}
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
}
360 { "Scale Numerator", "lsc.scale_num",
361 FT_INT16
, BASE_DEC
, NULL
, 0,
364 { &hf_lsc_scale_denom
,
365 { "Scale Denominator", "lsc.scale_denum",
366 FT_UINT16
, BASE_DEC
, NULL
, 0,
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
[] = {
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
));
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
404 * indent-tabs-mode: nil
407 * ex: set shiftwidth=2 tabstop=8 expandtab:
408 * :indentSize=2:tabSize=8:noTabs=true: