diff options
author | Anders Broman <anders.broman@ericsson.com> | 2012-03-13 08:57:04 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2012-03-13 08:57:04 +0000 |
commit | 45c342dfdb999404e356724ca8b594af3529a0a7 (patch) | |
tree | 2ecfd3bf12ce2d4a345ab9280a92db6066f6719c /epan/dissectors | |
parent | bb611755e98a63e40357723cfa53b2cbd263dd3f (diff) |
From Weston Schmidt:
Update packet-mpeg-sect to support CRCs & simpler header processing for subdissectors.
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6941
svn path=/trunk/; revision=41523
Diffstat (limited to 'epan/dissectors')
-rw-r--r-- | epan/dissectors/Makefile.common | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-dvb-data-mpe.c | 9 | ||||
-rw-r--r-- | epan/dissectors/packet-mpeg-pat.c | 9 | ||||
-rw-r--r-- | epan/dissectors/packet-mpeg-sect.c | 158 | ||||
-rw-r--r-- | epan/dissectors/packet-mpeg-sect.h | 43 |
5 files changed, 137 insertions, 83 deletions
diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common index 4bfdd8af56..45c35593b6 100644 --- a/epan/dissectors/Makefile.common +++ b/epan/dissectors/Makefile.common @@ -1299,6 +1299,7 @@ DISSECTOR_INCLUDES = \ packet-mms.h \ packet-mount.h \ packet-mp4ves.h \ + packet-mpeg-sect.h \ packet-mpls.h \ packet-mq.h \ packet-mrdisc.h \ diff --git a/epan/dissectors/packet-dvb-data-mpe.c b/epan/dissectors/packet-dvb-data-mpe.c index 2910e6b264..e9b031df2e 100644 --- a/epan/dissectors/packet-dvb-data-mpe.c +++ b/epan/dissectors/packet-dvb-data-mpe.c @@ -30,6 +30,7 @@ #include <glib.h> #include <epan/packet.h> +#include <epan/dissectors/packet-mpeg-sect.h> static int proto_dvb_data_mpe = -1; static int hf_dvb_data_mpe_reserved = -1; @@ -46,7 +47,7 @@ static gint ett_dvb_data_mpe = -1; static dissector_handle_t ip_handle; static dissector_handle_t llc_handle; -#define DVB_DATA_MPE_TID 0x3E +#define DVB_DATA_MPE_TID 0x3E #define DVB_DATA_MPE_RESERVED_MASK 0xC0 @@ -68,7 +69,7 @@ static void dissect_dvb_data_mpe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { - guint offset = 0; + guint offset = 0, tot_len = 0; guint8 llc_snap_flag = 0; int i; @@ -89,6 +90,9 @@ dissect_dvb_data_mpe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) ti = proto_tree_add_item(tree, proto_dvb_data_mpe, tvb, offset, -1, ENC_NA); dvb_data_mpe_tree = proto_item_add_subtree(ti, ett_dvb_data_mpe); + offset += packet_mpeg_sect_header(tvb, offset, dvb_data_mpe_tree, &tot_len, NULL); + + /* Parse the DMC-CC private section header */ mac_bytes_tvb[5] = tvb_new_subset(tvb, offset, 1, 1); @@ -133,6 +137,7 @@ dissect_dvb_data_mpe(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) call_dissector(ip_handle, data_tvb, pinfo, tree); } + packet_mpeg_sect_crc(tvb, pinfo, dvb_data_mpe_tree, 0, tot_len - 1); return; } diff --git a/epan/dissectors/packet-mpeg-pat.c b/epan/dissectors/packet-mpeg-pat.c index e6dd6daf05..8fd77a976e 100644 --- a/epan/dissectors/packet-mpeg-pat.c +++ b/epan/dissectors/packet-mpeg-pat.c @@ -31,6 +31,7 @@ #include <epan/packet.h> #include <epan/prefs.h> +#include <epan/dissectors/packet-mpeg-sect.h> static int proto_mpeg_pat = -1; static int hf_mpeg_pat_transport_stream_id = -1; @@ -48,7 +49,7 @@ static int hf_mpeg_pat_program_map_pid = -1; static gint ett_mpeg_pat = -1; static gint ett_mpeg_pat_prog = -1; -#define MPEG_PAT_TID 0x00 +#define MPEG_PAT_TID 0x00 #define MPEG_PAT_RESERVED_MASK 0xC0 #define MPEG_PAT_VERSION_NUMBER_MASK 0x3E @@ -86,7 +87,8 @@ dissect_mpeg_pat(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if (!tree) return; - length = tvb_reported_length_remaining(tvb, offset); + offset += packet_mpeg_sect_header(tvb, offset, mpeg_pat_tree, &length, NULL); + length -= 4; proto_tree_add_item(mpeg_pat_tree, hf_mpeg_pat_transport_stream_id, tvb, offset, 2, ENC_BIG_ENDIAN); offset += 2; @@ -124,8 +126,7 @@ dissect_mpeg_pat(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } - return; - + packet_mpeg_sect_crc(tvb, pinfo, mpeg_pat_tree, 0, offset); } diff --git a/epan/dissectors/packet-mpeg-sect.c b/epan/dissectors/packet-mpeg-sect.c index 9341116ed9..fd8e7349f3 100644 --- a/epan/dissectors/packet-mpeg-sect.c +++ b/epan/dissectors/packet-mpeg-sect.c @@ -37,11 +37,12 @@ #include <epan/packet.h> #include <epan/prefs.h> +#include <epan/crc32-tvb.h> +#include <epan/expert.h> static int proto_mpeg_sect = -1; static int hf_mpeg_sect_table_id = -1; static int hf_mpeg_sect_syntax_indicator = -1; -static int hf_mpeg_sect_zero = -1; static int hf_mpeg_sect_reserved = -1; static int hf_mpeg_sect_length = -1; static int hf_mpeg_sect_crc = -1; @@ -50,11 +51,9 @@ static gint ett_mpeg_sect = -1; static dissector_table_t mpeg_sect_tid_dissector_table; -#define MPEG_SECT_TABLE_ID_MASK 0xFF0000 -#define MPEG_SECT_SYNTAX_INDICATOR_MASK 0x008000 -#define MPEG_SECT_ZERO_MASK 0x004000 -#define MPEG_SECT_RESERVED_MASK 0x003000 -#define MPEG_SECT_LENGTH_MASK 0x000FFF +#define MPEG_SECT_SYNTAX_INDICATOR_MASK 0x8000 +#define MPEG_SECT_RESERVED_MASK 0x7000 +#define MPEG_SECT_LENGTH_MASK 0x0FFF /* From ISO/IEC 13818-1 */ enum { @@ -135,115 +134,129 @@ static const value_string mpeg_sect_table_id_vals[] = { { 0, NULL } }; -void -dissect_mpeg_sect(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +guint +packet_mpeg_sect_header(tvbuff_t *tvb, guint offset, + proto_tree *tree, guint *sect_len, gboolean *ssi) { + guint tmp; + guint len = 0; - gint offset = 0; + if (tree) + proto_tree_add_item(tree, hf_mpeg_sect_table_id, tvb, offset + len, 1, ENC_BIG_ENDIAN); - guint8 table_id = 0; - guint16 header = 0; - guint16 section_length = 0; - guint16 syntax_indicator = 0; + len++; - proto_item *ti = NULL; - proto_tree *mpeg_sect_tree = NULL; + if (tree) { + proto_tree_add_item(tree, hf_mpeg_sect_syntax_indicator, tvb, offset + len, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(tree, hf_mpeg_sect_reserved, tvb, offset + len, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(tree, hf_mpeg_sect_length, tvb, offset + len, 2, ENC_BIG_ENDIAN); + } - tvbuff_t *pload_tvb = NULL; + tmp = tvb_get_ntohs(tvb, offset + len); - table_id = tvb_get_guint8(tvb, offset); - header = tvb_get_ntohs(tvb, offset + 1); - syntax_indicator = header & MPEG_SECT_SYNTAX_INDICATOR_MASK; - section_length = header & MPEG_SECT_LENGTH_MASK; - - set_actual_length(tvb, section_length + 3); + if (sect_len) + *sect_len = MPEG_SECT_LENGTH_MASK & tmp; + + if (ssi) + *ssi = (MPEG_SECT_SYNTAX_INDICATOR_MASK & tmp); - col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPEG SECT"); - col_add_fstr(pinfo->cinfo, COL_INFO, "Table ID 0x%08x", table_id); + len += 2; - ti = proto_tree_add_item(tree, proto_mpeg_sect, tvb, offset, -1, ENC_NA); - mpeg_sect_tree = proto_item_add_subtree(ti, ett_mpeg_sect); + return len; +} - proto_item_append_text(ti, " Table_ID=0x%08x", table_id); - if (syntax_indicator) { - /* Pass everything but the CRC */ - section_length -= sizeof(guint32); +void +packet_mpeg_sect_crc(tvbuff_t *tvb, packet_info *pinfo, + proto_tree *tree, guint start, guint end) +{ + guint32 crc, calculated_crc; + + crc = tvb_get_ntohl(tvb, end); + calculated_crc = crc32_mpeg2_tvb_offset(tvb, start, end); + + if (calculated_crc == crc) { + proto_tree_add_uint_format( tree, hf_mpeg_sect_crc, tvb, + end, 4, crc, "CRC: 0x%08x [Verified]", crc); + } else { + proto_item *msg_error = NULL; + + msg_error = proto_tree_add_uint_format( tree, hf_mpeg_sect_crc, tvb, + end, 4, crc, + "CRC: 0x%08x [Failed Verification (Calculated: 0x%08x)]", + crc, calculated_crc ); + PROTO_ITEM_SET_GENERATED(msg_error); + expert_add_info_format( pinfo, msg_error, PI_MALFORMED, + PI_ERROR, "Invalid CRC" ); } +} - if (tree) { - proto_tree_add_item(mpeg_sect_tree, hf_mpeg_sect_table_id, tvb, offset, 3, ENC_BIG_ENDIAN); - proto_tree_add_item(mpeg_sect_tree, hf_mpeg_sect_syntax_indicator, tvb, offset, 3, ENC_BIG_ENDIAN); - proto_tree_add_item(mpeg_sect_tree, hf_mpeg_sect_zero, tvb, offset, 3, ENC_BIG_ENDIAN); - proto_tree_add_item(mpeg_sect_tree, hf_mpeg_sect_reserved, tvb, offset, 3, ENC_BIG_ENDIAN); - proto_tree_add_item(mpeg_sect_tree, hf_mpeg_sect_length, tvb, offset, 3, ENC_BIG_ENDIAN); +void +dissect_mpeg_sect(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + gint offset = 0; + guint8 table_id = 0; + guint section_length = 0; + gboolean syntax_indicator; - offset += 3; + proto_item *ti = NULL; + proto_tree *mpeg_sect_tree = NULL; - if (syntax_indicator) - proto_tree_add_item(mpeg_sect_tree, hf_mpeg_sect_crc, tvb, offset + section_length, 4, ENC_BIG_ENDIAN); - } + table_id = tvb_get_guint8(tvb, offset); - - pload_tvb = tvb_new_subset(tvb, 3, section_length, -1); - dissector_try_uint(mpeg_sect_tid_dissector_table, table_id, pload_tvb, pinfo, tree); + /* Check if a dissector can parse the current table */ + if (dissector_try_uint(mpeg_sect_tid_dissector_table, table_id, tvb, pinfo, tree)) + return; - return; + /* If no dissector is registered, use the common one */ + if (tree) { -} + col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPEG SECT"); + col_add_fstr(pinfo->cinfo, COL_INFO, "Table ID 0x%02x", table_id); + ti = proto_tree_add_item(tree, proto_mpeg_sect, tvb, offset, -1, ENC_NA); + mpeg_sect_tree = proto_item_add_subtree(ti, ett_mpeg_sect); -static gboolean -heur_dissect_mpeg_sect(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) -{ - guint16 section_length = 0; + proto_item_append_text(ti, " Table_ID=0x%02x", table_id); - section_length = (tvb_get_ntohs(tvb, 1) & MPEG_SECT_LENGTH_MASK) + 3; - if (tvb_length_remaining(tvb, 0) < section_length) - return FALSE; + offset += packet_mpeg_sect_header(tvb, offset, mpeg_sect_tree, + §ion_length, &syntax_indicator); - dissect_mpeg_sect(tvb, pinfo, tree); - return TRUE; + if (syntax_indicator) + packet_mpeg_sect_crc(tvb, pinfo, mpeg_sect_tree, 0, (section_length-1)); + } } + void proto_register_mpeg_sect(void) { - static hf_register_info hf[] = { - { &hf_mpeg_sect_table_id, { "Table ID", "mpeg_sect.tid", - FT_UINT24, BASE_HEX, VALS(mpeg_sect_table_id_vals), MPEG_SECT_TABLE_ID_MASK, NULL, HFILL + FT_UINT8, BASE_HEX, VALS(mpeg_sect_table_id_vals), 0, NULL, HFILL } }, { &hf_mpeg_sect_syntax_indicator, { "Syntax indicator", "mpeg_sect.syntax_indicator", - FT_UINT24, BASE_DEC, NULL, MPEG_SECT_SYNTAX_INDICATOR_MASK, NULL, HFILL - } }, - - { &hf_mpeg_sect_zero, { - "Zero or reserved", "mpeg_sect.zero", - FT_UINT24, BASE_DEC, NULL, MPEG_SECT_ZERO_MASK, NULL, HFILL + FT_UINT16, BASE_DEC, NULL, MPEG_SECT_SYNTAX_INDICATOR_MASK, NULL, HFILL } }, { &hf_mpeg_sect_reserved, { "Reserved", "mpeg_sect.reserved", - FT_UINT24, BASE_HEX, NULL, MPEG_SECT_RESERVED_MASK, NULL, HFILL + FT_UINT16, BASE_HEX, NULL, MPEG_SECT_RESERVED_MASK, NULL, HFILL } }, { &hf_mpeg_sect_length, { "Length", "mpeg_sect.len", - FT_UINT24, BASE_DEC, NULL, MPEG_SECT_LENGTH_MASK, NULL, HFILL + FT_UINT16, BASE_DEC, NULL, MPEG_SECT_LENGTH_MASK, NULL, HFILL } }, { &hf_mpeg_sect_crc, { "CRC 32", "mpeg_sect.crc", FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL - } }, - - + } } }; static gint *ett[] = { @@ -260,12 +273,3 @@ proto_register_mpeg_sect(void) mpeg_sect_tid_dissector_table = register_dissector_table("mpeg_sect.tid", "MPEG SECT Table ID", FT_UINT8, BASE_HEX); } - - -void -proto_reg_handoff_mpeg_sect(void) -{ - heur_dissector_add("mp2t.pid", heur_dissect_mpeg_sect, proto_mpeg_sect); -} - - diff --git a/epan/dissectors/packet-mpeg-sect.h b/epan/dissectors/packet-mpeg-sect.h new file mode 100644 index 0000000000..d94e56c632 --- /dev/null +++ b/epan/dissectors/packet-mpeg-sect.h @@ -0,0 +1,43 @@ +/* packet-mpeg-sect.h + * Declarations of exported routines from mpeg-sect dissector + * Copyright 2012, Weston Schmidt <weston_schmidt@alumni.purdue.edu> + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __PACKET_MPEG_SECT_H_ +#define __PACKET_MPEG_SECT_H__ + +/* + * Used to process the 'standard' mpeg section header that is described below + * and populate the data into the tree + */ +extern guint +packet_mpeg_sect_header(tvbuff_t *tvb, guint offset, + proto_tree *tree, guint *sect_len, gboolean *ssi); + +/* + * Used to process the mpeg CRC information & report erorrs found with it. + */ +extern void +packet_mpeg_sect_crc(tvbuff_t *tvb, packet_info *pinfo, + proto_tree *tree, guint start, guint end); +#endif |