Added two new arguments to epan_init() and proto_init() to
[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.42 2001/04/01 05:48:14 hagbard 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 "packet-osi.h"
47 #include "packet-isis.h"
48 #include "packet-esis.h"
49
50
51 gchar *calc_checksum( tvbuff_t *tvb, int offset, u_int len, u_int checksum) {
52   u_int   calc_sum = 0;
53   u_int   count    = 0;
54   const gchar *buffer;
55   guint   available_len;
56
57   if ( 0 == checksum )
58     return( "Not Used" );
59
60   available_len = tvb_length_remaining( tvb, offset );
61   if ( available_len < len )
62     return( "Not checkable - not all of packet was captured" );
63
64   buffer = tvb_get_ptr( tvb, offset, len );
65   for ( count = 0; count < len; count++ ) {
66     calc_sum += (u_int) buffer[count];
67   }
68   calc_sum %= 255;  /* modulo 255 divison */
69   
70   if ( 0 == calc_sum )
71     return( "Is good" );
72   else
73     return( "Is wrong" );       /* XXX - what should the checksum be? */
74 }
75
76
77 /* main entry point */
78
79 const value_string nlpid_vals[] = {
80         { NLPID_NULL,            "NULL" },
81         { NLPID_T_70,            "T.70" },
82         { NLPID_X_633,           "X.633" },
83         { NLPID_Q_931,           "Q.931" },
84         { NLPID_Q_2931,          "Q.2931" },
85         { NLPID_Q_2119,          "Q.2119" },
86         { NLPID_SNAP,            "SNAP" },
87         { NLPID_ISO8473_CLNP,    "CLNP" },
88         { NLPID_ISO9542_ESIS,    "ESIS" },
89         { NLPID_ISO10589_ISIS,   "ISIS" },
90         { NLPID_ISO10747_IDRP,   "IDRP" },
91         { NLPID_ISO9542X25_ESIS, "ESIS (X.25)" },
92         { NLPID_ISO10030,        "ISO 10030" },
93         { NLPID_ISO11577,        "ISO 11577" },
94         { NLPID_COMPRESSED,      "Data compression protocol" },
95         { NLPID_IP,              "IP" },
96         { NLPID_PPP,             "PPP" },
97         { 0,                     NULL },
98 };
99
100 dissector_table_t osinl_subdissector_table;
101
102 static void dissect_osi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) 
103 {
104   guint8 nlpid;
105
106   pinfo->current_proto = "OSI";
107
108   nlpid = tvb_get_guint8(tvb, 0);
109
110   /* do lookup with the subdissector table */
111   if (dissector_try_port(osinl_subdissector_table, nlpid, tvb, pinfo, tree))
112       return;
113
114   switch (nlpid) {
115
116     /* ESIS (X.25) is not currently decoded */
117
118     case NLPID_ISO9542X25_ESIS:
119       if (check_col(pinfo->fd, COL_PROTOCOL)) {
120         col_set_str(pinfo->fd, COL_PROTOCOL, "ESIS (X.25)");
121       }
122       dissect_data(tvb, 0, pinfo, tree);
123       break;
124     case NLPID_ISO10747_IDRP:
125       if (check_col(pinfo->fd, COL_PROTOCOL)) {
126         col_set_str(pinfo->fd, COL_PROTOCOL, "IDRP");
127       }
128       dissect_data(tvb, 0, pinfo, tree);
129       break;
130     default:
131       if (check_col(pinfo->fd, COL_PROTOCOL)) {
132         col_set_str(pinfo->fd, COL_PROTOCOL, "ISO");
133       }
134       if (check_col(pinfo->fd, COL_INFO)) {
135         col_add_fstr(pinfo->fd, COL_INFO, "Unknown ISO protocol (%02x)", nlpid);
136       }
137       dissect_data(tvb, 0, pinfo, tree);
138       break;
139   }
140 } /* dissect_osi */
141
142 void
143 proto_register_osi(void)
144 {
145         /* There's no "OSI" protocol *per se*, but we do register a
146            dissector table so various protocols running at the
147            network layer can register themselves. */
148         osinl_subdissector_table = register_dissector_table("osinl");
149 }
150
151 void
152 proto_reg_handoff_osi(void)
153 {
154         dissector_add("llc.dsap", SAP_OSINL, dissect_osi, -1);
155         dissector_add("null.type", BSD_AF_ISO, dissect_osi, -1);
156 }