From ffcacae8b39456e84de2c88cdbd81ed940425d1c Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 8 Dec 2014 15:25:50 -0800 Subject: Have different MTP2 dissectors for different metadata and CRC. Have separate MTP2 dissectors for: MTP2 frames with no pseudo-header and no CRC; MTP2 frames with a pseudo-header and no CRC; MTP2 frames with no pseudo-header and a CRC; and call the appropriate dissector in the appropriate places. While we're at it, get rid of a global variable - pass the "use extended sequence numbers" flag down through the dissection code path, rather than having it as a global. Change-Id: Id8da1fbe3529e3ffadd5c30646cbc922f506a01f Reviewed-on: https://code.wireshark.org/review/5679 Reviewed-by: Guy Harris --- epan/dissectors/packet-erf.c | 2 +- epan/dissectors/packet-mtp2.c | 71 +++++++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 28 deletions(-) (limited to 'epan') diff --git a/epan/dissectors/packet-erf.c b/epan/dissectors/packet-erf.c index 1438d33e36..033e184a61 100644 --- a/epan/dissectors/packet-erf.c +++ b/epan/dissectors/packet-erf.c @@ -1949,7 +1949,7 @@ proto_reg_handoff_erf(void) chdlc_handle = find_dissector("chdlc"); ppp_handle = find_dissector("ppp_hdlc"); frelay_handle = find_dissector("fr"); - mtp2_handle = find_dissector("mtp2"); + mtp2_handle = find_dissector("mtp2_with_crc"); /* Get handle for ATM dissector */ atm_untruncated_handle = find_dissector("atm_untruncated"); diff --git a/epan/dissectors/packet-mtp2.c b/epan/dissectors/packet-mtp2.c index c979688507..ffa720de76 100644 --- a/epan/dissectors/packet-mtp2.c +++ b/epan/dissectors/packet-mtp2.c @@ -67,7 +67,6 @@ static gint ett_mtp2 = -1; static dissector_handle_t mtp3_handle; static gboolean use_extended_sequence_numbers_default = FALSE; -static gboolean use_extended_sequence_numbers = FALSE; #define BSN_BIB_LENGTH 1 #define FSN_FIB_LENGTH 1 @@ -105,7 +104,7 @@ static gboolean use_extended_sequence_numbers = FALSE; #define EXTENDED_SPARE_MASK 0xfe00 static void -dissect_mtp2_header(tvbuff_t *su_tvb, proto_item *mtp2_tree) +dissect_mtp2_header(tvbuff_t *su_tvb, proto_item *mtp2_tree, gboolean use_extended_sequence_numbers) { if (mtp2_tree) { if (use_extended_sequence_numbers) { @@ -245,7 +244,8 @@ static const value_string status_field_acro_vals[] = { #define SF_EXTRA_LENGTH 1 static void -dissect_mtp2_lssu(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_tree) +dissect_mtp2_lssu(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_tree, + gboolean use_extended_sequence_numbers) { guint8 sf = 0xFF; guint8 sf_offset, sf_extra_offset; @@ -272,7 +272,8 @@ dissect_mtp2_lssu(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_tree) } static void -dissect_mtp2_msu(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_item, proto_item *tree) +dissect_mtp2_msu(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_item, + proto_item *tree, gboolean use_extended_sequence_numbers) { gint sif_sio_length; tvbuff_t *sif_sio_tvb; @@ -297,12 +298,14 @@ dissect_mtp2_msu(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_item, pr } static void -dissect_mtp2_su(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_item, proto_item *mtp2_tree, proto_tree *tree,gboolean validate_crc) +dissect_mtp2_su(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_item, + proto_item *mtp2_tree, proto_tree *tree, gboolean validate_crc, + gboolean use_extended_sequence_numbers) { guint16 li; tvbuff_t *next_tvb = NULL; - dissect_mtp2_header(su_tvb, mtp2_tree); + dissect_mtp2_header(su_tvb, mtp2_tree, use_extended_sequence_numbers); if (validate_crc) next_tvb = mtp2_decode_crc16(su_tvb, mtp2_tree, pinfo); @@ -317,52 +320,60 @@ dissect_mtp2_su(tvbuff_t *su_tvb, packet_info *pinfo, proto_item *mtp2_item, pro case 1: case 2: if (validate_crc) - dissect_mtp2_lssu(next_tvb, pinfo, mtp2_tree); + dissect_mtp2_lssu(next_tvb, pinfo, mtp2_tree, use_extended_sequence_numbers); else - dissect_mtp2_lssu(su_tvb, pinfo, mtp2_tree); + dissect_mtp2_lssu(su_tvb, pinfo, mtp2_tree, use_extended_sequence_numbers); break; default: /* In some capture files (like .rf5), CRC are not present */ /* So, to avoid trouble, give the complete buffer if CRC validation is disabled */ if (validate_crc) - dissect_mtp2_msu(next_tvb, pinfo, mtp2_item, tree); + dissect_mtp2_msu(next_tvb, pinfo, mtp2_item, tree, use_extended_sequence_numbers); else - dissect_mtp2_msu(su_tvb, pinfo, mtp2_item, tree); + dissect_mtp2_msu(su_tvb, pinfo, mtp2_item, tree, use_extended_sequence_numbers); break; } } static void -dissect_mtp2_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboolean validate_crc) +dissect_mtp2_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, + gboolean validate_crc, gboolean use_extended_sequence_numbers) { proto_item *mtp2_item; proto_tree *mtp2_tree; - if ((pinfo->phdr->pkt_encap != WTAP_ENCAP_MTP2_WITH_PHDR) || - (pinfo->pseudo_header->mtp2.annex_a_used == MTP2_ANNEX_A_USED_UNKNOWN)) - use_extended_sequence_numbers = use_extended_sequence_numbers_default; - else - use_extended_sequence_numbers = (pinfo->pseudo_header->mtp2.annex_a_used == MTP2_ANNEX_A_USED); - col_set_str(pinfo->cinfo, COL_PROTOCOL, "MTP2"); mtp2_item = proto_tree_add_item(tree, proto_mtp2, tvb, 0, -1, ENC_NA); mtp2_tree = proto_item_add_subtree(mtp2_item, ett_mtp2); - dissect_mtp2_su(tvb, pinfo, mtp2_item, mtp2_tree, tree, validate_crc); + dissect_mtp2_su(tvb, pinfo, mtp2_item, mtp2_tree, tree, validate_crc, + use_extended_sequence_numbers); +} + +/* Dissect MTP2 frame without CRC16 and with a pseudo-header */ +static void +dissect_mtp2_with_phdr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + if (pinfo->pseudo_header->mtp2.annex_a_used == MTP2_ANNEX_A_USED_UNKNOWN) + dissect_mtp2_common(tvb, pinfo, tree, FALSE, use_extended_sequence_numbers_default); + else + dissect_mtp2_common(tvb, pinfo, tree, FALSE, + (pinfo->pseudo_header->mtp2.annex_a_used == MTP2_ANNEX_A_USED)); +} + +/* Dissect MTP2 frame with CRC16 included at end of payload */ +static void +dissect_mtp2_with_crc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + dissect_mtp2_common(tvb, pinfo, tree, TRUE, use_extended_sequence_numbers_default); } -/* Dissect MTP2 frame with/without CRC16 included at end of payload */ +/* Dissect MTP2 frame without CRC16 included at end of payload */ static void dissect_mtp2(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { - /* If the link extension indicates the FCS presence, then the Checkbits - * have to be proceeded in the MTP2 dissector */ - if ( pinfo->fd->lnk_t == WTAP_ENCAP_ERF ) { - dissect_mtp2_common(tvb, pinfo, tree, TRUE); - } else { - dissect_mtp2_common(tvb, pinfo, tree, FALSE); - } + dissect_mtp2_common(tvb, pinfo, tree, FALSE, use_extended_sequence_numbers_default); } void @@ -401,6 +412,7 @@ proto_register_mtp2(void) proto_mtp2 = proto_register_protocol("Message Transfer Part Level 2", "MTP2", "mtp2"); mtp2_handle = register_dissector("mtp2", dissect_mtp2, proto_mtp2); + register_dissector("mtp2_with_crc", dissect_mtp2_with_crc, proto_mtp2); proto_register_field_array(proto_mtp2, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); @@ -420,8 +432,13 @@ proto_register_mtp2(void) void proto_reg_handoff_mtp2(void) { + dissector_handle_t mtp2_with_phdr_handle; + dissector_add_uint("wtap_encap", WTAP_ENCAP_MTP2, mtp2_handle); - dissector_add_uint("wtap_encap", WTAP_ENCAP_MTP2_WITH_PHDR, mtp2_handle); + mtp2_with_phdr_handle = create_dissector_handle(dissect_mtp2_with_phdr, + proto_mtp2); + dissector_add_uint("wtap_encap", WTAP_ENCAP_MTP2_WITH_PHDR, + mtp2_with_phdr_handle); mtp3_handle = find_dissector("mtp3"); } -- cgit v1.2.1