2 * Routines for Token-Ring Media Access Control
3 * Gilbert Ramirez <gram@verdict.uthscsa.edu>
5 * $Id: packet-trmac.c,v 1.7 1998/11/12 00:06:39 gram Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@unicom.net>
9 * Copyright 1998 Gerald Combs
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.
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.
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.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
44 #ifdef HAVE_NETINET_IN_H
45 # include <netinet/in.h>
53 static value_string major_vectors[] = {
56 { 0x03, "Claim Token" },
57 { 0x04, "Ring Purge" },
58 { 0x05, "Active Monitor Present" },
59 { 0x06, "Standby Monitor Present" },
60 { 0x07, "Duplicate Address Test" },
61 { 0x09, "Transmit Forward" },
62 { 0x0B, "Remove Ring Station" },
63 { 0x0C, "Change Parameters" },
64 { 0x0D, "Initialize Ring Station" },
65 { 0x0E, "Request Ring Station Address" },
66 { 0x0F, "Request Ring Station Address" },
67 { 0x10, "Request Ring Station Attachments" },
68 { 0x20, "Request Initialization" },
69 { 0x22, "Report Ring Station Address" },
70 { 0x23, "Report Ring Station State" },
71 { 0x24, "Report Ring Station Attachments" },
72 { 0x25, "Report New Active Monitor" },
73 { 0x26, "Report NAUN Change" },
74 { 0x27, "Report Poll Error" },
75 { 0x28, "Report Monitor Errors" },
76 { 0x29, "Report Error" },
77 { 0x2A, "Report Transmit Forward" },
84 sv_text(const u_char *pd, int pkt_offset, GtkWidget *tree)
86 int sv_length = pd[0];
88 char *beacon[] = {"Recovery mode set", "Signal loss error",
89 "Streaming signal not Claim Token MAC frame",
90 "Streaming signal, Claim Token MAC frame"};
92 GtkWidget *sv_tree, *ti;
94 u_char errors[6]; /* isolating or non-isolating */
96 /* this just adds to the clutter on the screen...
97 add_item_to_tree(tree, pkt_offset, 1,
98 "Subvector Length: %d bytes", sv_length);*/
101 case 0x01: /* Beacon Type */
102 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
103 "Beacon Type: %s", beacon[ pntohs( &pd[2] ) ] );
106 case 0x02: /* NAUN */
107 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
108 "NAUN: %s", ether_to_str((guint8*)&pd[2]));
111 case 0x03: /* Local Ring Number */
112 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
113 "Local Ring Number: 0x%04X (%d)",
114 pntohs( &pd[2] ), pntohs( &pd[2] ));
117 case 0x04: /* Assign Physical Location */
118 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
119 "Assign Physical Location: 0x%08X", pntohl( &pd[2] ) );
122 case 0x05: /* Soft Error Report Value */
123 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
124 "Soft Error Report Value: %d ms", 10 * pntohs( &pd[2] ) );
127 case 0x06: /* Enabled Function Classes */
128 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
129 "Enabled Function Classes: %04X", pntohs( &pd[2] ) );
132 case 0x07: /* Allowed Access Priority */
133 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
134 "Allowed Access Priority: %04X", pntohs( &pd[2] ) );
137 case 0x09: /* Correlator */
138 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
139 "Correlator: %04X", pntohs( &pd[2] ) );
142 case 0x0A: /* Address of last neighbor notification */
143 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
144 "Address of Last Neighbor Notification: %s",
145 ether_to_str((guint8*)&pd[2]));
148 case 0x0B: /* Physical Location */
149 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
150 "Physical Location: 0x%08X", pntohl( &pd[2] ) );
153 case 0x20: /* Response Code */
154 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
155 "Response Code: 0x%04X 0x%04X", pntohl( &pd[2] ),
159 case 0x21: /* Reserved */
160 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
161 "Reserved: 0x%04X", pntohs( &pd[2] ) );
164 case 0x22: /* Product Instance ID */
165 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
166 "Product Instance ID: ...");
169 case 0x23: /* Ring Station Microcode Level */
170 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
171 "Ring Station Microcode Level: ...");
174 case 0x26: /* Wrap data */
175 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
176 "Wrap Data: ... (%d bytes)", sv_length - 2);
179 case 0x27: /* Frame Forward */
180 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
181 "Frame Forward: ... (%d bytes)", sv_length - 2);
184 case 0x29: /* Ring Station Status Subvector */
185 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
186 "Ring Station Status Subvector: ...");
189 case 0x2A: /* Transmit Status Code */
190 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
191 "Transmit Status Code: %04X", pntohs( &pd[2] ) );
194 case 0x2B: /* Group Address */
195 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
196 "Group Address: %08X", pntohl( &pd[2] ) );
199 case 0x2C: /* Functional Address */
200 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
201 "Functional Address: %08X", pntohl( &pd[2] ) );
204 case 0x2D: /* Isolating Error Counts */
205 memcpy(errors, &pd[2], 6);
206 ti = add_item_to_tree(GTK_WIDGET(tree), pkt_offset+1, sv_length-1,
207 "Isolating Error Counts (%d total)",
208 errors[0] + errors[1] + errors[2] + errors[3] + errors[4]);
209 sv_tree = gtk_tree_new();
210 add_subtree(ti, sv_tree, ETT_TR_IERR_CNT);
212 add_item_to_tree(sv_tree, pkt_offset+2, 1,
213 "Line Errors: %d", errors[0]);
214 add_item_to_tree(sv_tree, pkt_offset+3, 1,
215 "Internal Errors: %d", errors[1]);
216 add_item_to_tree(sv_tree, pkt_offset+4, 1,
217 "Burst Errors: %d", errors[2]);
218 add_item_to_tree(sv_tree, pkt_offset+5, 1,
219 "A/C Errors: %d", errors[3]);
220 add_item_to_tree(sv_tree, pkt_offset+6, 1,
221 "Abort delimiter transmitted: %d", errors[4]);
225 case 0x2E: /* Non-Isolating Error Counts */
226 memcpy(errors, &pd[2], 6);
227 ti = add_item_to_tree(GTK_WIDGET(tree), pkt_offset+1, sv_length-1,
228 "Non-Isolating Error Counts (%d total)",
229 errors[0] + errors[1] + errors[2] + errors[3] + errors[4]);
230 sv_tree = gtk_tree_new();
231 add_subtree(ti, sv_tree, ETT_TR_NERR_CNT);
233 add_item_to_tree(sv_tree, pkt_offset+2, 1,
234 "Lost Frame Errors: %d", errors[0]);
235 add_item_to_tree(sv_tree, pkt_offset+3, 1,
236 "Receiver Congestion: %d", errors[1]);
237 add_item_to_tree(sv_tree, pkt_offset+4, 1,
238 "Frame-Copied Congestion: %d", errors[2]);
239 add_item_to_tree(sv_tree, pkt_offset+5, 1,
240 "Frequency Errors: %d", errors[3]);
241 add_item_to_tree(sv_tree, pkt_offset+6, 1,
242 "Token Errors: %d", errors[4]);
245 case 0x30: /* Error Code */
246 add_item_to_tree(tree, pkt_offset+1, sv_length-1,
247 "Error Code: %04X", pntohs( &pd[2] ) );
250 default: /* Unknown */
251 add_item_to_tree(tree, pkt_offset+1, 1,
252 "Unknown Sub-Vector: 0x%02X", pd[1]);
258 dissect_trmac(const u_char *pd, int offset, frame_data *fd, GtkTree *tree) {
260 GtkWidget *mac_tree = NULL, *ti;
261 int mv_length, sv_length, sv_offset;
262 char *class[] = { "Ring Station", "LLC Manager", "", "",
263 "Configuration Report Server", "Ring Parameter Server",
264 "Ring Error Monitor" };
267 mv_length = ntohs(*((guint16*)&pd[offset]));
270 ti = add_item_to_tree(GTK_WIDGET(tree), offset, mv_length,
271 "Media Access Control");
272 mac_tree = gtk_tree_new();
273 add_subtree(ti, mac_tree, ETT_TR_MAC);
276 /* Interpret the major vector */
277 mv_text = match_strval(pd[offset+3], major_vectors);
279 /* Summary information */
280 if (fd->win_info[COL_NUM]) {
281 strcpy(fd->win_info[COL_PROTOCOL], "TR MAC");
282 strcpy(fd->win_info[COL_INFO], mv_text);
287 add_item_to_tree(mac_tree, offset+3, 1, "Major Vector Command: %s",
290 add_item_to_tree(mac_tree, offset+3, 1, "Major Vector Command: %02X (Unknown)",
292 add_item_to_tree(mac_tree, offset, 2, "Total Length: %d bytes",
294 add_item_to_tree(mac_tree, offset+2, 1, "Source Class: %s",
295 class[ pd[offset+2] & 0x0f ]);
296 add_item_to_tree(mac_tree, offset+2, 1, "Destination Class: %s",
297 class[ pd[offset+2] >> 4 ]);
299 /* interpret the subvectors */
302 sv_length = mv_length - 4;
303 while (sv_offset < sv_length) {
304 sv_offset += sv_text(&pd[offset + sv_offset], offset + sv_offset,