MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / epan / dissectors / packet-tali.c
blob0eb02eba6aa253f771f3cc146d1f4c50de6aa355
1 /* packet-tali.c
3 * Routines for Transport Adapter Layer Interface (TALI) version 1.0 dissection (RFC 3094)
5 * Copyright : 2004 Viorel Suman, <vsuman[AT]avmob.ro>
6 * In association with Avalanche Mobile BV, http://www.avmob.com
8 * Dissector of a TALI (Transport Adapter Layer Interface) version 1.0, as defined by the
9 * Tekelec (www.tekelec.com) in RFC 3094, http://www.ietf.org/rfc/rfc3094.txt
11 * $Id$
13 * Refer to the AUTHORS file or the AUTHORS section in the man page
14 * for contacting the author(s) of this file.
16 * Wireshark - Network traffic analyzer
17 * By Gerald Combs <gerald@wireshark.org>
18 * Copyright 1998 Gerald Combs
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version 2
23 * of the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 #define NEW_PROTO_TREE_API
37 #include "config.h"
39 #include <string.h>
40 #include <glib.h>
42 #include <epan/packet.h>
43 #include <epan/prefs.h>
44 #include "packet-tcp.h"
46 #define TALI_SYNC_LENGTH 4
47 #define TALI_OPCODE_LENGTH 4
48 #define TALI_MSU_LENGTH 2
49 #define TALI_HEADER_LENGTH TALI_SYNC_LENGTH + TALI_OPCODE_LENGTH + TALI_MSU_LENGTH
51 #define TALI_SYNC "TALI"
52 #define TALI_TEST "test"
53 #define TALI_ALLO "allo"
54 #define TALI_PROH "proh"
55 #define TALI_PROA "proa"
56 #define TALI_MONI "moni"
57 #define TALI_MONA "mona"
58 #define TALI_SCCP "sccp"
59 #define TALI_ISOT "isot"
60 #define TALI_MTP3 "mtp3"
61 #define TALI_SAAL "saal"
63 /* Initialize the subtree pointers */
64 static gint ett_tali = -1;
65 static gint ett_tali_sync = -1;
66 static gint ett_tali_opcode = -1;
67 static gint ett_tali_msu_length = -1;
69 static header_field_info *hfi_tali = NULL;
71 #define TALI_HFI_INIT HFI_INIT(proto_tali)
73 /* Initialize the protocol and registered fields */
74 static header_field_info hfi_tali_sync_indicator TALI_HFI_INIT =
75 { "Sync", "tali.sync", FT_STRING, BASE_NONE, NULL, 0x00, "TALI SYNC", HFILL };
77 static header_field_info hfi_tali_opcode_indicator TALI_HFI_INIT =
78 { "Opcode", "tali.opcode", FT_STRING, BASE_NONE, NULL, 0x00, "TALI Operation Code", HFILL };
80 static header_field_info hfi_tali_length_indicator TALI_HFI_INIT =
81 { "Length", "tali.msu_length", FT_UINT16, BASE_DEC, NULL, 0x00, "TALI MSU Length", HFILL };
83 static dissector_table_t tali_dissector_table;
85 static dissector_handle_t data_handle;
87 /* Desegment TALI messages */
88 static gboolean tali_desegment = TRUE;
90 /* Code to actually dissect the packets */
91 static guint
92 get_tali_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
94 guint16 length;
96 length = tvb_get_letohs(tvb, offset + TALI_SYNC_LENGTH + TALI_OPCODE_LENGTH);
97 return length+TALI_HEADER_LENGTH;
100 static int
101 dissect_tali_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
103 char opcode[TALI_OPCODE_LENGTH+1]; /* TALI opcode */
104 guint16 length; /* TALI length */
105 tvbuff_t *payload_tvb = NULL;
107 /* Set up structures needed to add the protocol subtree and manage it */
108 proto_item *tali_item = NULL;
109 proto_tree *tali_tree = NULL;
111 tvb_memcpy(tvb, (guint8*)opcode, TALI_SYNC_LENGTH, TALI_OPCODE_LENGTH);
112 opcode[TALI_OPCODE_LENGTH] = '\0';
113 length = tvb_get_letohs(tvb, TALI_SYNC_LENGTH + TALI_OPCODE_LENGTH);
115 /* Make entries in Protocol column on summary display */
116 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TALI");
118 col_set_str(pinfo->cinfo, COL_INFO, "");
119 col_append_fstr(pinfo->cinfo, COL_INFO, "[%s] packet, [%u] bytes in payload", opcode, length);
121 if (tree) {
122 /* create display subtree for the protocol */
123 tali_item = proto_tree_add_item(tree, hfi_tali, tvb, 0, TALI_HEADER_LENGTH, ENC_NA);
124 tali_tree = proto_item_add_subtree(tali_item, ett_tali);
125 proto_tree_add_string(tali_tree, &hfi_tali_sync_indicator, tvb, 0, TALI_SYNC_LENGTH, TALI_SYNC);
126 proto_tree_add_string(tali_tree, &hfi_tali_opcode_indicator, tvb, TALI_SYNC_LENGTH, TALI_OPCODE_LENGTH, opcode);
127 proto_tree_add_uint(tali_tree, &hfi_tali_length_indicator, tvb, TALI_SYNC_LENGTH + TALI_OPCODE_LENGTH, TALI_MSU_LENGTH, length);
130 if (length > 0) {
131 payload_tvb = tvb_new_subset_remaining(tvb, TALI_HEADER_LENGTH);
132 if (payload_tvb != NULL && !dissector_try_string(tali_dissector_table, opcode, payload_tvb, pinfo, tree, NULL)) {
133 call_dissector(data_handle, payload_tvb, pinfo, tree);
137 return tvb_length(tvb);
140 static int
141 dissect_tali(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
143 tcp_dissect_pdus(tvb, pinfo, tree, tali_desegment, TALI_HEADER_LENGTH,
144 get_tali_pdu_len, dissect_tali_pdu, data);
145 return tvb_length(tvb);
149 * A 'heuristic dissector' that attemtps to establish whether we have
150 * a TALI MSU here.
151 * Only works when:
152 * the fixed header is there
153 * it is a 'well-known' operation
155 static gboolean
156 dissect_tali_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
158 char opcode[TALI_OPCODE_LENGTH]; /* TALI opcode */
160 if (tvb_reported_length(tvb) < TALI_HEADER_LENGTH) /* Mandatory header */
161 return FALSE;
163 if (tvb_strneql(tvb, 0, TALI_SYNC, TALI_SYNC_LENGTH) != 0)
164 return FALSE;
166 tvb_memcpy(tvb, (guint8*)opcode, TALI_SYNC_LENGTH, TALI_OPCODE_LENGTH);
167 if (strncmp(opcode, TALI_TEST, TALI_OPCODE_LENGTH) != 0 &&
168 strncmp(opcode, TALI_ALLO, TALI_OPCODE_LENGTH) != 0 &&
169 strncmp(opcode, TALI_PROH, TALI_OPCODE_LENGTH) != 0 &&
170 strncmp(opcode, TALI_PROA, TALI_OPCODE_LENGTH) != 0 &&
171 strncmp(opcode, TALI_MONI, TALI_OPCODE_LENGTH) != 0 &&
172 strncmp(opcode, TALI_MONA, TALI_OPCODE_LENGTH) != 0 &&
173 strncmp(opcode, TALI_SCCP, TALI_OPCODE_LENGTH) != 0 &&
174 strncmp(opcode, TALI_ISOT, TALI_OPCODE_LENGTH) != 0 &&
175 strncmp(opcode, TALI_MTP3, TALI_OPCODE_LENGTH) != 0 &&
176 strncmp(opcode, TALI_SAAL, TALI_OPCODE_LENGTH) != 0)
177 return FALSE;
179 dissect_tali(tvb, pinfo, tree, data);
180 return TRUE;
183 void
184 proto_register_tali(void)
186 #ifndef HAVE_HFI_SECTION_INIT
187 static header_field_info *hfi[] = {
188 &hfi_tali_sync_indicator,
189 &hfi_tali_opcode_indicator,
190 &hfi_tali_length_indicator
192 #endif
194 /* Setup protocol subtree array */
195 static gint *ett[] = {
196 &ett_tali,
197 &ett_tali_sync,
198 &ett_tali_opcode,
199 &ett_tali_msu_length
201 module_t *tali_module;
203 int proto_tali;
205 /* Register the protocol name and description */
206 proto_tali = proto_register_protocol("Transport Adapter Layer Interface v1.0, RFC 3094", "TALI", "tali");
207 hfi_tali = proto_registrar_get_nth(proto_tali);
209 new_register_dissector("tali", dissect_tali, proto_tali);
211 /* Required function calls to register the header fields and subtrees used */
212 proto_register_fields(proto_tali, hfi, array_length(hfi));
213 proto_register_subtree_array(ett, array_length(ett));
215 tali_dissector_table = register_dissector_table("tali.opcode", "Tali OPCODE", FT_STRING, BASE_NONE);
217 tali_module = prefs_register_protocol(proto_tali, NULL);
218 prefs_register_bool_preference(tali_module, "reassemble",
219 "Reassemble TALI messages spanning multiple TCP segments",
220 "Whether the TALI dissector should reassemble messages spanning multiple TCP segments."
221 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
222 &tali_desegment);
225 void
226 proto_reg_handoff_tali(void)
228 heur_dissector_add("tcp", dissect_tali_heur, hfi_tali->id);
230 data_handle = find_dissector("data");