Give "dissect_rpc_string()" an extra "char **" argument; if it's
[obnox/wireshark/wip.git] / packet-trmac.c
1 /* packet-trmac.c
2  * Routines for Token-Ring Media Access Control
3  * Gilbert Ramirez <gram@verdict.uthscsa.edu>
4  *
5  * $Id: packet-trmac.c,v 1.18 2000/01/07 22:05:41 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
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 <glib.h>
36 #include "packet.h"
37
38 static int proto_trmac = -1;
39 static int hf_trmac_mv = -1;
40 static int hf_trmac_length = -1;
41 static int hf_trmac_srcclass = -1;
42 static int hf_trmac_dstclass = -1;
43 static int hf_trmac_sv = -1;
44 static int hf_trmac_errors_iso = -1;
45 static int hf_trmac_errors_line = -1;
46 static int hf_trmac_errors_internal = -1;
47 static int hf_trmac_errors_burst = -1;
48 static int hf_trmac_errors_ac = -1;
49 static int hf_trmac_errors_abort = -1;
50 static int hf_trmac_errors_noniso = -1;
51 static int hf_trmac_errors_lost = -1;
52 static int hf_trmac_errors_congestion = -1;
53 static int hf_trmac_errors_fc = -1;
54 static int hf_trmac_errors_freq = -1;
55 static int hf_trmac_errors_token = -1;
56 static int hf_trmac_naun = -1;
57
58 static gint ett_tr_mac = -1;
59 static gint ett_tr_ierr_cnt = -1;
60 static gint ett_tr_nerr_cnt = -1;
61
62 /* Major Vector */
63 static value_string major_vector_vs[] = {
64                 { 0x00, "Response" },
65                 { 0x02, "Beacon" },
66                 { 0x03, "Claim Token" },
67                 { 0x04, "Ring Purge" },
68                 { 0x05, "Active Monitor Present" },
69                 { 0x06, "Standby Monitor Present" },
70                 { 0x07, "Duplicate Address Test" },
71                 { 0x09, "Transmit Forward" },
72                 { 0x0B, "Remove Ring Station" },
73                 { 0x0C, "Change Parameters" },
74                 { 0x0D, "Initialize Ring Station" },
75                 { 0x0E, "Request Ring Station Address" },
76                 { 0x0F, "Request Ring Station Address" },
77                 { 0x10, "Request Ring Station Attachments" },
78                 { 0x20, "Request Initialization" },
79                 { 0x22, "Report Ring Station Address" },
80                 { 0x23, "Report Ring Station State" },
81                 { 0x24, "Report Ring Station Attachments" },
82                 { 0x25, "Report New Active Monitor" },
83                 { 0x26, "Report NAUN Change" },
84                 { 0x27, "Report Poll Error" },
85                 { 0x28, "Report Monitor Errors" },
86                 { 0x29, "Report Error" },
87                 { 0x2A, "Report Transmit Forward" },
88                 { 0x00, NULL }
89 };
90
91 /* Src. and Dest. Classes */
92 static value_string classes_vs[] = {
93         { 0x00, "Ring Station" },
94         { 0x01, "LLC Manager" },
95         { 0x04, "Configuration Report Server" },
96         { 0x05, "Ring Parameter Server" },
97         { 0x06, "Ring Error Monitor" },
98         { 0x00, NULL }
99 };
100
101
102 /* Sub-vectors */
103 static int
104 sv_text(const u_char *pd, int pkt_offset, proto_tree *tree)
105 {
106         int     sv_length = pd[0];
107         guint16 beacon_type;
108
109         char *beacon[] = {"Recovery mode set", "Signal loss error",
110                 "Streaming signal not Claim Token MAC frame",
111                 "Streaming signal, Claim Token MAC frame"};
112
113         proto_tree      *sv_tree;
114         proto_item      *ti;
115
116         u_char          errors[6];      /* isolating or non-isolating */
117
118         /* this just adds to the clutter on the screen...
119         proto_tree_add_text(tree, pkt_offset, 1,
120                 "Subvector Length: %d bytes", sv_length);*/
121
122         proto_tree_add_item_hidden(tree, hf_trmac_sv, pkt_offset+1, 1, pd[1]);
123
124         switch(pd[1]) {
125                 case 0x01: /* Beacon Type */
126                         beacon_type = pntohs(&pd[2]);
127                         if (beacon_type < array_length(beacon)) {
128                                 proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
129                                         "Beacon Type: %s", beacon[beacon_type] );
130                         } else {
131                                 proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
132                                         "Beacon Type: Illegal value: %d", beacon_type );
133                         }
134                         break;
135
136                 case 0x02: /* NAUN */
137                         proto_tree_add_item(tree, hf_trmac_naun, pkt_offset+1, sv_length-1, (guint8*)&pd[2]);
138                         break;
139
140                 case 0x03: /* Local Ring Number */
141                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
142                                 "Local Ring Number: 0x%04X (%d)",
143                                 pntohs( &pd[2] ), pntohs( &pd[2] ));
144                         break;
145
146                 case 0x04: /* Assign Physical Location */
147                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
148                                 "Assign Physical Location: 0x%08X", pntohl( &pd[2] ) );
149                         break;
150
151                 case 0x05: /* Soft Error Report Value */
152                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
153                                 "Soft Error Report Value: %d ms", 10 * pntohs( &pd[2] ) );
154                         break;
155
156                 case 0x06: /* Enabled Function Classes */
157                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
158                                 "Enabled Function Classes: %04X",  pntohs( &pd[2] ) );
159                         break;
160
161                 case 0x07: /* Allowed Access Priority */
162                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
163                                 "Allowed Access Priority: %04X",  pntohs( &pd[2] ) );
164                         break;
165
166                 case 0x09: /* Correlator */
167                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
168                                 "Correlator: %04X",  pntohs( &pd[2] ) );
169                         break;
170
171                 case 0x0A: /* Address of last neighbor notification */
172                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
173                                 "Address of Last Neighbor Notification: %s",
174                                 ether_to_str((guint8*)&pd[2]));
175                         break;
176
177                 case 0x0B: /* Physical Location */
178                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
179                                 "Physical Location: 0x%08X", pntohl( &pd[2] ) );
180                         break;
181
182                 case 0x20: /* Response Code */
183                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
184                                 "Response Code: 0x%04X 0x%04X", pntohl( &pd[2] ),
185                                 pntohl( &pd[4] ) );
186                         break;
187
188                 case 0x21: /* Reserved */
189                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
190                                 "Reserved: 0x%04X", pntohs( &pd[2] ) );
191                         break;
192
193                 case 0x22: /* Product Instance ID */
194                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
195                                 "Product Instance ID: ...");
196                         break;
197
198                 case 0x23: /* Ring Station Microcode Level */
199                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
200                                 "Ring Station Microcode Level: ...");
201                         break;
202
203                 case 0x26: /* Wrap data */
204                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
205                                 "Wrap Data: ... (%d bytes)", sv_length - 2);
206                         break;
207
208                 case 0x27: /* Frame Forward */
209                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
210                                 "Frame Forward: ... (%d bytes)", sv_length - 2);
211                         break;
212
213                 case 0x29: /* Ring Station Status Subvector */
214                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
215                                 "Ring Station Status Subvector: ...");
216                         break;
217
218                 case 0x2A: /* Transmit Status Code */
219                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
220                                 "Transmit Status Code: %04X", pntohs( &pd[2] ) );
221                         break;
222
223                 case 0x2B: /* Group Address */
224                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
225                                 "Group Address: %08X", pntohl( &pd[2] ) );
226                         break;
227
228                 case 0x2C: /* Functional Address */
229                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
230                                 "Functional Address: %08X", pntohl( &pd[2] ) );
231                         break;
232
233                 case 0x2D: /* Isolating Error Counts */
234                         memcpy(errors, &pd[2], 6);
235                         ti = proto_tree_add_item(tree, hf_trmac_errors_iso, pkt_offset+1, sv_length-1,
236                                 errors[0] + errors[1] + errors[2] + errors[3] + errors[4]);
237                         sv_tree = proto_item_add_subtree(ti, ett_tr_ierr_cnt);
238
239                         proto_tree_add_item(sv_tree, hf_trmac_errors_line, pkt_offset+2, 1, errors[0]);
240                         proto_tree_add_item(sv_tree, hf_trmac_errors_internal, pkt_offset+3, 1, errors[1]);
241                         proto_tree_add_item(sv_tree, hf_trmac_errors_burst, pkt_offset+4, 1, errors[2]);
242                         proto_tree_add_item(sv_tree, hf_trmac_errors_ac, pkt_offset+5, 1, errors[3]);
243                         proto_tree_add_item(sv_tree, hf_trmac_errors_abort, pkt_offset+6, 1, errors[4]);
244
245                         break;
246
247                 case 0x2E: /* Non-Isolating Error Counts */
248                         memcpy(errors, &pd[2], 6);
249                         ti = proto_tree_add_item(tree, hf_trmac_errors_noniso, pkt_offset+1, sv_length-1,
250                                 errors[0] + errors[1] + errors[2] + errors[3] + errors[4]);
251                         sv_tree = proto_item_add_subtree(ti, ett_tr_nerr_cnt);
252
253                         proto_tree_add_item(sv_tree, hf_trmac_errors_lost, pkt_offset+2, 1, errors[0]);
254                         proto_tree_add_item(sv_tree, hf_trmac_errors_congestion, pkt_offset+3, 1, errors[1]);
255                         proto_tree_add_item(sv_tree, hf_trmac_errors_fc, pkt_offset+4, 1, errors[2]);
256                         proto_tree_add_item(sv_tree, hf_trmac_errors_freq, pkt_offset+5, 1, errors[3]);
257                         proto_tree_add_item(sv_tree, hf_trmac_errors_token, pkt_offset+6, 1, errors[4]);
258                         break;
259
260                 case 0x30: /* Error Code */
261                         proto_tree_add_text(tree, pkt_offset+1, sv_length-1,
262                                 "Error Code: %04X", pntohs( &pd[2] ) );
263                         break;
264
265                 default: /* Unknown */
266                         proto_tree_add_text(tree, pkt_offset+1, 1,
267                                 "Unknown Sub-Vector: 0x%02X", pd[1]);
268         }
269         return sv_length;
270 }
271
272 void
273 dissect_trmac(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
274
275         proto_tree      *mac_tree = NULL;
276         proto_item      *ti;
277         int             mv_length, sv_length, sv_offset, sv_additional;
278         guint8          mv_val;
279         char            *mv_text;
280
281         mv_val = pd[offset+3];
282         mv_length = pntohs(&pd[offset]);
283
284         /* Interpret the major vector */
285         mv_text = val_to_str(mv_val, major_vector_vs, "Unknown Major Vector: %d\n");
286
287         /* Summary information */
288         if (check_col(fd, COL_PROTOCOL))
289                 col_add_str(fd, COL_PROTOCOL, "TR MAC");
290         if (check_col(fd, COL_INFO))
291                 col_add_str(fd, COL_INFO, mv_text);
292
293         if (tree) {
294
295                 ti = proto_tree_add_item(tree, proto_trmac, offset, mv_length, NULL);
296                 mac_tree = proto_item_add_subtree(ti, ett_tr_mac);
297
298                 proto_tree_add_item(mac_tree, hf_trmac_mv, offset+3, 1, mv_val);
299                 proto_tree_add_item_format(mac_tree, hf_trmac_length, offset, 2, mv_length,
300                                 "Total Length: %d bytes", mv_length);
301                 proto_tree_add_item(mac_tree, hf_trmac_srcclass, offset+2, 1, pd[offset+2] & 0x0f);
302                 proto_tree_add_item(mac_tree, hf_trmac_dstclass, offset+2, 1, pd[offset+2] >> 4 );
303
304                 /* interpret the subvectors */
305                 sv_offset = 0;
306                 offset += 4;
307                 sv_length = mv_length - 4;
308                 while (sv_offset < sv_length) {
309                         sv_additional = sv_text(&pd[offset + sv_offset], offset + sv_offset,
310                                                                 mac_tree);
311
312                         /* if this is a bad packet, we could get a 0-length added here,
313                          * looping forever */
314                         if (sv_additional)
315                                 sv_offset += sv_additional;
316                         else
317                                 break;
318                 }
319         }
320 }
321
322 void
323 proto_register_trmac(void)
324 {
325         static hf_register_info hf[] = {
326                 { &hf_trmac_mv,
327                 { "Major Vector",                       "trmac.mvec", FT_UINT8, BASE_HEX, major_vector_vs, 0x0,
328                         "" }},
329
330                 { &hf_trmac_length,
331                 { "Total Length",                       "trmac.length", FT_UINT8, BASE_DEC, NULL, 0x0,
332                         "" }},
333
334                 { &hf_trmac_srcclass,
335                 { "Source Class",                       "trmac.srcclass", FT_UINT8, BASE_HEX, classes_vs, 0x0,
336                         "" }},
337
338                 { &hf_trmac_dstclass,
339                 { "Destination Class",                  "trmac.dstclass", FT_UINT8, BASE_HEX, classes_vs, 0x0,
340                         "" }},
341
342                 { &hf_trmac_sv,
343                 { "Sub-Vector",                         "trmac.svec", FT_UINT8, BASE_HEX, NULL, 0x0,
344                         "" }},
345
346                 { &hf_trmac_errors_iso,
347                 { "Isolating Errors",                   "trmac.errors.iso", FT_UINT16, BASE_DEC, NULL, 0x0,
348                         "" }},
349
350                 { &hf_trmac_errors_line,
351                 { "Line Errors",                        "trmac.errors.line", FT_UINT8, BASE_DEC, NULL, 0x0,
352                         "" }},
353
354                 { &hf_trmac_errors_internal,
355                 { "Internal Errors",                    "trmac.errors.internal", FT_UINT8, BASE_DEC, NULL, 0x0,
356                         "" }},
357
358                 { &hf_trmac_errors_burst,
359                 { "Burst Errors",                       "trmac.errors.burst", FT_UINT8, BASE_DEC, NULL, 0x0,
360                         "" }},
361
362                 { &hf_trmac_errors_ac,
363                 { "A/C Errors",                         "trmac.errors.ac", FT_UINT8, BASE_DEC, NULL, 0x0,
364                         "" }},
365
366                 { &hf_trmac_errors_abort,
367                 { "Abort Delimiter Transmitted Errors", "trmac.errors.abort", FT_UINT8, BASE_DEC, NULL, 0x0,
368                         "" }},
369
370                 { &hf_trmac_errors_noniso,
371                 { "Non-Isolating Errors",               "trmac.errors.noniso", FT_UINT16, BASE_DEC, NULL, 0x0,
372                         "" }},
373
374                 { &hf_trmac_errors_lost,
375                 { "Lost Frame Errors",                  "trmac.errors.lost", FT_UINT8, BASE_DEC, NULL, 0x0,
376                         "" }},
377
378                 { &hf_trmac_errors_congestion,
379                 { "Receiver Congestion Errors",         "trmac.errors.congestion", FT_UINT8, BASE_DEC, NULL, 0x0,
380                         "" }},
381
382                 { &hf_trmac_errors_fc,
383                 { "Frame-Copied Errors",                "trmac.errors.fc", FT_UINT8, BASE_DEC, NULL, 0x0,
384                         "" }},
385
386                 { &hf_trmac_errors_freq,
387                 { "Frequency Errors",                   "trmac.errors.freq", FT_UINT8, BASE_DEC, NULL, 0x0,
388                         "" }},
389
390                 { &hf_trmac_errors_token,
391                 { "Token Errors",                       "trmac.errors.token", FT_UINT8, BASE_DEC, NULL, 0x0,
392                         "" }},
393
394                 { &hf_trmac_naun,
395                 { "NAUN",                               "trmac.naun", FT_ETHER, BASE_DEC, NULL, 0x0,
396                         "" }},
397         };
398         static gint *ett[] = {
399                 &ett_tr_mac,
400                 &ett_tr_ierr_cnt,
401                 &ett_tr_nerr_cnt,
402         };
403
404         proto_trmac = proto_register_protocol("Token-Ring Media Access Control", "trmac");
405         proto_register_field_array(proto_trmac, hf, array_length(hf));
406         proto_register_subtree_array(ett, array_length(ett));
407 }