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