2 * Routines for ISO/OSI network and transport protocol packet disassembly
3 * Main entrance point and common functions
6 * Laurent Deniel <laurent.deniel@free.fr>
7 * Ralf Schneider <Ralf.Schneider@t-online.de>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/prefs.h>
37 #include <epan/packet.h>
38 #include <epan/llcsaps.h>
39 #include <epan/aftypes.h>
40 #include <epan/nlpid.h>
41 #include <epan/ppptypes.h>
42 #include <epan/chdlctypes.h>
43 #include "packet-osi.h"
44 #include "packet-isis.h"
45 #include "packet-esis.h"
46 #include "packet-tpkt.h"
48 static int proto_osi = -1;
49 static dissector_handle_t osi_handle;
51 /* Preferences for OSI over TPKT over TCP */
52 static gboolean tpkt_desegment = FALSE;
53 static guint global_tcp_port_osi_over_tpkt = 0;
56 calc_checksum( tvbuff_t *tvb, int offset, guint len, guint checksum) {
67 available_len = tvb_length_remaining( tvb, offset );
68 if ( available_len < len )
69 return( DATA_MISSING );
71 buffer = tvb_get_ptr( tvb, offset, len );
74 * The maximum values of c0 and c1 will occur if all bytes have the
75 * value 255; if so, then c0 will be len*255 and c1 will be
76 * (len*255 + (len-1)*255 + ... + 255), which is
77 * (len + (len - 1) + ... + 1)*255, or 255*(len*(len + 1))/2.
78 * This means it can overflow if "len" is 5804 or greater.
80 * (A+B) mod 255 = ((A mod 255) + (B mod 255) mod 255, so
81 * we can solve this by taking c0 and c1 mod 255 every
91 for (i = 0; i < seglen; i++) {
101 if (c0 != 0 || c1 != 0)
102 return( CKSUM_NOT_OK ); /* XXX - what should the checksum field be? */
109 check_and_get_checksum( tvbuff_t *tvb, int offset, guint len, guint checksum, int offset_check, guint16* result) {
114 guint32 c0, c1, factor;
115 guint seglen, initlen = len;
122 available_len = tvb_length_remaining( tvb, offset );
123 offset_check -= offset;
124 if ( ( available_len < len ) || ( offset_check < 0 ) || ( (guint)(offset_check+2) > len ) )
125 return( DATA_MISSING );
127 buffer = tvb_get_ptr( tvb, offset, len );
128 block = offset_check / 5803;
131 * The maximum values of c0 and c1 will occur if all bytes have the
132 * value 255; if so, then c0 will be len*255 and c1 will be
133 * (len*255 + (len-1)*255 + ... + 255), which is
134 * (len + (len - 1) + ... + 1)*255, or 255*(len*(len + 1))/2.
135 * This means it can overflow if "len" is 5804 or greater.
137 * (A+B) mod 255 = ((A mod 255) + (B mod 255) mod 255, so
138 * we can solve this by taking c0 and c1 mod 255 every
147 if ( block-- == 0 ) {
148 seglen = offset_check % 5803;
150 } else if ( seglen > 5803 )
152 for (i = 0; i < seglen; i++) {
158 * This works even if (offset_check % 5803) == 5802
172 factor = ( initlen - offset_check ) * c0;
173 x = factor - c0 - c1;
177 * This algorithm uses the 8 bits one's complement arithmetic.
178 * Therefore, we must correct an effect produced
179 * by the "standard" arithmetic (two's complement)
188 if (x == 0) x = 0xFF;
189 if (y == 0) y = 0x01;
191 *result = ( x << 8 ) | ( y & 0xFF );
193 if (*result != checksum)
194 return( CKSUM_NOT_OK ); /* XXX - what should the checksum field be? */
201 /* main entry point */
204 * These assume the NLPID is a secondary protocol identifier, not an
205 * initial protocol identifier.
207 * This is an issue only if, in any packet where an NLPID appears, it's
208 * an initial protocol identifier *AND* it can have the value 1, which
209 * means T.70 for an IPI and X.29 for an SPI.
211 const value_string nlpid_vals[] = {
212 { NLPID_NULL, "NULL" },
213 { NLPID_SPI_X_29, "X.29" },
214 { NLPID_X_633, "X.633" },
215 { NLPID_Q_931, "Q.931" },
216 { NLPID_Q_2931, "Q.2931" },
217 { NLPID_Q_2119, "Q.2119" },
218 { NLPID_SNAP, "SNAP" },
219 { NLPID_ISO8473_CLNP, "CLNP" },
220 { NLPID_ISO9542_ESIS, "ESIS" },
221 { NLPID_ISO10589_ISIS, "ISIS" },
222 { NLPID_ISO10747_IDRP, "IDRP" },
223 { NLPID_ISO9542X25_ESIS, "ESIS (X.25)" },
224 { NLPID_ISO10030, "ISO 10030" },
225 { NLPID_ISO11577, "ISO 11577" },
226 { NLPID_COMPRESSED, "Data compression protocol" },
228 { NLPID_SNDCF, "SubNetwork Dependent Convergence Function"},
229 { NLPID_IP6, "IPv6" },
230 { NLPID_PPP, "PPP" },
234 static dissector_table_t osinl_subdissector_table;
235 static dissector_table_t osinl_excl_subdissector_table;
236 static dissector_handle_t data_handle, ppp_handle;
238 /* Dissect OSI over TCP over TPKT */
240 dissect_osi_tpkt(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
242 dissect_tpkt_encap(tvb, pinfo, tree, tpkt_desegment, osi_handle);
245 static void dissect_osi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
250 pinfo->current_proto = "OSI";
252 nlpid = tvb_get_guint8(tvb, 0);
254 /* try lookup with the subdissector tables that includes the nlpid */
255 if (dissector_try_port(osinl_subdissector_table, nlpid, tvb, pinfo, tree))
257 /* try lookup with the subdissector tables that excludes the nlpid */
258 new_tvb = tvb_new_subset(tvb, 1, -1, -1);
259 if (dissector_try_port(osinl_excl_subdissector_table, nlpid, new_tvb, pinfo, tree))
264 /* ESIS (X.25) is not currently decoded */
266 case NLPID_ISO9542X25_ESIS:
267 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
268 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIS (X.25)");
270 call_dissector(data_handle,tvb, pinfo, tree);
272 case NLPID_ISO10747_IDRP:
273 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
274 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IDRP");
276 call_dissector(data_handle,tvb, pinfo, tree);
279 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
280 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ISO");
282 if (check_col(pinfo->cinfo, COL_INFO)) {
283 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown ISO protocol (%02x)", nlpid);
285 call_dissector(data_handle,tvb, pinfo, tree);
291 proto_reg_handoff_osi(void)
293 static gboolean osi_prefs_initialized = FALSE;
294 static dissector_handle_t osi_tpkt_handle;
295 static guint tcp_port_osi_over_tpkt;
297 if (!osi_prefs_initialized) {
298 osi_handle = create_dissector_handle(dissect_osi, proto_osi);
299 dissector_add("llc.dsap", SAP_OSINL1, osi_handle);
300 dissector_add("llc.dsap", SAP_OSINL2, osi_handle);
301 dissector_add("llc.dsap", SAP_OSINL3, osi_handle);
302 dissector_add("llc.dsap", SAP_OSINL4, osi_handle);
303 dissector_add("llc.dsap", SAP_OSINL5, osi_handle);
304 dissector_add("ppp.protocol", PPP_OSI, osi_handle);
305 dissector_add("chdlctype", CHDLCTYPE_OSI, osi_handle);
306 dissector_add("null.type", BSD_AF_ISO, osi_handle);
307 dissector_add("gre.proto", SAP_OSINL5, osi_handle);
308 data_handle = find_dissector("data");
309 ppp_handle = find_dissector("ppp");
311 osi_tpkt_handle = create_dissector_handle(dissect_osi_tpkt, proto_osi);
312 dissector_add_handle("tcp.port", osi_tpkt_handle); /* for 'decode-as' */
313 osi_prefs_initialized = TRUE;
315 if (tcp_port_osi_over_tpkt != 0) {
316 dissector_delete("tcp.port", tcp_port_osi_over_tpkt, osi_tpkt_handle);
320 if (global_tcp_port_osi_over_tpkt != 0) {
321 dissector_add("tcp.port", global_tcp_port_osi_over_tpkt, osi_tpkt_handle);
323 tcp_port_osi_over_tpkt = global_tcp_port_osi_over_tpkt;
327 proto_register_osi(void)
329 module_t *osi_module;
331 /* There's no "OSI" protocol *per se*, but we do register a
332 dissector table so various protocols running at the
333 network layer can register themselves.
334 all protocols that require inclusion of the NLPID
337 osinl_subdissector_table = register_dissector_table("osinl",
338 "OSI incl NLPID", FT_UINT8, BASE_HEX);
340 /* This dissector table is for those protocols whose PDUs
341 * aren't* defined to begin with an NLPID.
342 * (typically non OSI protocols like IP,IPv6,PPP */
343 osinl_excl_subdissector_table = register_dissector_table("osinl.excl",
344 "OSI excl NLPID", FT_UINT8, BASE_HEX);
346 proto_osi = proto_register_protocol("OSI", "OSI", "osi");
347 /* Preferences how OSI protocols should be dissected */
348 osi_module = prefs_register_protocol(proto_osi, proto_reg_handoff_osi);
350 prefs_register_uint_preference(osi_module, "tpkt_port",
351 "TCP port for OSI over TPKT",
352 "TCP port for OSI over TPKT",
353 10, &global_tcp_port_osi_over_tpkt);
354 prefs_register_bool_preference(osi_module, "tpkt_reassemble",
355 "Reassemble segmented TPKT datagrams",
356 "Whether segmented TPKT datagrams should be reassembled",