Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/wireshark/wip.git] / epan / dissectors / packet-calcappprotocol.c
1 /* packet-calcappprotocol.c
2  * Routines for the Calculation Application Protocol, a test application of the
3  * rsplib RSerPool implementation
4  * http://www.tdr.wiwi.uni-due.de/forschung/forschungsprojekte/reliable-server-pooling//
5  *
6  * Copyright 2006 by Thomas Dreibholz <dreibh [AT] exp-math.uni-essen.de>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * Copied from README.developer
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  */
28
29 #include "config.h"
30
31 #include <epan/packet.h>
32 #include <epan/sctpppids.h>
33
34
35 #define CALCAPPPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY 0x29097603
36
37 void proto_register_calcappprotocol(void);
38 void proto_reg_handoff_calcappprotocol(void);
39
40 /* Initialize the protocol and registered fields */
41 static int proto_calcappprotocol = -1;
42 static int hf_message_type       = -1;
43 static int hf_message_flags      = -1;
44 static int hf_message_length     = -1;
45 static int hf_message_jobid      = -1;
46 static int hf_message_jobsize    = -1;
47 static int hf_message_completed  = -1;
48
49 /* Initialize the subtree pointers */
50 static gint ett_calcappprotocol = -1;
51
52 /* Dissectors for messages. This is specific to CalcAppProtocol */
53 #define MESSAGE_TYPE_LENGTH      1
54 #define MESSAGE_FLAGS_LENGTH     1
55 #define MESSAGE_LENGTH_LENGTH    2
56 #define MESSAGE_JOBID_LENGTH     4
57 #define MESSAGE_JOBSIZE_LENGTH   8
58 #define MESSAGE_COMPLETED_LENGTH 8
59
60 #define MESSAGE_TYPE_OFFSET      0
61 #define MESSAGE_FLAGS_OFFSET     (MESSAGE_TYPE_OFFSET    + MESSAGE_TYPE_LENGTH)
62 #define MESSAGE_LENGTH_OFFSET    (MESSAGE_FLAGS_OFFSET   + MESSAGE_FLAGS_LENGTH)
63 #define MESSAGE_JOBID_OFFSET     (MESSAGE_LENGTH_OFFSET  + MESSAGE_LENGTH_LENGTH)
64 #define MESSAGE_JOBSIZE_OFFSET   (MESSAGE_JOBID_OFFSET   + MESSAGE_JOBID_OFFSET)
65 #define MESSAGE_COMPLETED_OFFSET (MESSAGE_JOBSIZE_OFFSET + MESSAGE_JOBSIZE_OFFSET)
66
67
68 #define CALCAPP_REQUEST_MESSAGE_TYPE       1
69 #define CALCAPP_ACCEPT_MESSAGE_TYPE        2
70 #define CALCAPP_REJECT_MESSAGE_TYPE        3
71 #define CALCAPP_ABORT_MESSAGE_TYPE         4
72 #define CALCAPP_COMPLETE_MESSAGE_TYPE      5
73 #define CALCAPP_KEEPALIVE_MESSAGE_TYPE     6
74 #define CALCAPP_KEEPALIVE_ACK_MESSAGE_TYPE 7
75
76
77 static const value_string message_type_values[] = {
78   { CALCAPP_REQUEST_MESSAGE_TYPE,        "CalcApp Request" },
79   { CALCAPP_ACCEPT_MESSAGE_TYPE,         "CalcApp Accept" },
80   { CALCAPP_REJECT_MESSAGE_TYPE,         "CalcApp Reject" },
81   { CALCAPP_ABORT_MESSAGE_TYPE,          "CalcApp Abort" },
82   { CALCAPP_COMPLETE_MESSAGE_TYPE,       "CalcApp Complete" },
83   { CALCAPP_KEEPALIVE_MESSAGE_TYPE,      "CalcApp Keep-Alive" },
84   { CALCAPP_KEEPALIVE_ACK_MESSAGE_TYPE,  "CalcApp Keep-Alive Ack" },
85   { 0, NULL }
86 };
87
88
89 static void
90 dissect_calcappprotocol_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *calcappprotocol_tree)
91 {
92   guint8 type;
93
94   type = tvb_get_guint8(message_tvb, MESSAGE_TYPE_OFFSET);
95   col_add_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str_const(type, message_type_values, "Unknown CalcAppProtocol type"));
96
97   proto_tree_add_item(calcappprotocol_tree, hf_message_type,      message_tvb, MESSAGE_TYPE_OFFSET,      MESSAGE_TYPE_LENGTH,      ENC_BIG_ENDIAN);
98   proto_tree_add_item(calcappprotocol_tree, hf_message_flags,     message_tvb, MESSAGE_FLAGS_OFFSET,     MESSAGE_FLAGS_LENGTH,     ENC_BIG_ENDIAN);
99   proto_tree_add_item(calcappprotocol_tree, hf_message_length,    message_tvb, MESSAGE_LENGTH_OFFSET,    MESSAGE_LENGTH_LENGTH,    ENC_BIG_ENDIAN);
100   proto_tree_add_item(calcappprotocol_tree, hf_message_jobid,     message_tvb, MESSAGE_JOBID_OFFSET,     MESSAGE_JOBID_LENGTH,     ENC_BIG_ENDIAN);
101   proto_tree_add_item(calcappprotocol_tree, hf_message_jobsize,   message_tvb, MESSAGE_JOBSIZE_OFFSET,   MESSAGE_JOBSIZE_LENGTH,   ENC_BIG_ENDIAN);
102   proto_tree_add_item(calcappprotocol_tree, hf_message_completed, message_tvb, MESSAGE_COMPLETED_OFFSET, MESSAGE_COMPLETED_LENGTH, ENC_BIG_ENDIAN);
103 }
104
105
106 static int
107 dissect_calcappprotocol(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
108 {
109   proto_item *calcappprotocol_item;
110   proto_tree *calcappprotocol_tree;
111
112   col_set_str(pinfo->cinfo, COL_PROTOCOL, "CalcAppProtocol");
113
114   /* In the interest of speed, if "tree" is NULL, don't do any work not
115      necessary to generate protocol tree items. */
116   if (tree) {
117     /* create the calcappprotocol protocol tree */
118     calcappprotocol_item = proto_tree_add_item(tree, proto_calcappprotocol, message_tvb, 0, -1, ENC_NA);
119     calcappprotocol_tree = proto_item_add_subtree(calcappprotocol_item, ett_calcappprotocol);
120   } else {
121     calcappprotocol_tree = NULL;
122   };
123   /* dissect the message */
124   dissect_calcappprotocol_message(message_tvb, pinfo, calcappprotocol_tree);
125   return(TRUE);
126 }
127
128
129 /* Register the protocol with Wireshark */
130 void
131 proto_register_calcappprotocol(void)
132 {
133
134   /* Setup list of header fields */
135   static hf_register_info hf[] = {
136     { &hf_message_type,      { "Type",      "calcappprotocol.message_type",      FT_UINT8,  BASE_DEC, VALS(message_type_values), 0x0, NULL, HFILL } },
137     { &hf_message_flags,     { "Flags",     "calcappprotocol.message_flags",     FT_UINT8,  BASE_DEC, NULL,                      0x0, NULL, HFILL } },
138     { &hf_message_length,    { "Length",    "calcappprotocol.message_length",    FT_UINT16, BASE_DEC, NULL,                      0x0, NULL, HFILL } },
139     { &hf_message_jobid,     { "JobID",     "calcappprotocol.message_jobid",     FT_UINT32, BASE_DEC, NULL,                      0x0, NULL, HFILL } },
140     { &hf_message_jobsize,   { "JobSize",   "calcappprotocol.message_jobsize",   FT_UINT64, BASE_DEC, NULL,                      0x0, NULL, HFILL } },
141     { &hf_message_completed, { "Completed", "calcappprotocol.message_completed", FT_UINT64, BASE_DEC, NULL,                      0x0, NULL, HFILL } },
142   };
143
144   /* Setup protocol subtree array */
145   static gint *ett[] = {
146     &ett_calcappprotocol
147   };
148
149   /* Register the protocol name and description */
150   proto_calcappprotocol = proto_register_protocol("Calculation Application Protocol", "CalcAppProtocol", "calcappprotocol");
151
152   /* Required function calls to register the header fields and subtrees used */
153   proto_register_field_array(proto_calcappprotocol, hf, array_length(hf));
154   proto_register_subtree_array(ett, array_length(ett));
155 }
156
157 void
158 proto_reg_handoff_calcappprotocol(void)
159 {
160   dissector_handle_t calcappprotocol_handle;
161
162   calcappprotocol_handle = new_create_dissector_handle(dissect_calcappprotocol, proto_calcappprotocol);
163   dissector_add_uint("sctp.ppi", CALCAPPPROTOCOL_PAYLOAD_PROTOCOL_ID_LEGACY, calcappprotocol_handle);
164   dissector_add_uint("sctp.ppi", CALCAPP_PAYLOAD_PROTOCOL_ID, calcappprotocol_handle);
165 }