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.38 2000/11/19 08:54:00 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-isis.h"
48 #include "packet-esis.h"
51 gchar *print_system_id( const u_char *buffer, int length ) {
54 static gchar str[MAX_SYSTEMID_LEN * 3 + 5]; /* Don't trust exact matching */
56 if ( ( length <= 0 ) || ( length > MAX_SYSTEMID_LEN ) ) {
57 sprintf( str, "<Invalid length of SYSTEM ID>");
62 if ( ( 6 == length ) || ( 7 == length ) ) { /* Special case, print as MAC */
63 cur += sprintf(str, "[%02x:%02x:%02x_%02x:%02x:%02x]", buffer[0], buffer[1],
64 buffer[2], buffer[3], buffer[4], buffer[5] );
66 sprintf( cur, "-%02x", buffer[6] );
71 while ( tmp < length / 4 ) { /* 16 / 4 == 4 > four Octets left to print */
72 cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++],
73 buffer[tmp++], buffer[tmp++] );
75 if ( 1 == tmp ) { /* Special case for Designated IS */
76 sprintf( --cur, "-%02x", buffer[tmp] );
79 for ( ; tmp < length; ) { /* print the rest without dot */
80 cur += sprintf( cur, "%02x", buffer[tmp++] );
87 gchar *print_area(const u_char *buffer, int length)
89 /* to do : all real area decoding now: NET is assumed if id len is 1 more byte
90 * and take away all these stupid resource consuming local statics
93 static gchar str[MAX_AREA_LEN * 3 + 20]; /* reserve space for nice layout */
99 if (length <= 0 || length > MAX_AREA_LEN) {
100 sprintf( str, "<Invalid length of AREA>");
104 if ( ( ( NSAP_IDI_ISODCC == *buffer )
105 || ( NSAP_IDI_GOSIP2 == *buffer )
108 ( ( RFC1237_FULLAREA_LEN == length )
109 || ( RFC1237_FULLAREA_LEN + 1 == length )
111 ) { /* AFI is good and length is long enough */
113 if ( length > RFC1237_FULLAREA_LEN + 1 ) { /* Special Case Designated IS */
114 sprintf( str, "<Invalid length of AREA for DCC / GOSIP AFI>");
118 cur += sprintf( cur, "[%02x|%02x:%02x][%02x|%02x:%02x:%02x|%02x:%02x]",
119 buffer[0], buffer[1], buffer[2], buffer[3], buffer[4],
120 buffer[5], buffer[6], buffer[7], buffer[8] );
121 cur += sprintf( cur, "[%02x:%02x|%02x:%02x]",
122 buffer[9], buffer[10], buffer[11], buffer[12] );
123 if ( RFC1237_FULLAREA_LEN + 1 == length ) {
124 sprintf( cur, "-[%02x]", buffer[20] );
128 else { /* print standard format */
130 while ( tmp < length / 4 ) { /* 16/4==4 four Octets left to print */
131 cur += sprintf( str, "%02x%02x%02x%02x.", buffer[tmp++], buffer[tmp++],
132 buffer[tmp++], buffer[tmp++] );
134 if ( 1 == tmp ) { /* Special case for Designated IS */
135 sprintf( --cur, "-%02x", buffer[tmp] );
138 for ( ; tmp < length; ) { /* print the rest without dot */
139 cur += sprintf( cur, "%02x", buffer[tmp++] );
148 gchar *print_nsap_net( const u_char *buffer, int length)
150 /* to do : NSAP / NET decoding */
152 static gchar str[MAX_NSAP_LEN * 3 + 50]; /* reserve space for nice layout */
157 if ( (length <= 0 ) || ( length > MAX_NSAP_LEN ) ) {
158 sprintf( str, "<Invalid length of NSAP>");
161 if ( ( length == RFC1237_NSAP_LEN ) || ( length == RFC1237_NSAP_LEN + 1 ) ) {
162 cur += sprintf( cur, "%s", print_area( buffer, RFC1237_FULLAREA_LEN ) );
163 cur += sprintf( cur, "%s", print_system_id( buffer + RFC1237_FULLAREA_LEN,
164 RFC1237_SYSTEMID_LEN ) );
165 cur += sprintf( cur, "[%02x]",
166 buffer[ RFC1237_FULLAREA_LEN + RFC1237_SYSTEMID_LEN ] );
167 if ( length == RFC1237_NSAP_LEN + 1 ) {
168 cur += sprintf( cur, "-%02x", buffer[ length -1 ] );
172 else { /* probably format as standard */
173 return( print_area( buffer, length ) );
178 gchar *calc_checksum( tvbuff_t *tvb, int offset, u_int len, u_int checksum) {
185 return( "Not Used" );
187 available_len = tvb_length_remaining( tvb, offset );
188 if ( available_len < len )
189 return( "Not checkable - not all of packet was captured" );
191 buffer = tvb_get_ptr( tvb, offset, len );
192 for ( count = 0; count < len; count++ ) {
193 calc_sum += (u_int) buffer[count];
195 calc_sum %= 255; /* modulo 255 divison */
200 return( "Is wrong" ); /* XXX - what should the checksum be? */
204 /* main entry point */
206 const value_string nlpid_vals[] = {
207 { NLPID_NULL, "NULL" },
208 { NLPID_T_70, "T.70" },
209 { NLPID_X_633, "X.633" },
210 { NLPID_Q_931, "Q.931" },
211 { NLPID_Q_2931, "Q.2931" },
212 { NLPID_Q_2119, "Q.2119" },
213 { NLPID_SNAP, "SNAP" },
214 { NLPID_ISO8473_CLNP, "CLNP" },
215 { NLPID_ISO9542_ESIS, "ESIS" },
216 { NLPID_ISO10589_ISIS, "ISIS" },
217 { NLPID_ISO10747_IDRP, "IDRP" },
218 { NLPID_ISO9542X25_ESIS, "ESIS (X.25)" },
219 { NLPID_ISO10030, "ISO 10030" },
220 { NLPID_ISO11577, "ISO 11577" },
222 { NLPID_PPP, "PPP" },
226 static dissector_table_t subdissector_table;
228 void dissect_osi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
232 pinfo->current_proto = "OSI";
234 nlpid = tvb_get_guint8(tvb, 0);
236 /* do lookup with the subdissector table */
237 if (dissector_try_port(subdissector_table, nlpid, tvb, pinfo, tree))
242 /* ESIS (X.25) is not currently decoded */
244 case NLPID_ISO9542X25_ESIS:
245 if (check_col(pinfo->fd, COL_PROTOCOL)) {
246 col_set_str(pinfo->fd, COL_PROTOCOL, "ESIS (X.25)");
248 dissect_data(tvb, 0, pinfo, tree);
250 case NLPID_ISO10747_IDRP:
251 if (check_col(pinfo->fd, COL_PROTOCOL)) {
252 col_set_str(pinfo->fd, COL_PROTOCOL, "IDRP");
254 dissect_data(tvb, 0, pinfo, tree);
257 if (check_col(pinfo->fd, COL_PROTOCOL)) {
258 col_set_str(pinfo->fd, COL_PROTOCOL, "ISO");
260 if (check_col(pinfo->fd, COL_INFO)) {
261 col_add_fstr(pinfo->fd, COL_INFO, "Unknown ISO protocol (%02x)", nlpid);
263 dissect_data(tvb, 0, pinfo, tree);
269 proto_register_osi(void)
271 /* There's no "OSI" protocol *per se*, but we do register a
272 dissector table so various protocols running at the
273 network layer can register themselves. */
274 subdissector_table = register_dissector_table("osinl");
278 proto_reg_handoff_osi(void)
280 dissector_add("llc.dsap", SAP_OSINL, dissect_osi);
281 dissector_add("null.type", BSD_AF_ISO, dissect_osi);