/* packet-h1.c * Routines for Sinec H1 packet disassembly * Gerrit Gehnen * * $Id: packet-h1.c,v 1.9 2000/05/31 05:07:05 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs * 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. */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #ifdef HAVE_SYS_TYPES_H # include #endif #include #include #include "packet.h" #include "globals.h" static int proto_h1 = -1; static int hf_h1_header = -1; static int hf_h1_len = -1; static int hf_h1_opfield = -1; static int hf_h1_oplen = -1; static int hf_h1_opcode = -1; static int hf_h1_requestblock = -1; static int hf_h1_requestlen = -1; static int hf_h1_dbnr = -1; static int hf_h1_dwnr = -1; static int hf_h1_dlen = -1; static int hf_h1_org = -1; static int hf_h1_response = -1; static int hf_h1_response_len = -1; static int hf_h1_response_value = -1; static int hf_h1_empty_len = -1; static int hf_h1_empty = -1; #define EMPTY_BLOCK 0xFF #define OPCODE_BLOCK 0x01 #define REQUEST_BLOCK 0x03 #define RESPONSE_BLOCK 0x0F static const value_string opcode_vals[] = { {3, "Write Request"}, {4, "Write Response"}, {5, "Read Request"}, {6, "Read Response"}, {0, NULL} }; static const value_string org_vals[] = { {0x01, "DB"}, {0x02, "MB"}, {0x03, "EB"}, {0x04, "AB"}, {0x05, "PB"}, {0x06, "ZB"}, {0x07, "TB"}, {0x08, "BS"}, {0x09, "AS"}, {0x0a, "DX"}, {0x10, "DE"}, {0x11, "QB"}, {0, NULL} }; static const value_string returncode_vals[] = { {0x00, "No error"}, {0x02, "Requested block does not exist"}, {0x03, "Requested block too small"}, {0xFF, "Error, reason unknown"}, {0, NULL} }; static gint ett_h1 = -1; static gint ett_opcode = -1; static gint ett_org = -1; static gint ett_response = -1; static gint ett_empty = -1; static gboolean dissect_h1 (const u_char * pd, int offset, frame_data * fd, proto_tree * tree) { proto_tree *h1_tree = NULL; proto_item *ti; proto_tree *opcode_tree = NULL; proto_tree *org_tree = NULL; proto_tree *response_tree = NULL; proto_tree *empty_tree = NULL; unsigned int position = 3; if (!(pd[offset] == 'S' && pd[offset + 1] == '5')) { return FALSE; } if (check_col (fd, COL_PROTOCOL)) col_add_str (fd, COL_PROTOCOL, "H1"); if (check_col (fd, COL_INFO)) col_add_str (fd, COL_INFO, "S5: "); if (tree) { ti = proto_tree_add_item (tree, proto_h1, NullTVB, offset, 16, FALSE); h1_tree = proto_item_add_subtree (ti, ett_h1); proto_tree_add_uint (h1_tree, hf_h1_header, NullTVB, offset, 2, pd[offset] * 0x100 + pd[offset + 1]); proto_tree_add_uint (h1_tree, hf_h1_len, NullTVB, offset + 2, 1, pd[offset + 2]); } while (position < pd[offset + 2]) { switch (pd[offset + position]) { case OPCODE_BLOCK: if (h1_tree) { ti = proto_tree_add_uint (h1_tree, hf_h1_opfield, NullTVB, offset + position, pd[offset + position + 1], pd[offset + position]); opcode_tree = proto_item_add_subtree (ti, ett_opcode); proto_tree_add_uint (opcode_tree, hf_h1_oplen, NullTVB, offset + position + 1, 1, pd[offset + position + 1]); proto_tree_add_uint (opcode_tree, hf_h1_opcode, NullTVB, offset + position + 2, 1, pd[offset + position + 2]); } if (check_col (fd, COL_INFO)) { col_append_str (fd, COL_INFO, val_to_str (pd[offset + position + 2], opcode_vals,"Unknown Opcode (0x%2.2x)")); } break; case REQUEST_BLOCK: if (h1_tree) { ti = proto_tree_add_uint (h1_tree, hf_h1_requestblock, NullTVB, offset + position, pd[offset + position + 1], pd[offset + position]); org_tree = proto_item_add_subtree (ti, ett_org); proto_tree_add_uint (org_tree, hf_h1_requestlen, NullTVB, offset + position + 1, 1, pd[offset + position + 1]); proto_tree_add_uint (org_tree, hf_h1_org, NullTVB, offset + position + 2, 1, pd[offset + position + 2]); proto_tree_add_uint (org_tree, hf_h1_dbnr, NullTVB, offset + position + 3, 1, pd[offset + position + 3]); proto_tree_add_uint (org_tree, hf_h1_dwnr, NullTVB, offset + position + 4, 2, pd[offset + position + 4] * 0x100 + pd[offset + position + 5]); proto_tree_add_int (org_tree, hf_h1_dlen, NullTVB, offset + position + 6, 2, pd[offset + position + 6] * 0x100 + pd[offset + position + 7]); } if (check_col (fd, COL_INFO)) { col_append_fstr (fd, COL_INFO, " %s %d", val_to_str (pd[offset + position + 2], org_vals,"Unknown Type (0x%2.2x)"), pd[offset + position + 3]); col_append_fstr (fd, COL_INFO, " DW %d", pd[offset + position + 4] * 0x100 + pd[offset + position + 5]); col_append_fstr (fd, COL_INFO, " Count %d", pd[offset + position + 6] * 0x100 + pd[offset + position + 7]); } break; case RESPONSE_BLOCK: if (h1_tree) { ti = proto_tree_add_uint (h1_tree, hf_h1_response, NullTVB, offset + position, pd[offset + position + 1], pd[offset + position]); response_tree = proto_item_add_subtree (ti, ett_response); proto_tree_add_uint (response_tree, hf_h1_response_len, NullTVB, offset + position + 1, 1, pd[offset + position + 1]); proto_tree_add_uint (response_tree, hf_h1_response_value, NullTVB, offset + position + 2, 1, pd[offset + position + 2]); } if (check_col (fd, COL_INFO)) { col_append_fstr (fd, COL_INFO, " %s", val_to_str (pd[offset + position + 2], returncode_vals,"Unknown Returcode (0x%2.2x")); } break; case EMPTY_BLOCK: if (h1_tree) { ti = proto_tree_add_uint (h1_tree, hf_h1_empty, NullTVB, offset + position, pd[offset + position + 1], pd[offset + position]); empty_tree = proto_item_add_subtree (ti, ett_empty); proto_tree_add_uint (empty_tree, hf_h1_empty_len, NullTVB, offset + position + 1, 1, pd[offset + position + 1]); } break; default: /* This is not a valid telegram. So cancel dissection and try the next dissector */ return FALSE; break; } position += pd[offset + position + 1]; /* Goto next section */ } /* ..while */ dissect_data (pd, offset + pd[offset + 2], fd, tree); return TRUE; } void proto_register_h1 (void) { static hf_register_info hf[] = { {&hf_h1_header, {"H1-Header", "h1.header", FT_UINT16, BASE_HEX, NULL, 0x0, ""}}, {&hf_h1_len, {"Length indicator", "h1.len", FT_UINT16, BASE_DEC, NULL, 0x0, ""}}, {&hf_h1_opfield, {"Operation identifier", "h1.opfield", FT_UINT8, BASE_HEX, NULL, 0x0, ""}}, {&hf_h1_oplen, {"Operation length", "h1.oplen", FT_UINT8, BASE_HEX, NULL, 0x0, ""}}, {&hf_h1_opcode, {"Opcode", "h1.opcode", FT_UINT8, BASE_HEX, VALS (opcode_vals), 0x0, ""}}, {&hf_h1_requestblock, {"Request identifier", "h1.request", FT_UINT8, BASE_HEX, NULL, 0x0, ""}}, {&hf_h1_requestlen, {"Request length", "h1.reqlen", FT_UINT8, BASE_HEX, NULL, 0x0, ""}}, {&hf_h1_org, {"Memory type", "h1.org", FT_UINT8, BASE_HEX, VALS (org_vals), 0x0, ""}}, {&hf_h1_dbnr, {"Memory block number", "h1.dbnr", FT_UINT8, BASE_DEC, NULL, 0x0, ""}}, {&hf_h1_dwnr, {"Address within memory block", "h1.dwnr", FT_UINT16, BASE_DEC, NULL, 0x0, ""}}, {&hf_h1_dlen, {"Length in words", "h1.dlen", FT_INT16, BASE_DEC, NULL, 0x0, ""}}, {&hf_h1_response, {"Response identifier", "h1.response", FT_UINT8, BASE_DEC, NULL, 0x0, ""}}, {&hf_h1_response_len, {"Response length", "h1.reslen", FT_UINT8, BASE_DEC, NULL, 0x0, ""}}, {&hf_h1_response_value, {"Response value", "h1.resvalue", FT_UINT8, BASE_DEC, VALS (returncode_vals), 0x0, ""}}, {&hf_h1_empty, {"Empty field", "h1.empty", FT_UINT8, BASE_HEX, NULL, 0x0, ""}}, {&hf_h1_empty_len, {"Empty field length", "h1.empty_len", FT_UINT8, BASE_DEC, NULL, 0x0, ""}} }; static gint *ett[] = { &ett_h1, &ett_opcode, &ett_response, &ett_org, &ett_empty }; proto_h1 = proto_register_protocol ("Sinec H1 Protocol", "h1"); proto_register_field_array (proto_h1, hf, array_length (hf)); proto_register_subtree_array (ett, array_length (ett)); } void proto_reg_handoff_h1(void) { heur_dissector_add("cotp_is", dissect_h1); }