/* packet-csm-encaps.c * Routines for CSM_ENCAPS dissection * Copyright 2005, Angelo Bannack * Wireshark - Network traffic analyzer * By Gerald Combs * Copyright 2003 Gerald Combs * * Copied from packet-ans.c * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ #include "config.h" #include #include #define OPCODE_NOOP 0x0000 #define OPCODE_CONTROL_PACKET 0x0001 #define OPCODE_RELIABLE_DATA 0x0002 #define CSM_ENCAPS_CTRL_ACK 0x80 #define CSM_ENCAPS_CTRL_ACK_SUPPRESS 0x40 #define CSM_ENCAPS_CTRL_ACK_TO_HOST 0x20 #define CSM_ENCAPS_CTRL_ENDIAN 0x01 #define CSM_ENCAPS_TYPE_CHANGE 0x00 #define CSM_ENCAPS_TYPE_QUERY 0x01 #define CSM_ENCAPS_TYPE_RESPONSE 0x02 #define CSM_ENCAPS_TYPE_INDICATION 0x03 #define CSM_ENCAPS_TYPE_QUERY_RESPONSE 0x04 #define CSM_ENCAPS_TYPE_INDICATION_RESPONSE 0x05 void proto_register_csm_encaps(void); void proto_reg_handoff_csm_encaps(void); static const value_string opcode_vals[] = { { OPCODE_NOOP, "No Operation" }, { OPCODE_CONTROL_PACKET, "Control Packet" }, { OPCODE_RELIABLE_DATA, "Reliable Data Transfer" }, { 0, NULL } }; static const value_string function_code_vals[] = { {0x0000, " "}, { 0, NULL } }; static const value_string class_type_vals[] = { { 0, NULL } }; static const value_string exclusive_to_host_vals[] = { { 0, NULL } }; static const value_string exclusive_to_host_ct_vals[] = { { 0, NULL } }; static const value_string error_vals[] = { { 0, NULL } }; /* Initialize the protocol and registered fields */ static int proto_csm_encaps = -1; static int hf_csm_encaps_opcode = -1; static int hf_csm_encaps_seq = -1; static int hf_csm_encaps_ctrl = -1; static int hf_csm_encaps_ctrl_endian = -1; static int hf_csm_encaps_ctrl_ack = -1; static int hf_csm_encaps_ctrl_ack_suppress = -1; static int hf_csm_encaps_channel = -1; static int hf_csm_encaps_index = -1; static int hf_csm_encaps_length = -1; static int hf_csm_encaps_class = -1; static int hf_csm_encaps_type = -1; static int hf_csm_encaps_function_code = -1; static int hf_csm_encaps_reserved = -1; static int hf_csm_encaps_param_error = -1; static int hf_csm_encaps_param1 = -1; static int hf_csm_encaps_param2 = -1; static int hf_csm_encaps_param3 = -1; static int hf_csm_encaps_param4 = -1; static int hf_csm_encaps_param5 = -1; static int hf_csm_encaps_param6 = -1; static int hf_csm_encaps_param7 = -1; static int hf_csm_encaps_param8 = -1; static int hf_csm_encaps_param9 = -1; static int hf_csm_encaps_param10 = -1; static int hf_csm_encaps_param11 = -1; static int hf_csm_encaps_param12 = -1; static int hf_csm_encaps_param13 = -1; static int hf_csm_encaps_param14 = -1; static int hf_csm_encaps_param15 = -1; static int hf_csm_encaps_param16 = -1; static int hf_csm_encaps_param17 = -1; static int hf_csm_encaps_param18 = -1; static int hf_csm_encaps_param19 = -1; static int hf_csm_encaps_param20 = -1; static int hf_csm_encaps_param21 = -1; static int hf_csm_encaps_param22 = -1; static int hf_csm_encaps_param23 = -1; static int hf_csm_encaps_param24 = -1; static int hf_csm_encaps_param25 = -1; static int hf_csm_encaps_param26 = -1; static int hf_csm_encaps_param27 = -1; static int hf_csm_encaps_param28 = -1; static int hf_csm_encaps_param29 = -1; static int hf_csm_encaps_param30 = -1; static int hf_csm_encaps_param31 = -1; static int hf_csm_encaps_param32 = -1; static int hf_csm_encaps_param33 = -1; static int hf_csm_encaps_param34 = -1; static int hf_csm_encaps_param35 = -1; static int hf_csm_encaps_param36 = -1; static int hf_csm_encaps_param37 = -1; static int hf_csm_encaps_param38 = -1; static int hf_csm_encaps_param39 = -1; static int hf_csm_encaps_param40 = -1; static int hf_csm_encaps_param = -1; /* Initialize the subtree pointers */ static gint ett_csm_encaps = -1; static gint ett_csm_encaps_control = -1; /* returns the command name */ static const gchar * csm_fc(guint16 fc, guint16 ct) { if (fc == 0x0000) { return val_to_str(ct, class_type_vals, "0x%04x"); } else { return val_to_str(fc, function_code_vals, "0x%04x"); } } /* check to see if the message is an exclusive message send to host */ static gboolean csm_to_host(guint16 fc, guint16 ct) { if (fc == 0x0000) { return (try_val_to_str(ct, exclusive_to_host_ct_vals) != NULL); } else { return (try_val_to_str(fc, exclusive_to_host_vals) != NULL); } } /* Code to actually dissect the packets */ static int dissect_csm_encaps(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) { proto_item *ti; proto_tree *csm_encaps_tree = NULL; guint16 function_code, channel, class_type; guint control, type, sequence, length; guint i; gboolean show_error_param= FALSE; const gchar *str_function_name; function_code = tvb_get_letohs(tvb, 10); control = tvb_get_guint8(tvb, 3); class_type = tvb_get_guint8(tvb, 9); class_type = class_type<<8; class_type|= tvb_get_guint8(tvb, 8); type = tvb_get_guint8(tvb, 8); sequence = tvb_get_guint8(tvb, 2); length = tvb_get_guint8(tvb, 6); channel = tvb_get_ntohs(tvb, 4); if (CSM_ENCAPS_CTRL_ACK&control) show_error_param= FALSE; else { if (csm_to_host(function_code, class_type)) /* exclusive messages to host */ show_error_param= FALSE; else { if (type == CSM_ENCAPS_TYPE_RESPONSE) show_error_param= TRUE; else show_error_param= FALSE; } } col_set_str(pinfo->cinfo, COL_PROTOCOL, "CSM_ENCAPS"); col_clear(pinfo->cinfo, COL_INFO); if (CSM_ENCAPS_CTRL_ACK&control) { if (CSM_ENCAPS_CTRL_ACK_TO_HOST&control) col_append_fstr(pinfo->cinfo, COL_INFO, "<-- ACK Ch: 0x%04X, Seq: %2d (To Host)", channel, sequence); else col_append_fstr(pinfo->cinfo, COL_INFO, "--> ACK Ch: 0x%04X, Seq: %2d (From Host)", channel, sequence); } else { str_function_name= csm_fc(function_code, class_type); if ((type == CSM_ENCAPS_TYPE_RESPONSE) || (csm_to_host(function_code, class_type))) col_append_fstr(pinfo->cinfo, COL_INFO, "<-- %-35s Ch: 0x%04X, Seq: %2d (To Host)", str_function_name, channel, sequence); else col_append_fstr(pinfo->cinfo, COL_INFO, "--> %-35s Ch: 0x%04X, Seq: %2d (From Host)", str_function_name, channel, sequence); } if (tree) { static const int * control_flags[] = { &hf_csm_encaps_ctrl_ack, &hf_csm_encaps_ctrl_ack_suppress, &hf_csm_encaps_ctrl_endian, NULL }; ti = proto_tree_add_item(tree, proto_csm_encaps, tvb, 0, -1, ENC_NA); csm_encaps_tree = proto_item_add_subtree(ti, ett_csm_encaps); proto_tree_add_item(csm_encaps_tree, hf_csm_encaps_opcode, tvb, 0, 2, ENC_BIG_ENDIAN); proto_tree_add_item(csm_encaps_tree, hf_csm_encaps_seq, tvb, 2, 1, ENC_BIG_ENDIAN); proto_tree_add_bitmask(tree, tvb, 3, hf_csm_encaps_ctrl, ett_csm_encaps_control, control_flags, ENC_NA); proto_tree_add_item(csm_encaps_tree, hf_csm_encaps_channel, tvb, 4, 2, ENC_BIG_ENDIAN); proto_tree_add_item(csm_encaps_tree, hf_csm_encaps_length, tvb, 6, 1, ENC_BIG_ENDIAN); proto_tree_add_item(csm_encaps_tree, hf_csm_encaps_index, tvb, 7, 1, ENC_BIG_ENDIAN); proto_tree_add_item(csm_encaps_tree, hf_csm_encaps_class, tvb, 9, 1, ENC_BIG_ENDIAN); proto_tree_add_item(csm_encaps_tree, hf_csm_encaps_type, tvb, 8, 1, ENC_BIG_ENDIAN); proto_tree_add_item(csm_encaps_tree, hf_csm_encaps_function_code, tvb, 10, 2, ENC_LITTLE_ENDIAN); i=6; if (i