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.30 2000/04/15 22:11:12 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.
31 * - add other network protocols (IS-IS)
32 * - add NSAP decoding & resolution
41 #ifdef HAVE_SYS_TYPES_H
42 # include <sys/types.h>
50 #include "packet-h1.h"
52 #include "packet-osi.h"
53 #include "packet-clnp.h"
54 #include "packet-isis.h"
55 #include "packet-esis.h"
58 gchar *print_system_id( const u_char *buffer, int length ) {
61 static gchar str[MAX_SYSTEMID_LEN * 3 + 5]; /* Don't trust exact matching */
63 if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
64 sprintf( str, "<Invalid length of SYSTEM ID>");
69 if ( ( 6 == length ) || ( 7 == length ) ) { /* Special case, print as MAC */
70 cur += sprintf(str, "[%02x:%02x:%02x_%02x:%02x:%02x]", buffer[0], buffer[1],
71 buffer[2], buffer[3], buffer[4], buffer[5] );
73 sprintf( cur, "-%02x", buffer[6] );
78 while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */
79 cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++],
80 buffer[tmp++], buffer[tmp++] );
82 if ( 1 == tmp ) { /* Special case for Designated IS */
83 sprintf( --cur, "-%02x", buffer[tmp] );
86 for ( ; tmp < length; ) { /* print the rest without dot */
87 cur += sprintf( cur, "%02x", buffer[tmp++] );
94 gchar *print_area(const u_char *buffer, int length)
96 /* to do : all real area decoding now: NET is assumed if id len is 1 more byte
97 * and take away all these stupid resource consuming local statics
100 static gchar str[MAX_AREA_LEN * 3 + 20]; /* reserve space for nice layout */
106 if (length <= 0 || length > MAX_AREA_LEN) {
107 sprintf( str, "<Invalid length of AREA>");
111 if ( ( ( NSAP_IDI_ISODCC == *buffer )
112 || ( NSAP_IDI_GOSIP2 == *buffer )
115 ( ( RFC1237_FULLAREA_LEN == length )
116 || ( RFC1237_FULLAREA_LEN + 1 == length )
118 ) { /* AFI is good and length is long enough */
120 if ( length > RFC1237_FULLAREA_LEN + 1 ) { /* Special Case Designated IS */
121 sprintf( str, "<Invalid length of AREA for DCC / GOSIP AFI>");
125 cur += sprintf( cur, "[%02x|%02x:%02x][%02x|%02x:%02x:%02x|%02x:%02x]",
126 buffer[0], buffer[1], buffer[2], buffer[3], buffer[4],
127 buffer[5], buffer[6], buffer[7], buffer[8] );
128 cur += sprintf( cur, "[%02x:%02x|%02x:%02x]",
129 buffer[9], buffer[10], buffer[11], buffer[12] );
130 if ( RFC1237_FULLAREA_LEN + 1 == length ) {
131 sprintf( cur, "-[%02x]", buffer[20] );
135 else { /* print standard format */
137 while ( tmp < length / 4 ) { /* 16/4==4 four Octets left to print */
138 cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++],
139 buffer[tmp++], buffer[tmp++] );
141 if ( 1 == tmp ) { /* Special case for Designated IS */
142 sprintf( --cur, "-%02x", buffer[tmp] );
145 for ( ; tmp < length; ) { /* print the rest without dot */
146 cur += sprintf( cur, "%02x", buffer[tmp++] );
155 gchar *print_nsap_net( const u_char *buffer, int length)
157 /* to do : NSAP / NET decoding */
159 static gchar str[MAX_NSAP_LEN * 3 + 50]; /* reserve space for nice layout */
164 if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) {
165 sprintf( str, "<Invalid length of NSAP>");
168 if ( ( length == RFC1237_NSAP_LEN ) || ( length == RFC1237_NSAP_LEN + 1 ) ) {
169 cur += sprintf( cur, "%s", print_area( buffer, RFC1237_FULLAREA_LEN ) );
170 cur += sprintf( cur, "%s", print_system_id( buffer + RFC1237_FULLAREA_LEN,
171 RFC1237_SYSTEMID_LEN ) );
172 cur += sprintf( cur, "[%02x]",
173 buffer[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] );
174 if ( length == RFC1237_NSAP_LEN + 1 ) {
175 cur += sprintf( cur, "-%02x", buffer[ length -1 ] );
179 else { /* probably format as standard */
180 return( print_area( buffer, length ) );
185 gchar *calc_checksum( const u_char *buffer, u_int len, u_int checksum) {
189 static char *checksum_string[] = { "Not Used",
193 return( checksum_string[0] );
195 for ( count = 0; count < len; count++ ) {
196 calc_sum += (u_int) buffer[count];
198 calc_sum %= 255; /* modulo 255 divison */
201 return( checksum_string[1] );
203 return( checksum_string[2] );
207 /* main entry point */
209 const value_string nlpid_vals[] = {
210 { NLPID_NULL, "NULL" },
211 { NLPID_T_70, "T.70" },
212 { NLPID_X_633, "X.633" },
213 { NLPID_Q_931, "Q.931" },
214 { NLPID_Q_2931, "Q.2931" },
215 { NLPID_Q_2119, "Q.2119" },
216 { NLPID_SNAP, "SNAP" },
217 { NLPID_ISO8473_CLNP, "CLNP" },
218 { NLPID_ISO9542_ESIS, "ESIS" },
219 { NLPID_ISO10589_ISIS, "ISIS" },
220 { NLPID_ISO10747_IDRP, "IDRP" },
221 { NLPID_ISO9542X25_ESIS, "ESIS (X.25)" },
222 { NLPID_ISO10030, "ISO 10030" },
223 { NLPID_ISO11577, "ISO 11577" },
225 { NLPID_PPP, "PPP" },
229 void dissect_osi(const u_char *pd, int offset, frame_data *fd,
232 switch (pd[offset]) {
234 /* ESIS (X.25) is not currently decoded */
236 case NLPID_ISO8473_CLNP:
237 case NLPID_NULL: /* "Inactive Subset" of ISO 8473 CLNP */
238 dissect_clnp(pd, offset, fd, tree);
240 case NLPID_ISO9542_ESIS:
241 dissect_esis(pd, offset, fd, tree);
243 case NLPID_ISO9542X25_ESIS:
244 if (check_col(fd, COL_PROTOCOL)) {
245 col_add_str(fd, COL_PROTOCOL, "ESIS (X.25)");
247 dissect_data(pd, offset, fd, tree);
249 case NLPID_ISO10589_ISIS:
250 dissect_isis(pd, offset, fd, tree);
252 case NLPID_ISO10747_IDRP:
253 if (check_col(fd, COL_PROTOCOL)) {
254 col_add_str(fd, COL_PROTOCOL, "IDRP");
256 dissect_data(pd, offset, fd, tree);
259 if (check_col(fd, COL_PROTOCOL)) {
260 col_add_str(fd, COL_PROTOCOL, "ISO");
262 if (check_col(fd, COL_INFO)) {
263 col_add_fstr(fd, COL_INFO, "Unknown ISO protocol (%02x)", pd[offset]);
265 dissect_data(pd, offset, fd, tree);