Fix Gerald's address.
[obnox/wireshark/wip.git] / packet-osi.c
1 /* packet-osi.c
2  * Routines for ISO/OSI network and transport protocol packet disassembly
3  * Main entrance point and common functions
4  *
5  * $Id: packet-osi.c,v 1.44 2001/04/16 10:04:30 guy Exp $
6  * Laurent Deniel <deniel@worldnet.fr>
7  * Ralf Schneider <Ralf.Schneider@t-online.de>
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@zing.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * 
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.
18  * 
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.
23  * 
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.
27  *
28  */
29
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
33
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #include <stdio.h>
39 #include <string.h>
40 #include <ctype.h>
41 #include <glib.h>
42 #include "packet.h"
43 #include "llcsaps.h"
44 #include "aftypes.h"
45 #include "nlpid.h"
46 #include "ppptypes.h"
47 #include "packet-osi.h"
48 #include "packet-isis.h"
49 #include "packet-esis.h"
50
51
52 gchar *calc_checksum( tvbuff_t *tvb, int offset, u_int len, u_int checksum) {
53   u_int   calc_sum = 0;
54   u_int   count    = 0;
55   const gchar *buffer;
56   guint   available_len;
57
58   if ( 0 == checksum )
59     return( "Not Used" );
60
61   available_len = tvb_length_remaining( tvb, offset );
62   if ( available_len < len )
63     return( "Not checkable - not all of packet was captured" );
64
65   buffer = tvb_get_ptr( tvb, offset, len );
66   for ( count = 0; count < len; count++ ) {
67     calc_sum += (u_int) buffer[count];
68   }
69   calc_sum %= 255;  /* modulo 255 divison */
70   
71   if ( 0 == calc_sum )
72     return( "Is good" );
73   else
74     return( "Is wrong" );       /* XXX - what should the checksum be? */
75 }
76
77
78 /* main entry point */
79
80 const value_string nlpid_vals[] = {
81         { NLPID_NULL,            "NULL" },
82         { NLPID_T_70,            "T.70" },
83         { NLPID_X_633,           "X.633" },
84         { NLPID_Q_931,           "Q.931" },
85         { NLPID_Q_2931,          "Q.2931" },
86         { NLPID_Q_2119,          "Q.2119" },
87         { NLPID_SNAP,            "SNAP" },
88         { NLPID_ISO8473_CLNP,    "CLNP" },
89         { NLPID_ISO9542_ESIS,    "ESIS" },
90         { NLPID_ISO10589_ISIS,   "ISIS" },
91         { NLPID_ISO10747_IDRP,   "IDRP" },
92         { NLPID_ISO9542X25_ESIS, "ESIS (X.25)" },
93         { NLPID_ISO10030,        "ISO 10030" },
94         { NLPID_ISO11577,        "ISO 11577" },
95         { NLPID_COMPRESSED,      "Data compression protocol" },
96         { NLPID_IP,              "IP" },
97         { NLPID_IP6,             "IPv6" },
98         { NLPID_PPP,             "PPP" },
99         { 0,                     NULL },
100 };
101
102 dissector_table_t osinl_subdissector_table;
103
104 static void dissect_osi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) 
105 {
106   guint8 nlpid;
107
108   pinfo->current_proto = "OSI";
109
110   nlpid = tvb_get_guint8(tvb, 0);
111
112   /* do lookup with the subdissector table */
113   if (dissector_try_port(osinl_subdissector_table, nlpid, tvb, pinfo, tree))
114       return;
115
116   switch (nlpid) {
117
118     /* ESIS (X.25) is not currently decoded */
119
120     case NLPID_ISO9542X25_ESIS:
121       if (check_col(pinfo->fd, COL_PROTOCOL)) {
122         col_set_str(pinfo->fd, COL_PROTOCOL, "ESIS (X.25)");
123       }
124       dissect_data(tvb, 0, pinfo, tree);
125       break;
126     case NLPID_ISO10747_IDRP:
127       if (check_col(pinfo->fd, COL_PROTOCOL)) {
128         col_set_str(pinfo->fd, COL_PROTOCOL, "IDRP");
129       }
130       dissect_data(tvb, 0, pinfo, tree);
131       break;
132     default:
133       if (check_col(pinfo->fd, COL_PROTOCOL)) {
134         col_set_str(pinfo->fd, COL_PROTOCOL, "ISO");
135       }
136       if (check_col(pinfo->fd, COL_INFO)) {
137         col_add_fstr(pinfo->fd, COL_INFO, "Unknown ISO protocol (%02x)", nlpid);
138       }
139       dissect_data(tvb, 0, pinfo, tree);
140       break;
141   }
142 } /* dissect_osi */
143
144 void
145 proto_register_osi(void)
146 {
147         /* There's no "OSI" protocol *per se*, but we do register a
148            dissector table so various protocols running at the
149            network layer can register themselves. */
150         osinl_subdissector_table = register_dissector_table("osinl");
151 }
152
153 void
154 proto_reg_handoff_osi(void)
155 {
156         dissector_add("llc.dsap", SAP_OSINL, dissect_osi, -1);
157         dissector_add("ppp.protocol", PPP_OSI, dissect_osi, -1);
158         dissector_add("null.type", BSD_AF_ISO, dissect_osi, -1);
159 }