diff options
author | wmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7> | 2009-08-03 22:09:08 +0000 |
---|---|---|
committer | wmeier <wmeier@f5534014-38df-0310-8fa8-9805f1628bb7> | 2009-08-03 22:09:08 +0000 |
commit | 5d49445dce9c9fd8a9b8a3ce5e12b1df7672255b (patch) | |
tree | 32bed2e01b46a934a6e42ec3e9afbd87985629f2 /plugins/m2m | |
parent | 6edca2934bdce4ea559eca6bc0d984e8f9f13b3a (diff) |
Various minor cleanups:
- Do all find_dissector() calls only once during proto_reg_handoff
(not each time a sub-dissector is called when dissecting frames).
- Move proto_register & proto_reg_handoff to the end of the file as per convention;
- Move a global variables to be local;
- Change a global variable to be static;
- Remove unneeded multiple #include <string.h>
- Remove an unneeded variable and a few unneeded lines of code.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@29282 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'plugins/m2m')
-rw-r--r-- | plugins/m2m/packet-m2m.c | 513 |
1 files changed, 250 insertions, 263 deletions
diff --git a/plugins/m2m/packet-m2m.c b/plugins/m2m/packet-m2m.c index 95d9c81171..d04cf56118 100644 --- a/plugins/m2m/packet-m2m.c +++ b/plugins/m2m/packet-m2m.c @@ -32,9 +32,6 @@ #include "config.h" #endif -#include <string.h> - -#include <string.h> #include <glib.h> #include <epan/packet.h> #include <epan/reassemble.h> @@ -42,7 +39,6 @@ #include <plugins/wimax/wimax_tlv.h> /* forward reference */ -static void dissect_m2m(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree); static void fch_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo); static void cdma_code_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo); static void pdu_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo, gint burst_number, gint frag_type, gint frag_number); @@ -53,34 +49,22 @@ static void extended_tlv_decoder(packet_info *pinfo); void proto_tree_add_tlv(tlv_info_t *this, tvbuff_t *tvb, guint offset, packet_info *pinfo, proto_tree *tree, gint hf); /* Global variables */ -gint sequence_number = 0; -GHashTable *pdu_frag_table = NULL; -guint g_frame_number = 0; - -/* Local Variables */ -static gint proto_m2m = -1; -static dissector_handle_t wimax_fch_burst_handle = NULL; -static dissector_handle_t wimax_cdma_code_burst_handle = NULL; -static dissector_handle_t wimax_pdu_burst_handle = NULL; -static dissector_handle_t wimax_ffb_burst_handle = NULL; -static dissector_handle_t wimax_hack_burst_handle = NULL; -static dissector_handle_t wimax_phy_attributes_burst_handle = NULL; - -static gint ett_m2m = -1; -static gint ett_m2m_tlv = -1; -static gint ett_m2m_fch = -1; -static gint ett_m2m_cdma = -1; -static gint ett_m2m_ffb = -1; +static dissector_handle_t wimax_cdma_code_burst_handle; +static dissector_handle_t wimax_ffb_burst_handle; +static dissector_handle_t wimax_fch_burst_handle; +static dissector_handle_t wimax_hack_burst_handle; +static dissector_handle_t wimax_pdu_burst_handle; +static dissector_handle_t wimax_phy_attributes_burst_handle; -/* Setup protocol subtree array */ -static gint *ett[] = -{ - &ett_m2m, - &ett_m2m_tlv, - &ett_m2m_fch, - &ett_m2m_cdma, - &ett_m2m_ffb, -}; +static GHashTable *pdu_frag_table = NULL; + +static gint proto_m2m = -1; + +static gint ett_m2m = -1; +static gint ett_m2m_tlv = -1; +static gint ett_m2m_fch = -1; +static gint ett_m2m_cdma = -1; +static gint ett_m2m_ffb = -1; /* TLV types (rev:0.2) */ #define TLV_PROTO_VER 1 @@ -178,221 +162,6 @@ m2m_defragment_init(void) fragment_table_init(&pdu_frag_table); } -/* Register Wimax Mac to Mac Protocol handler */ -void proto_reg_handoff_m2m(void) -{ - dissector_handle_t m2m_handle; - - m2m_handle = create_dissector_handle(dissect_m2m, proto_m2m); - dissector_add("ethertype", ETHERTYPE_WMX_M2M, m2m_handle); -} - -/* Register Wimax Mac to Mac Protocol */ -void proto_register_m2m(void) -{ - /* M2M TLV display */ - static hf_register_info hf[] = - { - { - &hf_m2m_sequence_number, - { - "Packet Sequence Number", "m2m.seq_number", - FT_UINT16, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_frame_number, - { - "Value", "m2m.frame_number", - FT_UINT24, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_tlv_count, - { - "Number of TLVs in the packet", "m2m.tlv_count", - FT_UINT16, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - } - }; - - /* WiMax TLV display */ - static hf_register_info hf_tlv[] = - { - { - &hf_m2m_type, - { - "Type", "m2m.tlv_type", - FT_UINT8, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_len, - { - "Length", "m2m.tlv_len", - FT_UINT8, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_len_size, - { - "Length Size", "m2m.tlv_len_size", - FT_UINT8, BASE_HEX, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_bytes, - { - "Value (hex)", "m2m.multibyte_tlv_value", - FT_BYTES, BASE_NONE, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_protocol_vers_uint8, - { - "Value", "m2m.protocol_vers_tlv_value", - FT_UINT8, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_burst_num_uint8, - { - "Value", "m2m.burst_num_tlv_value", - FT_UINT8, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_frag_type_uint8, - { - "Value", "m2m.frag_type_tlv_value", - FT_UINT8, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_frag_num_uint8, - { - "Value", "m2m.frag_num_tlv_value", - FT_UINT8, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_pdu_burst, - { - "Value (hex)", "m2m.pdu_burst_tlv_value", - FT_BYTES, BASE_NONE, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_fast_fb, - { - "Value (hex)", "m2m.fast_fb_tlv_value", - FT_BYTES, BASE_NONE, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_fch_burst_uint24, - { - "Value", "m2m.fch_burst_tlv_value", - FT_BYTES, BASE_NONE, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_cdma_code_uint24, - { - "Value", "m2m.cdma_code_tlv_value", - FT_UINT24, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_crc16_status_uint8, - { - "Value", "m2m.crc16_status_tlv_value", - FT_UINT8, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_burst_power_uint16, - { - "Value", "m2m.burst_power_tlv_value", - FT_UINT16, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_burst_cinr_uint16, - { - "Value", "m2m.burst_cinr_tlv_value", - FT_UINT16, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_preamble_uint16, - { - "Value", "m2m.preamble_tlv_value", - FT_UINT16, BASE_DEC, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_value_harq_ack_burst_bytes, - { - "Value (hex)", "m2m.harq_ack_burst_tlv_value", - FT_BYTES, BASE_NONE, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_m2m_phy_attributes, - { - "Value (hex)", "m2m.phy_attributes", - FT_BYTES, BASE_NONE, NULL, 0x0, - NULL, HFILL - } - }, - { - &hf_wimax_invalid_tlv, - { - "Invalid TLV (hex)", "m2m.invalid_tlv", - FT_BYTES, BASE_NONE, NULL, 0x0, - NULL, HFILL - } - } - }; - - proto_m2m = proto_register_protocol ( - "WiMax Mac to Mac Packet", /* name */ - "M2M (m2m)", /* short name */ - "m2m" /* abbrev */ - ); - - proto_register_field_array(proto_m2m, hf, array_length(hf)); - proto_register_field_array(proto_m2m, hf_tlv, array_length(hf_tlv)); - proto_register_subtree_array(ett, array_length(ett)); - - /* init the PDU fragment table */ - fragment_table_init(&pdu_frag_table); - /* Register the PDU fragment table init routine */ - register_init_routine(m2m_defragment_init); - - /* Add new protocols here */ -} /* WiMax MAC to MAC protocol dissector */ static void dissect_m2m(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) @@ -409,6 +178,7 @@ static void dissect_m2m(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) gint tlv_frag_number = 0; tlv_info_t m2m_tlv_info; gint hf = 0; + guint frame_number; /* display the M2M protocol name */ if (check_col(pinfo->cinfo, COL_PROTOCOL)) @@ -433,8 +203,6 @@ static void dissect_m2m(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_item_append_text(m2m_item, " (%u bytes) - Packet Sequence Number,Number of TLVs", length); */ proto_item_append_text(m2m_item, " (%u bytes)", length); - /* get the sequence number */ - sequence_number = tvb_get_ntohs(tvb, offset); /* display the sequence number */ proto_tree_add_item(m2m_tree, hf_m2m_sequence_number, tvb, offset, 2, FALSE); offset += 2; @@ -521,10 +289,10 @@ static void dissect_m2m(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) case TLV_FRAME_NUM: /* get the frame number */ - g_frame_number = tvb_get_ntoh24( tvb, offset ); + frame_number = tvb_get_ntoh24( tvb, offset ); /* add the description */ proto_tree_add_item(tlv_tree, hf_m2m_frame_number, tvb, offset, 3, FALSE); - proto_item_append_text(ti, ": %d", g_frame_number); + proto_item_append_text(ti, ": %d", frame_number); break; case TLV_FCH_BURST: @@ -616,8 +384,6 @@ static void dissect_m2m(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* Decode and display the FCH burst */ static void fch_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo) { - /* find the TLV FCH Burst handler */ - wimax_fch_burst_handle = find_dissector("wimax_fch_burst_handler"); if(wimax_fch_burst_handle) { /* call FCH dissector */ call_dissector(wimax_fch_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree); @@ -634,8 +400,6 @@ static void fch_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint /* Decode and display the CDMA Code Attribute */ static void cdma_code_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo) { - /* find the TLV CDMA CODE Burst handler */ - wimax_cdma_code_burst_handle = find_dissector("wimax_cdma_code_burst_handler"); if(wimax_cdma_code_burst_handle) { /* call CDMA dissector */ call_dissector(wimax_cdma_code_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree); @@ -700,11 +464,11 @@ static void pdu_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint } /* process the defragmented PDU burst */ if(pdu_tvb) - { /* find the TLV PDU Burst handler */ - wimax_pdu_burst_handle = find_dissector("wimax_pdu_burst_handler"); + { if(wimax_pdu_burst_handle) - /* decode and display PDU Burst */ + {/* decode and display PDU Burst */ call_dissector(wimax_pdu_burst_handle, pdu_tvb, pinfo, tree); + } else /* display PDU Burst info */ { /* update the info column */ if (check_col(pinfo->cinfo, COL_INFO)) @@ -718,8 +482,6 @@ static void pdu_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint /* Decode and display the Fast Feedback Burst */ static void fast_feedback_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo) { - /* find the TLV Fast Feedback Burst handler */ - wimax_ffb_burst_handle = find_dissector("wimax_ffb_burst_handler"); if(wimax_ffb_burst_handle) { /* display the TLV Fast Feedback Burst dissector info */ call_dissector(wimax_ffb_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree); @@ -735,8 +497,6 @@ static void fast_feedback_burst_decoder(proto_tree *tree, tvbuff_t *tvb, gint of static void harq_ack_bursts_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo) { - /* find the TLV HARQ ACK Bursts handler */ - wimax_hack_burst_handle = find_dissector("wimax_hack_burst_handler"); if(wimax_hack_burst_handle) { /* call the TLV HARQ ACK Bursts dissector */ call_dissector(wimax_hack_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree); @@ -752,8 +512,6 @@ static void harq_ack_bursts_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset static void physical_attributes_decoder(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, packet_info *pinfo) { - /* find the TLV PDU Burst Physical Attributes handler */ - wimax_phy_attributes_burst_handle = find_dissector("wimax_phy_attributes_burst_handler"); if(wimax_phy_attributes_burst_handle) { /* call the TLV PDU Burst Physical Attributes dissector */ call_dissector(wimax_phy_attributes_burst_handle, tvb_new_subset(tvb, offset, length, length), pinfo, tree); @@ -822,3 +580,232 @@ void proto_tree_add_tlv(tlv_info_t *this, tvbuff_t *tvb, guint offset, packet_in tlv_len = get_tlv_length(this); proto_tree_add_item(tree, hf, tvb, (offset + this->value_offset), tlv_len, FALSE); } + +/* Register Wimax Mac to Mac Protocol */ +void proto_register_m2m(void) +{ + /* M2M TLV display */ + static hf_register_info hf[] = + { + { + &hf_m2m_sequence_number, + { + "Packet Sequence Number", "m2m.seq_number", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_frame_number, + { + "Value", "m2m.frame_number", + FT_UINT24, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_tlv_count, + { + "Number of TLVs in the packet", "m2m.tlv_count", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + } + }; + + /* WiMax TLV display */ + static hf_register_info hf_tlv[] = + { + { + &hf_m2m_type, + { + "Type", "m2m.tlv_type", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_len, + { + "Length", "m2m.tlv_len", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_len_size, + { + "Length Size", "m2m.tlv_len_size", + FT_UINT8, BASE_HEX, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_bytes, + { + "Value (hex)", "m2m.multibyte_tlv_value", + FT_BYTES, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_protocol_vers_uint8, + { + "Value", "m2m.protocol_vers_tlv_value", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_burst_num_uint8, + { + "Value", "m2m.burst_num_tlv_value", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_frag_type_uint8, + { + "Value", "m2m.frag_type_tlv_value", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_frag_num_uint8, + { + "Value", "m2m.frag_num_tlv_value", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_pdu_burst, + { + "Value (hex)", "m2m.pdu_burst_tlv_value", + FT_BYTES, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_fast_fb, + { + "Value (hex)", "m2m.fast_fb_tlv_value", + FT_BYTES, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_fch_burst_uint24, + { + "Value", "m2m.fch_burst_tlv_value", + FT_BYTES, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_cdma_code_uint24, + { + "Value", "m2m.cdma_code_tlv_value", + FT_UINT24, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_crc16_status_uint8, + { + "Value", "m2m.crc16_status_tlv_value", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_burst_power_uint16, + { + "Value", "m2m.burst_power_tlv_value", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_burst_cinr_uint16, + { + "Value", "m2m.burst_cinr_tlv_value", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_preamble_uint16, + { + "Value", "m2m.preamble_tlv_value", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_value_harq_ack_burst_bytes, + { + "Value (hex)", "m2m.harq_ack_burst_tlv_value", + FT_BYTES, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_m2m_phy_attributes, + { + "Value (hex)", "m2m.phy_attributes", + FT_BYTES, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_wimax_invalid_tlv, + { + "Invalid TLV (hex)", "m2m.invalid_tlv", + FT_BYTES, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + } + }; + + static gint *ett[] = + { + &ett_m2m, + &ett_m2m_tlv, + &ett_m2m_fch, + &ett_m2m_cdma, + &ett_m2m_ffb, + }; + + proto_m2m = proto_register_protocol ( + "WiMax Mac to Mac Packet", /* name */ + "M2M (m2m)", /* short name */ + "m2m" /* abbrev */ + ); + + proto_register_field_array(proto_m2m, hf, array_length(hf)); + proto_register_field_array(proto_m2m, hf_tlv, array_length(hf_tlv)); + proto_register_subtree_array(ett, array_length(ett)); + + /* Register the PDU fragment table init routine */ + register_init_routine(m2m_defragment_init); +} + +/* Register Wimax Mac to Mac Protocol handler */ +void proto_reg_handoff_m2m(void) +{ + dissector_handle_t m2m_handle; + + m2m_handle = create_dissector_handle(dissect_m2m, proto_m2m); + dissector_add("ethertype", ETHERTYPE_WMX_M2M, m2m_handle); + + /* find the wimax handlers */ + wimax_cdma_code_burst_handle = find_dissector("wimax_cdma_code_burst_handler"); + wimax_fch_burst_handle = find_dissector("wimax_fch_burst_handler"); + wimax_ffb_burst_handle = find_dissector("wimax_ffb_burst_handler"); + wimax_hack_burst_handle = find_dissector("wimax_hack_burst_handler"); + wimax_pdu_burst_handle = find_dissector("wimax_pdu_burst_handler"); + wimax_phy_attributes_burst_handle = find_dissector("wimax_phy_attributes_burst_handler"); +} |