The non-SNAP vines doesn't work with dissect_vines(). We don't know what my
[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.5 1998/09/17 21:30:58 gram 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 #include <pcap.h>
32
33 #include <gtk/gtk.h>
34
35 #include <stdio.h>
36
37 #include "packet.h"
38 #include "ethereal.h"
39 #include "etypes.h"
40
41 struct sap_info {
42         u_char  sap;
43         void    (*func) (const u_char *, int, frame_data *, GtkTree *);
44         char    *text;
45 };
46
47 static struct sap_info  saps[] = {
48         { 0x00, NULL,           "NULL LSAP" },
49         { 0x02, NULL,           "LLC Sub-Layer Management Individual" },
50         { 0x03, NULL,           "LLC Sub-Layer Management Group" },
51         { 0x04, NULL,           "SNA Path Control Individual" },
52         { 0x05, NULL,           "SNA Path Control Group" },
53         { 0x06, dissect_ip,     "TCP/IP" },
54         { 0x08, NULL,           "SNA" },
55         { 0x0C, NULL,           "SNA" },
56         { 0x42, NULL,           "Spanning Tree BPDU" },
57         { 0x7F, NULL,           "ISO 802.2" },
58         { 0x80, NULL,           "XNS" },
59         { 0xAA, NULL,           "SNAP" },
60         /*{ 0xBA, dissect_vines,        "Banyan Vines" },
61         { 0xBC, dissect_vines,  "Banyan Vines" },*/
62         { 0xBA, NULL,           "Banyan Vines" },
63         { 0xBC, NULL,           "Banyan Vines" },
64         { 0xE0, dissect_ipx,    "NetWare" },
65         { 0xF0, NULL,           "NetBIOS" },
66         { 0xF4, NULL,           "IBM Net Management Individual" },
67         { 0xF5, NULL,           "IBM Net Management Group" },
68         { 0xF8, NULL,           "Remote Program Load" },
69         { 0xFC, NULL,           "Remote Program Load" },
70         { 0xFE, dissect_osi,    "ISO Network Layer" },
71         { 0xFF, NULL,           "Global LSAP" },
72         { 0x00, NULL,           NULL }
73 };
74
75
76 static char*
77 sap_text(u_char sap) {
78         int i=0;
79
80         while (saps[i].text != NULL) {
81                 if (saps[i].sap == sap) {
82                         return saps[i].text;
83                 }
84                 i++;
85         }
86         return "Unknown";
87 }
88
89 static void*
90 sap_func(u_char sap) {
91         int i=0;
92
93         while (saps[i].text != NULL) {
94                 if (saps[i].sap == sap) {
95                         return saps[i].func;
96                 }
97                 i++;
98         }
99         return dissect_data;
100 }
101
102 static char*
103 llc_org(const u_char *ptr) {
104
105         unsigned long org = (ptr[0] << 16) | (ptr[1] << 8) | ptr[2];
106         char *llc_org[1] = {
107                 "Encapsulated Ethernet"};
108
109         if (org > 0) {
110                 return "Unknown";
111         }
112         else {
113                 return llc_org[org];
114         }
115 }
116
117 void
118 dissect_llc(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
119
120         GtkWidget       *llc_tree, *ti;
121         guint16         etype;
122         int             is_snap;
123         void            (*dissect) (const u_char *, int, frame_data *, GtkTree *);
124
125         /* LLC Strings */
126         char *llc_ctrl[4] = {
127                 "Information Transfer", "Supervisory",
128                 "", "Unnumbered Information" };
129
130         is_snap = (pd[offset] == 0xAA) && (pd[offset+1] == 0xAA);
131
132         if (fd->win_info[0]) {
133                 strcpy(fd->win_info[3], "LLC");
134         }
135   
136         if (tree) {
137                 ti = add_item_to_tree(GTK_WIDGET(tree), offset, (is_snap ? 8 : 3),
138                         "Logical-Link Control");
139                 llc_tree = gtk_tree_new();
140                 add_subtree(ti, llc_tree, ETT_LLC);
141                 add_item_to_tree(llc_tree, offset,      1, "DSAP: %s (0x%02X)",
142                         sap_text(pd[offset]), pd[offset]);
143                 add_item_to_tree(llc_tree, offset+1,    1, "SSAP: %s (0x%02X)",
144                         sap_text(pd[offset+1]), pd[offset+1]);
145                 add_item_to_tree(llc_tree, offset+2,    1, "Control: %s",
146                         llc_ctrl[pd[offset+2] & 3]);
147         }
148
149         if (is_snap) {
150                 if (fd->win_info[0]) {
151                         strcpy(fd->win_info[4], "802.2 LLC (SNAP)");
152                 }
153                 if (tree) {
154                         add_item_to_tree(llc_tree, offset+3,    3,
155                                 "Organization Code: %s (%02X-%02X-%02X)",
156                                 llc_org(&pd[offset+3]), 
157                                 pd[offset+3], pd[offset+4], pd[offset+5]);
158                 }
159                 etype  = (pd[offset+6] << 8) | pd[offset+7];
160                 offset += 8;
161                 ethertype(etype, offset, pd, fd, tree, llc_tree);
162         }               
163         else {
164                 if (fd->win_info[0]) {
165                         sprintf(fd->win_info[4], "802.2 LLC (%s)", sap_text(pd[offset]));
166                 }
167
168                 dissect = sap_func(pd[offset]);
169
170                 /* non-SNAP */
171                 offset += 3;
172
173                 if (dissect) {
174                         dissect(pd, offset, fd, tree);
175                 }
176                 else {
177                         dissect_data(pd, offset, fd, tree);
178                 }
179
180         }
181 }