2 * Routines for ISO/OSI network and transport protocol packet disassembly
3 * Main entrance point and common functions
5 * $Id: packet-osi.c,v 1.59 2003/02/24 19:49:03 guy Exp $
6 * Laurent Deniel <laurent.deniel@free.fr>
7 * Ralf Schneider <Ralf.Schneider@t-online.de>
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
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/packet.h>
41 #include "chdlctypes.h"
42 #include "packet-osi.h"
43 #include "packet-isis.h"
44 #include "packet-esis.h"
48 calc_checksum( tvbuff_t *tvb, int offset, guint len, guint checksum) {
59 available_len = tvb_length_remaining( tvb, offset );
60 if ( available_len < len )
61 return( DATA_MISSING );
63 buffer = tvb_get_ptr( tvb, offset, len );
66 * The maximum values of c0 and c1 will occur if all bytes have the
67 * value 255; if so, then c0 will be len*255 and c1 will be
68 * (len*255 + (len-1)*255 + ... + 255), which is
69 * (len + (len - 1) + ... + 1)*255, or 255*(len*(len + 1))/2.
70 * This means it can overflow if "len" is 5804 or greater.
72 * (A+B) mod 255 = ((A mod 255) + (B mod 255) mod 255, so
73 * we can solve this by taking c0 and c1 mod 255 every
83 for (i = 0; i < seglen; i++) {
93 if (c0 != 0 || c1 != 0)
94 return( CKSUM_NOT_OK ); /* XXX - what should the checksum be? */
100 /* main entry point */
103 * These assume the NLPID is a secondary protocol identifier, not an
104 * initial protocol identifier.
106 * This is an issue only if, in any packet where an NLPID appears, it's
107 * an initial protocol identifier *AND* it can have the value 1, which
108 * means T.70 for an IPI and X.29 for an SPI.
110 const value_string nlpid_vals[] = {
111 { NLPID_NULL, "NULL" },
112 { NLPID_SPI_X_29, "X.29" },
113 { NLPID_X_633, "X.633" },
114 { NLPID_Q_931, "Q.931" },
115 { NLPID_Q_2931, "Q.2931" },
116 { NLPID_Q_2119, "Q.2119" },
117 { NLPID_SNAP, "SNAP" },
118 { NLPID_ISO8473_CLNP, "CLNP" },
119 { NLPID_ISO9542_ESIS, "ESIS" },
120 { NLPID_ISO10589_ISIS, "ISIS" },
121 { NLPID_ISO10747_IDRP, "IDRP" },
122 { NLPID_ISO9542X25_ESIS, "ESIS (X.25)" },
123 { NLPID_ISO10030, "ISO 10030" },
124 { NLPID_ISO11577, "ISO 11577" },
125 { NLPID_COMPRESSED, "Data compression protocol" },
127 { NLPID_SNDCF, "SubNetwork Dependent Convergence Function"},
128 { NLPID_IP6, "IPv6" },
129 { NLPID_PPP, "PPP" },
133 dissector_table_t osinl_subdissector_table;
134 static dissector_handle_t data_handle;
136 static void dissect_osi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
140 pinfo->current_proto = "OSI";
142 nlpid = tvb_get_guint8(tvb, 0);
144 /* do lookup with the subdissector table */
145 if (dissector_try_port(osinl_subdissector_table, nlpid, tvb, pinfo, tree))
150 /* ESIS (X.25) is not currently decoded */
152 case NLPID_ISO9542X25_ESIS:
153 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
154 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIS (X.25)");
156 call_dissector(data_handle,tvb, pinfo, tree);
158 case NLPID_ISO10747_IDRP:
159 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
160 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IDRP");
162 call_dissector(data_handle,tvb, pinfo, tree);
165 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
166 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ISO");
168 if (check_col(pinfo->cinfo, COL_INFO)) {
169 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown ISO protocol (%02x)", nlpid);
171 call_dissector(data_handle,tvb, pinfo, tree);
177 proto_register_osi(void)
179 /* There's no "OSI" protocol *per se*, but we do register a
180 dissector table so various protocols running at the
181 network layer can register themselves. */
182 osinl_subdissector_table = register_dissector_table("osinl",
183 "OSI NLPID", FT_UINT8, BASE_HEX);
187 proto_reg_handoff_osi(void)
189 dissector_handle_t osi_handle;
191 osi_handle = create_dissector_handle(dissect_osi, -1);
192 dissector_add("llc.dsap", SAP_OSINL, osi_handle);
193 dissector_add("ppp.protocol", PPP_OSI, osi_handle);
194 dissector_add("chdlctype", CHDLCTYPE_OSI, osi_handle);
195 dissector_add("null.type", BSD_AF_ISO, osi_handle);
196 dissector_add("gre.proto", SAP_OSINL, osi_handle);
197 data_handle = find_dissector("data");