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.36 2000/11/18 10:38:24 guy Exp $
6 * Laurent Deniel <deniel@worldnet.fr>
7 * Ralf Schneider <Ralf.Schneider@t-online.de>
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@zing.org>
11 * Copyright 1998 Gerald Combs
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
46 #include "packet-osi.h"
47 #include "packet-clnp.h"
48 #include "packet-isis.h"
49 #include "packet-esis.h"
52 gchar *print_system_id( const u_char *buffer, int length ) {
55 static gchar str[MAX_SYSTEMID_LEN * 3 + 5]; /* Don't trust exact matching */
57 if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
58 sprintf( str, "<Invalid length of SYSTEM ID>");
63 if ( ( 6 == length ) || ( 7 == length ) ) { /* Special case, print as MAC */
64 cur += sprintf(str, "[%02x:%02x:%02x_%02x:%02x:%02x]", buffer[0], buffer[1],
65 buffer[2], buffer[3], buffer[4], buffer[5] );
67 sprintf( cur, "-%02x", buffer[6] );
72 while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */
73 cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++],
74 buffer[tmp++], buffer[tmp++] );
76 if ( 1 == tmp ) { /* Special case for Designated IS */
77 sprintf( --cur, "-%02x", buffer[tmp] );
80 for ( ; tmp < length; ) { /* print the rest without dot */
81 cur += sprintf( cur, "%02x", buffer[tmp++] );
88 gchar *print_area(const u_char *buffer, int length)
90 /* to do : all real area decoding now: NET is assumed if id len is 1 more byte
91 * and take away all these stupid resource consuming local statics
94 static gchar str[MAX_AREA_LEN * 3 + 20]; /* reserve space for nice layout */
100 if (length <= 0 || length > MAX_AREA_LEN) {
101 sprintf( str, "<Invalid length of AREA>");
105 if ( ( ( NSAP_IDI_ISODCC == *buffer )
106 || ( NSAP_IDI_GOSIP2 == *buffer )
109 ( ( RFC1237_FULLAREA_LEN == length )
110 || ( RFC1237_FULLAREA_LEN + 1 == length )
112 ) { /* AFI is good and length is long enough */
114 if ( length > RFC1237_FULLAREA_LEN + 1 ) { /* Special Case Designated IS */
115 sprintf( str, "<Invalid length of AREA for DCC / GOSIP AFI>");
119 cur += sprintf( cur, "[%02x|%02x:%02x][%02x|%02x:%02x:%02x|%02x:%02x]",
120 buffer[0], buffer[1], buffer[2], buffer[3], buffer[4],
121 buffer[5], buffer[6], buffer[7], buffer[8] );
122 cur += sprintf( cur, "[%02x:%02x|%02x:%02x]",
123 buffer[9], buffer[10], buffer[11], buffer[12] );
124 if ( RFC1237_FULLAREA_LEN + 1 == length ) {
125 sprintf( cur, "-[%02x]", buffer[20] );
129 else { /* print standard format */
131 while ( tmp < length / 4 ) { /* 16/4==4 four Octets left to print */
132 cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++],
133 buffer[tmp++], buffer[tmp++] );
135 if ( 1 == tmp ) { /* Special case for Designated IS */
136 sprintf( --cur, "-%02x", buffer[tmp] );
139 for ( ; tmp < length; ) { /* print the rest without dot */
140 cur += sprintf( cur, "%02x", buffer[tmp++] );
149 gchar *print_nsap_net( const u_char *buffer, int length)
151 /* to do : NSAP / NET decoding */
153 static gchar str[MAX_NSAP_LEN * 3 + 50]; /* reserve space for nice layout */
158 if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) {
159 sprintf( str, "<Invalid length of NSAP>");
162 if ( ( length == RFC1237_NSAP_LEN ) || ( length == RFC1237_NSAP_LEN + 1 ) ) {
163 cur += sprintf( cur, "%s", print_area( buffer, RFC1237_FULLAREA_LEN ) );
164 cur += sprintf( cur, "%s", print_system_id( buffer + RFC1237_FULLAREA_LEN,
165 RFC1237_SYSTEMID_LEN ) );
166 cur += sprintf( cur, "[%02x]",
167 buffer[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] );
168 if ( length == RFC1237_NSAP_LEN + 1 ) {
169 cur += sprintf( cur, "-%02x", buffer[ length -1 ] );
173 else { /* probably format as standard */
174 return( print_area( buffer, length ) );
179 gchar *calc_checksum( tvbuff_t *tvb, int offset, u_int len, u_int checksum) {
186 return( "Not Used" );
188 available_len = tvb_length_remaining( tvb, offset );
189 if ( available_len < len )
190 return( "Not checkable - not all of packet was captured" );
192 buffer = tvb_get_ptr( tvb, offset, len );
193 for ( count = 0; count < len; count++ ) {
194 calc_sum += (u_int) buffer[count];
196 calc_sum %= 255; /* modulo 255 divison */
201 return( "Is wrong" ); /* XXX - what should the checksum be? */
205 /* main entry point */
207 const value_string nlpid_vals[] = {
208 { NLPID_NULL, "NULL" },
209 { NLPID_T_70, "T.70" },
210 { NLPID_X_633, "X.633" },
211 { NLPID_Q_931, "Q.931" },
212 { NLPID_Q_2931, "Q.2931" },
213 { NLPID_Q_2119, "Q.2119" },
214 { NLPID_SNAP, "SNAP" },
215 { NLPID_ISO8473_CLNP, "CLNP" },
216 { NLPID_ISO9542_ESIS, "ESIS" },
217 { NLPID_ISO10589_ISIS, "ISIS" },
218 { NLPID_ISO10747_IDRP, "IDRP" },
219 { NLPID_ISO9542X25_ESIS, "ESIS (X.25)" },
220 { NLPID_ISO10030, "ISO 10030" },
221 { NLPID_ISO11577, "ISO 11577" },
223 { NLPID_PPP, "PPP" },
227 static dissector_table_t subdissector_table;
229 void dissect_osi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
233 pinfo->current_proto = "OSI";
235 nlpid = tvb_get_guint8(tvb, 0);
237 /* do lookup with the subdissector table */
238 if (dissector_try_port(subdissector_table, nlpid, tvb, pinfo, tree))
243 /* ESIS (X.25) is not currently decoded */
245 case NLPID_ISO9542X25_ESIS:
246 if (check_col(pinfo->fd, COL_PROTOCOL)) {
247 col_add_str(pinfo->fd, COL_PROTOCOL, "ESIS (X.25)");
249 dissect_data(tvb, 0, pinfo, tree);
251 case NLPID_ISO10747_IDRP:
252 if (check_col(pinfo->fd, COL_PROTOCOL)) {
253 col_add_str(pinfo->fd, COL_PROTOCOL, "IDRP");
255 dissect_data(tvb, 0, pinfo, tree);
258 if (check_col(pinfo->fd, COL_PROTOCOL)) {
259 col_add_str(pinfo->fd, COL_PROTOCOL, "ISO");
261 if (check_col(pinfo->fd, COL_INFO)) {
262 col_add_fstr(pinfo->fd, COL_INFO, "Unknown ISO protocol (%02x)", nlpid);
264 dissect_data(tvb, 0, pinfo, tree);
270 proto_register_osi(void)
272 /* There's no "OSI" protocol *per se*, but we do register a
273 dissector table so various protocols running at the
274 network layer can register themselves. */
275 subdissector_table = register_dissector_table("osinl");
279 proto_reg_handoff_osi(void)
281 dissector_add("llc.dsap", SAP_OSINL, dissect_osi);
282 dissector_add("null.type", BSD_AF_ISO, dissect_osi);