I removed the bit-fields that depended upon gcc's ability to use any type
[obnox/wireshark/wip.git] / packet-llc.c
1 /* packet-llc.c
2  * Routines for IEEE 802.2 LLC layer
3  * Gilbert Ramirez <gram@verdict.uthscsa.edu>
4  *
5  * $Id: packet-llc.c,v 1.10 1998/11/17 04:28:56 gerald Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@unicom.net>
9  * Copyright 1998 Gerald Combs
10  *
11  * 
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * 
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35
36 #include <gtk/gtk.h>
37
38 #include <stdio.h>
39
40 #include "ethereal.h"
41 #include "packet.h"
42 #include "etypes.h"
43
44 struct sap_info {
45         guint8  sap;
46         void    (*func) (const u_char *, int, frame_data *, GtkTree *);
47         char    *text;
48 };
49
50 static struct sap_info  saps[] = {
51         { 0x00, NULL,           "NULL LSAP" },
52         { 0x02, NULL,           "LLC Sub-Layer Management Individual" },
53         { 0x03, NULL,           "LLC Sub-Layer Management Group" },
54         { 0x04, NULL,           "SNA Path Control Individual" },
55         { 0x05, NULL,           "SNA Path Control Group" },
56         { 0x06, dissect_ip,     "TCP/IP" },
57         { 0x08, NULL,           "SNA" },
58         { 0x0C, NULL,           "SNA" },
59         { 0x42, NULL,           "Spanning Tree BPDU" },
60         { 0x7F, NULL,           "ISO 802.2" },
61         { 0x80, NULL,           "XNS" },
62         { 0xAA, NULL,           "SNAP" },
63         /*{ 0xBA, dissect_vines,        "Banyan Vines" },
64         { 0xBC, dissect_vines,  "Banyan Vines" },*/
65         { 0xBA, NULL,           "Banyan Vines" },
66         { 0xBC, NULL,           "Banyan Vines" },
67         { 0xE0, dissect_ipx,    "NetWare" },
68         { 0xF0, NULL,           "NetBIOS" },
69         { 0xF4, NULL,           "IBM Net Management Individual" },
70         { 0xF5, NULL,           "IBM Net Management Group" },
71         { 0xF8, NULL,           "Remote Program Load" },
72         { 0xFC, NULL,           "Remote Program Load" },
73         { 0xFE, dissect_osi,    "ISO Network Layer" },
74         { 0xFF, NULL,           "Global LSAP" },
75         { 0x00, NULL,           NULL }
76 };
77
78
79 static char*
80 sap_text(u_char sap) {
81         int i=0;
82
83         while (saps[i].text != NULL) {
84                 if (saps[i].sap == sap) {
85                         return saps[i].text;
86                 }
87                 i++;
88         }
89         return "Unknown";
90 }
91
92 static void*
93 sap_func(u_char sap) {
94         int i=0;
95
96         while (saps[i].text != NULL) {
97                 if (saps[i].sap == sap) {
98                         return saps[i].func;
99                 }
100                 i++;
101         }
102         return dissect_data;
103 }
104
105 static char*
106 llc_org(const u_char *ptr) {
107
108         unsigned long org = (ptr[0] << 16) | (ptr[1] << 8) | ptr[2];
109         char *llc_org[1] = {
110                 "Encapsulated Ethernet"};
111
112         if (org > 0) {
113                 return "Unknown";
114         }
115         else {
116                 return llc_org[org];
117         }
118 }
119
120 void
121 dissect_llc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
122
123         GtkWidget       *llc_tree = NULL, *ti;
124         guint16         etype;
125         int             is_snap;
126         void            (*dissect) (const u_char *, int, frame_data *, GtkTree *);
127
128         /* LLC Strings */
129         char *llc_ctrl[4] = {
130                 "Information Transfer", "Supervisory",
131                 "", "Unnumbered Information" };
132
133         is_snap = (pd[offset] == 0xAA) && (pd[offset+1] == 0xAA);
134
135         if (check_col(fd, COL_PROTOCOL)) {
136                 col_add_str(fd, COL_PROTOCOL, "LLC");
137         }
138   
139         if (tree) {
140                 ti = add_item_to_tree(GTK_WIDGET(tree), offset, (is_snap ? 8 : 3),
141                         "Logical-Link Control");
142                 llc_tree = gtk_tree_new();
143                 add_subtree(ti, llc_tree, ETT_LLC);
144                 add_item_to_tree(llc_tree, offset,      1, "DSAP: %s (0x%02X)",
145                         sap_text(pd[offset]), pd[offset]);
146                 add_item_to_tree(llc_tree, offset+1,    1, "SSAP: %s (0x%02X)",
147                         sap_text(pd[offset+1]), pd[offset+1]);
148                 add_item_to_tree(llc_tree, offset+2,    1, "Control: %s",
149                         llc_ctrl[pd[offset+2] & 3]);
150         }
151
152         if (is_snap) {
153                 if (check_col(fd, COL_INFO)) {
154                         col_add_str(fd, COL_INFO, "802.2 LLC (SNAP)");
155                 }
156                 if (tree) {
157                         add_item_to_tree(llc_tree, offset+3,    3,
158                                 "Organization Code: %s (%02X-%02X-%02X)",
159                                 llc_org(&pd[offset+3]), 
160                                 pd[offset+3], pd[offset+4], pd[offset+5]);
161                 }
162                 etype  = (pd[offset+6] << 8) | pd[offset+7];
163                 offset += 8;
164                 ethertype(etype, offset, pd, fd, tree, llc_tree);
165         }               
166         else {
167                 if (check_col(fd, COL_INFO)) {
168                         col_add_fstr(fd, COL_INFO, "802.2 LLC (%s)", sap_text(pd[offset]));
169                 }
170
171                 dissect = sap_func(pd[offset]);
172
173                 /* non-SNAP */
174                 offset += 3;
175
176                 if (dissect) {
177                         dissect(pd, offset, fd, tree);
178                 }
179                 else {
180                         dissect_data(pd, offset, fd, tree);
181                 }
182
183         }
184 }