Fix to use #define values as subscripts of "win_info[]".
[obnox/wireshark/wip.git] / packet-fddi.c
1 /* packet-fddi.c
2  * Routines for FDDI packet disassembly
3  *
4  * Laurent Deniel <deniel@worldnet.fr>
5  *
6  * $Id: packet-fddi.c,v 1.3 1998/10/13 05:12:13 guy Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@zing.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <gtk/gtk.h>
33
34 #include <stdio.h>
35
36 #include <pcap.h>
37
38 #include "ethereal.h"
39 #include "packet.h"
40 #include "resolv.h"
41
42 /* FDDI Frame Control values */
43
44 #define FDDI_FC_VOID            0x00            /* Void frame */
45 #define FDDI_FC_NRT             0x80            /* Nonrestricted token */
46 #define FDDI_FC_RT              0xc0            /* Restricted token */
47 #define FDDI_FC_MAC             0xc0            /* MAC frame */
48 #define FDDI_FC_SMT             0x40            /* SMT frame */
49 #define FDDI_FC_SMT_INFO        0x41            /* SMT Info */
50 #define FDDI_FC_SMT_NSA         0x4F            /* SMT Next station adrs */
51 #define FDDI_FC_SMT_MIN         FDDI_FC_SMT_INFO
52 #define FDDI_FC_SMT_MAX         FDDI_FC_SMT_NSA
53 #define FDDI_FC_MAC_MIN         0xc1
54 #define FDDI_FC_MAC_BEACON      0xc2            /* MAC Beacon frame */
55 #define FDDI_FC_MAC_CLAIM       0xc3            /* MAC Claim frame */
56 #define FDDI_FC_MAC_MAX         0xcf
57 #define FDDI_FC_LLC_ASYNC       0x50            /* Async. LLC frame */
58 #define FDDI_FC_LLC_ASYNC_MIN   FDDI_FC_LLC_ASYNC
59 #define FDDI_FC_LLC_ASYNC_DEF   0x54
60 #define FDDI_FC_LLC_ASYNC_MAX   0x5f
61 #define FDDI_FC_LLC_SYNC        0xd0            /* Sync. LLC frame */
62 #define FDDI_FC_LLC_SYNC_MIN    FDDI_FC_LLC_SYNC
63 #define FDDI_FC_LLC_SYNC_MAX    0xd7
64 #define FDDI_FC_IMP_ASYNC       0x60            /* Implementor Async. */
65 #define FDDI_FC_IMP_ASYNC_MIN   FDDI_FC_IMP_ASYNC
66 #define FDDI_FC_IMP_ASYNC_MAX   0x6f
67 #define FDDI_FC_IMP_SYNC        0xe0            /* Implementor Synch. */
68
69 #define FDDI_HEADER_SIZE        13
70
71 /* field positions */
72
73 #define FDDI_P_FC               0
74 #define FDDI_P_DHOST            1
75 #define FDDI_P_SHOST            7
76
77 void dissect_fddi(const u_char *pd, frame_data *fd, GtkTree *tree) 
78 {
79
80   int        offset = 0, fc;
81   GtkWidget *fh_tree, *ti;
82
83   if (fd->cap_len < FDDI_HEADER_SIZE) {
84     dissect_data(pd, offset, fd, tree);
85     return;
86   }
87
88   fc = (int) pd[FDDI_P_FC];
89
90   if (fd->win_info[COL_NUM]) {
91     strcpy(fd->win_info[COL_DESTINATION], get_ether_name((u_char *)&pd[FDDI_P_DHOST]));
92     strcpy(fd->win_info[COL_SOURCE], get_ether_name((u_char *)&pd[FDDI_P_SHOST]));
93     strcpy(fd->win_info[COL_INFO], "FDDI");
94   }
95
96   if (tree) {
97     ti = add_item_to_tree(GTK_WIDGET(tree), 0, offset,
98                           "FDDI %s (%d on wire, %d captured)",
99                           (fc >= FDDI_FC_LLC_ASYNC_MIN && fc <= FDDI_FC_LLC_ASYNC_MAX) ?
100                           "Async LLC" : "unsupported FC",
101                           fd->pkt_len, fd->cap_len);
102
103       fh_tree = gtk_tree_new();
104       add_subtree(ti, fh_tree, ETT_FDDI);
105       add_item_to_tree(fh_tree, FDDI_P_FC, 1, "Frame Control: 0x%02x", fc);
106       add_item_to_tree(fh_tree, FDDI_P_DHOST, 6, "Destination: %s (%s)",
107                        ether_to_str((guint8 *) &pd[FDDI_P_DHOST]),
108                        get_ether_name((u_char *) &pd[FDDI_P_DHOST]));
109       add_item_to_tree(fh_tree, FDDI_P_SHOST, 6, "Source: %s (%s)",
110                        ether_to_str((guint8 *) &pd[FDDI_P_SHOST]),
111                        get_ether_name((u_char *)&pd[FDDI_P_SHOST]));
112     }
113
114   offset = FDDI_HEADER_SIZE;
115
116   switch (fc) {
117
118     /* From now, only 802.2 SNAP (Async. LCC frame) is supported */
119
120     case FDDI_FC_LLC_ASYNC + 0  :
121     case FDDI_FC_LLC_ASYNC + 1  :
122     case FDDI_FC_LLC_ASYNC + 2  :
123     case FDDI_FC_LLC_ASYNC + 3  :
124     case FDDI_FC_LLC_ASYNC + 4  :
125     case FDDI_FC_LLC_ASYNC + 5  :
126     case FDDI_FC_LLC_ASYNC + 6  :
127     case FDDI_FC_LLC_ASYNC + 7  :
128     case FDDI_FC_LLC_ASYNC + 8  :
129     case FDDI_FC_LLC_ASYNC + 9  :
130     case FDDI_FC_LLC_ASYNC + 10 :
131     case FDDI_FC_LLC_ASYNC + 11 :
132     case FDDI_FC_LLC_ASYNC + 12 :
133     case FDDI_FC_LLC_ASYNC + 13 :
134     case FDDI_FC_LLC_ASYNC + 14 :
135     case FDDI_FC_LLC_ASYNC + 15 :
136       dissect_llc(pd, offset, fd, tree);
137       return;
138       
139     default :
140       dissect_data(pd, offset, fd, tree);
141       return;
142
143   } /* fc */
144
145 } /* dissect_fddi */
146