2 * Routines for Pegasus LSC packet disassembly
3 * Copyright 2006, Sean Sheedy <seansh@users.sourceforge.net>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
31 #include <epan/prefs.h>
33 #include <packet-tcp.h>
35 /* Forward declaration we need below */
36 void proto_reg_handoff_lsc(void);
38 #define LSC_PAUSE 0x01
39 #define LSC_RESUME 0x02
40 #define LSC_STATUS 0x03
41 #define LSC_RESET 0x04
45 #define LSC_PAUSE_REPLY 0x81
46 #define LSC_RESUME_REPLY 0x82
47 #define LSC_STATUS_REPLY 0x83
48 #define LSC_RESET_REPLY 0x84
49 #define LSC_JUMP_REPLY 0x85
50 #define LSC_PLAY_REPLY 0x86
52 #define isReply(o) ((o) & 0x80)
54 static const value_string op_code_vals
[] = {
55 { LSC_PAUSE
, "LSC_PAUSE" },
56 { LSC_RESUME
, "LSC_RESUME" },
57 { LSC_STATUS
, "LSC_STATUS" },
58 { LSC_RESET
, "LSC_RESET" },
59 { LSC_JUMP
, "LSC_JUMP" },
60 { LSC_PLAY
, "LSC_PLAY" },
61 { LSC_DONE
, "LSC_DONE" },
62 { LSC_PAUSE_REPLY
, "LSC_PAUSE_REPLY" },
63 { LSC_RESUME_REPLY
, "LSC_RESUME_REPLY" },
64 { LSC_STATUS_REPLY
, "LSC_STATUS_REPLY" },
65 { LSC_RESET_REPLY
, "LSC_RESET_REPLY" },
66 { LSC_JUMP_REPLY
, "LSC_JUMP_REPLY" },
67 { LSC_PLAY_REPLY
, "LSC_PLAY_REPLY" },
71 #define LSC_OPCODE_LEN 3 /* Length to find op code */
72 #define LSC_MIN_LEN 8 /* Minimum packet length */
73 /* Length of each packet type */
74 #define LSC_PAUSE_LEN 12
75 #define LSC_RESUME_LEN 16
76 #define LSC_STATUS_LEN 8
77 #define LSC_RESET_LEN 8
78 #define LSC_JUMP_LEN 20
79 #define LSC_PLAY_LEN 20
80 #define LSC_REPLY_LEN 17
82 static const value_string status_code_vals
[] = {
84 { 0x10, "LSC_BAD_REQUEST" },
85 { 0x11, "LSC_BAD_STREAM" },
86 { 0x12, "LSC_WRONG_STATE" },
87 { 0x13, "LSC_UNKNOWN" },
88 { 0x14, "LSC_NO_PERMISSION" },
89 { 0x15, "LSC_BAD_PARAM" },
90 { 0x16, "LSC_NO_IMPLEMENT" },
91 { 0x17, "LSC_NO_MEMORY" },
92 { 0x18, "LSC_IMP_LIMIT" },
93 { 0x19, "LSC_TRANSIENT" },
94 { 0x1a, "LSC_NO_RESOURCES" },
95 { 0x20, "LSC_SERVER_ERROR" },
96 { 0x21, "LSC_SERVER_FAILURE" },
97 { 0x30, "LSC_BAD_SCALE" },
98 { 0x31, "LSC_BAD_START" },
99 { 0x32, "LSC_BAD_STOP" },
100 { 0x40, "LSC_MPEG_DELIVERY" },
104 static const value_string mode_vals
[] = {
105 { 0x00, "O - Open Mode" },
106 { 0x01, "P - Pause Mode" },
107 { 0x02, "ST - Search Transport" },
108 { 0x03, "T - Transport" },
109 { 0x04, "TP - Transport Pause" },
110 { 0x05, "STP - Search Transport Pause" },
111 { 0x06, "PST - Pause Search Transport" },
112 { 0x07, "EOS - End of Stream" },
116 /* Initialize the protocol and registered fields */
117 static int proto_lsc
= -1;
118 static int hf_lsc_version
= -1;
119 static int hf_lsc_trans_id
= -1;
120 static int hf_lsc_op_code
= -1;
121 static int hf_lsc_status_code
= -1;
122 static int hf_lsc_stream_handle
= -1;
123 static int hf_lsc_start_npt
= -1;
124 static int hf_lsc_stop_npt
= -1;
125 static int hf_lsc_current_npt
= -1;
126 static int hf_lsc_scale_num
= -1;
127 static int hf_lsc_scale_denom
= -1;
128 static int hf_lsc_mode
= -1;
131 static guint global_lsc_port
= 0;
133 /* Initialize the subtree pointers */
134 static gint ett_lsc
= -1;
136 /* Code to actually dissect the packets */
138 dissect_lsc_common(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
141 proto_tree
*lsc_tree
;
146 /* Protocol is LSC, packet summary is not yet known */
147 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "LSC");
148 col_clear(pinfo
->cinfo
, COL_INFO
);
150 /* Too little data? */
151 if (tvb_length(tvb
) < LSC_MIN_LEN
)
153 col_set_str(pinfo
->cinfo
, COL_INFO
, "[Too short]");
157 /* Get the op code */
158 op_code
= tvb_get_guint8(tvb
, 2);
159 /* And the stream handle */
160 stream
= tvb_get_ntohl(tvb
, 4);
162 /* Check the data length against what we actually received */
166 expected_len
= LSC_PAUSE_LEN
;
169 expected_len
= LSC_RESUME_LEN
;
172 expected_len
= LSC_STATUS_LEN
;
175 expected_len
= LSC_RESET_LEN
;
178 expected_len
= LSC_JUMP_LEN
;
181 expected_len
= LSC_PLAY_LEN
;
184 case LSC_PAUSE_REPLY
:
185 case LSC_RESUME_REPLY
:
186 case LSC_STATUS_REPLY
:
187 case LSC_RESET_REPLY
:
190 expected_len
= LSC_REPLY_LEN
;
193 /* Unrecognized op code */
194 expected_len
= LSC_MIN_LEN
;
198 /* Display the op code in the summary */
199 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "%s, session %.8u",
200 val_to_str(op_code
, op_code_vals
, "Unknown op code (0x%x)"),
203 if (tvb_length(tvb
) < expected_len
)
204 col_append_str(pinfo
->cinfo
, COL_INFO
, " [Too short]");
205 else if (tvb_length(tvb
) > expected_len
)
206 col_append_str(pinfo
->cinfo
, COL_INFO
, " [Too long]");
209 /* Create display subtree for the protocol */
210 ti
= proto_tree_add_item(tree
, proto_lsc
, tvb
, 0, -1, ENC_NA
);
211 lsc_tree
= proto_item_add_subtree(ti
, ett_lsc
);
213 /* Add already fetched items to the tree */
214 proto_tree_add_uint(lsc_tree
, hf_lsc_op_code
, tvb
, 2, 1, op_code
);
215 proto_tree_add_uint_format_value(lsc_tree
, hf_lsc_stream_handle
, tvb
, 4, 4,
216 stream
, "%.8u", stream
);
218 /* Add rest of LSC header */
219 proto_tree_add_uint(lsc_tree
, hf_lsc_version
, tvb
, 0, 1,
220 tvb_get_guint8(tvb
, 0));
221 proto_tree_add_uint(lsc_tree
, hf_lsc_trans_id
, tvb
, 1, 1,
222 tvb_get_guint8(tvb
, 1));
224 /* Only replies contain a status code */
225 if (isReply(op_code
))
226 proto_tree_add_uint(lsc_tree
, hf_lsc_status_code
, tvb
, 3, 1,
227 tvb_get_guint8(tvb
, 3));
229 /* Add op code specific parts */
233 proto_tree_add_int(lsc_tree
, hf_lsc_stop_npt
, tvb
, 8, 4,
234 tvb_get_ntohl(tvb
, 8));
237 proto_tree_add_int(lsc_tree
, hf_lsc_start_npt
, tvb
, 8, 4,
238 tvb_get_ntohl(tvb
, 8));
239 proto_tree_add_int(lsc_tree
, hf_lsc_scale_num
, tvb
, 12, 2,
240 tvb_get_ntohs(tvb
, 12));
241 proto_tree_add_uint(lsc_tree
, hf_lsc_scale_denom
, tvb
, 14, 2,
242 tvb_get_ntohs(tvb
, 14));
246 proto_tree_add_int(lsc_tree
, hf_lsc_start_npt
, tvb
, 8, 4,
247 tvb_get_ntohl(tvb
, 8));
248 proto_tree_add_int(lsc_tree
, hf_lsc_stop_npt
, tvb
, 12, 4,
249 tvb_get_ntohl(tvb
, 12));
250 proto_tree_add_int(lsc_tree
, hf_lsc_scale_num
, tvb
, 16, 2,
251 tvb_get_ntohs(tvb
, 16));
252 proto_tree_add_uint(lsc_tree
, hf_lsc_scale_denom
, tvb
, 18, 2,
253 tvb_get_ntohs(tvb
, 18));
256 case LSC_PAUSE_REPLY
:
257 case LSC_RESUME_REPLY
:
258 case LSC_STATUS_REPLY
:
259 case LSC_RESET_REPLY
:
262 proto_tree_add_int(lsc_tree
, hf_lsc_current_npt
, tvb
, 8, 4,
263 tvb_get_ntohl(tvb
, 8));
264 proto_tree_add_int(lsc_tree
, hf_lsc_scale_num
, tvb
, 12, 2,
265 tvb_get_ntohs(tvb
, 12));
266 proto_tree_add_uint(lsc_tree
, hf_lsc_scale_denom
, tvb
, 14, 2,
267 tvb_get_ntohs(tvb
, 14));
268 proto_tree_add_uint(lsc_tree
, hf_lsc_mode
, tvb
, 16, 1,
269 tvb_get_guint8(tvb
, 16));
276 return tvb_length(tvb
);
279 /* Decode LSC over UDP */
281 dissect_lsc_udp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
283 return dissect_lsc_common(tvb
, pinfo
, tree
, data
);
286 /* Determine length of LSC message */
288 get_lsc_pdu_len(packet_info
*pinfo _U_
, tvbuff_t
*tvb
, int offset
)
293 /* Get the op code */
294 op_code
= tvb_get_guint8(tvb
, offset
+ 2);
299 pdu_len
= LSC_PAUSE_LEN
;
302 pdu_len
= LSC_RESUME_LEN
;
305 pdu_len
= LSC_STATUS_LEN
;
308 pdu_len
= LSC_RESET_LEN
;
311 pdu_len
= LSC_JUMP_LEN
;
314 pdu_len
= LSC_PLAY_LEN
;
317 case LSC_PAUSE_REPLY
:
318 case LSC_RESUME_REPLY
:
319 case LSC_STATUS_REPLY
:
320 case LSC_RESET_REPLY
:
323 pdu_len
= LSC_REPLY_LEN
;
326 /* Unrecognized op code */
327 pdu_len
= LSC_OPCODE_LEN
;
334 /* Decode LSC over TCP */
336 dissect_lsc_tcp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
338 tcp_dissect_pdus(tvb
, pinfo
, tree
, TRUE
, LSC_OPCODE_LEN
, get_lsc_pdu_len
,
339 dissect_lsc_common
, data
);
340 return tvb_length(tvb
);
343 /* Register the protocol with Wireshark */
345 proto_register_lsc(void)
347 module_t
*lsc_module
;
349 /* Setup list of header fields */
350 static hf_register_info hf
[] = {
352 { "Version", "lsc.version",
353 FT_UINT8
, BASE_DEC
, NULL
, 0,
354 "Version of the Pegasus LSC protocol", HFILL
}
357 { "Transaction ID", "lsc.trans_id",
358 FT_UINT8
, BASE_DEC
, NULL
, 0,
362 { "Op Code", "lsc.op_code",
363 FT_UINT8
, BASE_HEX
, VALS(op_code_vals
), 0,
364 "Operation Code", HFILL
}
366 { &hf_lsc_status_code
,
367 { "Status Code", "lsc.status_code",
368 FT_UINT8
, BASE_HEX
, VALS(status_code_vals
), 0,
371 { &hf_lsc_stream_handle
,
372 { "Stream Handle", "lsc.stream_handle",
373 FT_UINT32
, BASE_DEC
, NULL
, 0,
374 "Stream identification handle", HFILL
}
377 { "Start NPT", "lsc.start_npt",
378 FT_INT32
, BASE_DEC
, NULL
, 0,
379 "Start Time (milliseconds)", HFILL
}
382 { "Stop NPT", "lsc.stop_npt",
383 FT_INT32
, BASE_DEC
, NULL
, 0,
384 "Stop Time (milliseconds)", HFILL
}
386 { &hf_lsc_current_npt
,
387 { "Current NPT", "lsc.current_npt",
388 FT_INT32
, BASE_DEC
, NULL
, 0,
389 "Current Time (milliseconds)", HFILL
}
392 { "Scale Numerator", "lsc.scale_num",
393 FT_INT16
, BASE_DEC
, NULL
, 0,
396 { &hf_lsc_scale_denom
,
397 { "Scale Denominator", "lsc.scale_denum",
398 FT_UINT16
, BASE_DEC
, NULL
, 0,
402 { "Server Mode", "lsc.mode",
403 FT_UINT8
, BASE_HEX
, VALS(mode_vals
), 0,
404 "Current Server Mode", HFILL
}
408 /* Setup protocol subtree array */
409 static gint
*ett
[] = {
413 /* Register the protocol name and description */
414 proto_lsc
= proto_register_protocol("Pegasus Lightweight Stream Control",
417 /* Required function calls to register the header fields and subtrees used */
418 proto_register_field_array(proto_lsc
, hf
, array_length(hf
));
419 proto_register_subtree_array(ett
, array_length(ett
));
421 /* Register preferences module */
422 lsc_module
= prefs_register_protocol(proto_lsc
, proto_reg_handoff_lsc
);
424 /* Register preferences */
425 prefs_register_uint_preference(lsc_module
, "port",
427 "Set the TCP or UDP port for Pegasus LSC messages",
428 10, &global_lsc_port
);
432 proto_reg_handoff_lsc(void)
434 static gboolean initialized
= FALSE
;
435 static dissector_handle_t lsc_udp_handle
;
436 static dissector_handle_t lsc_tcp_handle
;
437 static guint saved_lsc_port
;
440 lsc_udp_handle
= new_create_dissector_handle(dissect_lsc_udp
, proto_lsc
);
441 lsc_tcp_handle
= new_create_dissector_handle(dissect_lsc_tcp
, proto_lsc
);
442 dissector_add_handle("udp.port", lsc_udp_handle
); /* for 'decode-as' */
443 dissector_add_handle("tcp.port", lsc_tcp_handle
); /* ... */
446 if (saved_lsc_port
!= 0) {
447 dissector_delete_uint("udp.port", saved_lsc_port
, lsc_udp_handle
);
448 dissector_delete_uint("tcp.port", saved_lsc_port
, lsc_tcp_handle
);
452 /* Set the port number */
453 if (global_lsc_port
!= 0) {
454 dissector_add_uint("udp.port", global_lsc_port
, lsc_udp_handle
);
455 dissector_add_uint("tcp.port", global_lsc_port
, lsc_tcp_handle
);
457 saved_lsc_port
= global_lsc_port
;