HTTPS (almost) everywhere.
[metze/wireshark/wip.git] / epan / dissectors / packet-trmac.c
1 /* packet-trmac.c
2  * Routines for Token-Ring Media Access Control
3  * Gilbert Ramirez <gram@alumni.rice.edu>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11
12 #include "config.h"
13
14 #include <epan/packet.h>
15 #include <epan/to_str.h>
16 #include <epan/expert.h>
17
18 void proto_register_trmac(void);
19
20 static int proto_trmac = -1;
21 static int hf_trmac_mv = -1;
22 static int hf_trmac_length = -1;
23 static int hf_trmac_srcclass = -1;
24 static int hf_trmac_dstclass = -1;
25 static int hf_trmac_sv_len = -1;
26 static int hf_trmac_sv_id = -1;
27 static int hf_trmac_errors_iso = -1;
28 static int hf_trmac_errors_line = -1;
29 static int hf_trmac_errors_internal = -1;
30 static int hf_trmac_errors_burst = -1;
31 static int hf_trmac_errors_ac = -1;
32 static int hf_trmac_errors_abort = -1;
33 static int hf_trmac_errors_noniso = -1;
34 static int hf_trmac_errors_lost = -1;
35 static int hf_trmac_errors_congestion = -1;
36 static int hf_trmac_errors_fc = -1;
37 static int hf_trmac_errors_freq = -1;
38 static int hf_trmac_errors_token = -1;
39 static int hf_trmac_naun = -1;
40 static int hf_trmac_beacon_type = -1;
41 static int hf_trmac_assign_physical_drop_number = -1;
42 static int hf_trmac_error_code = -1;
43 static int hf_trmac_group_address32 = -1;
44 static int hf_trmac_transmit_status_code = -1;
45 static int hf_trmac_station_identifier = -1;
46 static int hf_trmac_sa_of_last_amp_or_smp_frame = -1;
47 static int hf_trmac_error_report_timer_value = -1;
48 static int hf_trmac_individual_address_count = -1;
49 static int hf_trmac_correlator = -1;
50 static int hf_trmac_group_address_ether = -1;
51 static int hf_trmac_authorized_access_priority = -1;
52 static int hf_trmac_physical_drop_number = -1;
53 static int hf_trmac_authorized_function_classes = -1;
54 static int hf_trmac_local_ring_number = -1;
55 static int hf_trmac_functional_addresses = -1;
56 /* Generated from convert_proto_tree_add_text.pl */
57 static int hf_trmac_unknown_subvector = -1;
58 static int hf_trmac_response_code48 = -1;
59 static int hf_trmac_product_instance_id = -1;
60 static int hf_trmac_ring_station_version_number = -1;
61 static int hf_trmac_wrap_data = -1;
62 static int hf_trmac_ring_station_status = -1;
63 static int hf_trmac_frame_forward = -1;
64 static int hf_trmac_response_code32 = -1;
65
66 static gint ett_tr_mac = -1;
67 static gint ett_tr_sv = -1;
68 static gint ett_tr_ierr_cnt = -1;
69 static gint ett_tr_nerr_cnt = -1;
70
71 static expert_field ei_trmac_sv_len = EI_INIT;
72
73 /* Major Vector */
74 static const value_string major_vector_vs[] = {
75         { 0x00, "Response" },
76         { 0x02, "Beacon" },
77         { 0x03, "Claim Token" },
78         { 0x04, "Ring Purge" },
79         { 0x05, "Active Monitor Present" },
80         { 0x06, "Standby Monitor Present" },
81         { 0x07, "Duplicate Address Test" },
82         { 0x09, "Transmit Forward" },
83         { 0x0B, "Remove Ring Station" },
84         { 0x0C, "Change Parameters" },
85         { 0x0D, "Initialize Ring Station" },
86         { 0x0E, "Request Ring Station Address" },
87         { 0x0F, "Request Ring Station Address" },
88         { 0x10, "Request Ring Station Attachments" },
89         { 0x20, "Request Initialization" },
90         { 0x22, "Report Ring Station Address" },
91         { 0x23, "Report Ring Station State" },
92         { 0x24, "Report Ring Station Attachments" },
93         { 0x25, "Report New Active Monitor" },
94         { 0x26, "Report NAUN Change" },
95         { 0x27, "Report Poll Error" },
96         { 0x28, "Report Monitor Errors" },
97         { 0x29, "Report Error" },
98         { 0x2A, "Report Transmit Forward" },
99         { 0x00, NULL }
100 };
101 static value_string_ext major_vector_vs_ext = VALUE_STRING_EXT_INIT(major_vector_vs);
102
103 /* Src. and Dest. Classes */
104 static const value_string classes_vs[] = {
105         { 0x00, "Ring Station" },
106         { 0x01, "LLC Manager" },
107         { 0x04, "Configuration Report Server" },
108         { 0x05, "Ring Parameter Server" },
109         { 0x06, "Ring Error Monitor" },
110         { 0x00, NULL }
111 };
112
113 static const value_string subvector_vs[] = {
114         { 0x01, "Beacon Type" },
115         { 0x02, "Upstream Neighbor's Address" },
116         { 0x03, "Local Ring Number" },
117         { 0x04, "Assign Physical Drop Number" },
118         { 0x05, "Error Report Timer Value" },
119         { 0x06, "Authorized Function Classes" },
120         { 0x07, "Authorized Access Priority" },
121         { 0x09, "Correlator" },
122         { 0x0A, "SA of Last AMP or SMP Frame" },
123         { 0x0B, "Physical Drop Number" },
124         { 0x20, "Response Code" },
125         { 0x21, "Individual Address Count" },
126         { 0x22, "Product Instance ID" },
127         { 0x23, "Ring Station Version Number" },
128         { 0x26, "Wrap Data" },
129         { 0x27, "Frame Forward" },
130         { 0x28, "Station Identifier" },
131         { 0x29, "Ring Station Status" },
132         { 0x2A, "Transmit Forward Status Code" },
133         { 0x2B, "Group Addresses" },
134         { 0x2C, "Functional Addresses" },
135         { 0x2D, "Isolating Error Counts" },
136         { 0x2E, "Non-Isolating Error Counts" },
137         { 0x2F, "Function Request ID" },
138         { 0x30, "Error Code" },
139         { 0x00, NULL }
140 };
141 static value_string_ext subvector_vs_ext = VALUE_STRING_EXT_INIT(subvector_vs);
142
143 static const value_string beacon_vs[] = {
144         { 0x00, "Recovery mode set" },
145         { 0x01, "Signal loss error" },
146         { 0x02, "Streaming signal not Claim Token MAC frame" },
147         { 0x03, "Streaming signal, Claim Token MAC frame" },
148         { 0x00, NULL }
149 };
150
151 /* Sub-vectors */
152 static int
153 sv_text(tvbuff_t *tvb, int svoff, packet_info *pinfo, proto_tree *tree)
154 {
155         guint   sv_length, sv_id;
156         guint16 beacon_type, ring;
157         guint32 error_report_timer_value;
158
159         proto_tree      *sv_tree, *sv_subtree;
160         proto_item      *sv_item, *len_item, *ti;
161
162         guchar          errors[6];      /* isolating or non-isolating */
163
164         sv_tree = proto_tree_add_subtree(tree, tvb, svoff+0, 1, ett_tr_sv, &sv_item, "Subvector");
165
166         sv_length = tvb_get_guint8(tvb, svoff+0);
167         len_item = proto_tree_add_item(sv_tree, hf_trmac_sv_len, tvb, svoff+0, 1, ENC_BIG_ENDIAN);
168
169         /* Check the SV length; it must be at least 2, to include
170            the subvector length and indicator. */
171         if (sv_length < 2) {
172                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
173                         "Invalid subvector: length < 2");
174                 return 0;       /* tells our caller to give up */
175         }
176
177         sv_id = tvb_get_guint8(tvb, svoff+1);
178         proto_tree_add_item(sv_tree, hf_trmac_sv_id, tvb, svoff+1, 1, ENC_BIG_ENDIAN);
179         proto_item_append_text(sv_item, " (%s)", val_to_str_ext(sv_id, &subvector_vs_ext, "Unknown subvector ID 0x%02X"));
180
181         switch(sv_id) {
182                 case 0x01: /* Beacon Type */
183                         if (sv_length != 4) {
184                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
185                                     "Subvector length is != 4");
186                                 break;
187                         }
188                         beacon_type = tvb_get_ntohs(tvb, svoff+2);
189                         proto_tree_add_item(sv_tree, hf_trmac_beacon_type, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
190                         proto_item_append_text(sv_item,
191                                         ": %s", val_to_str(beacon_type, beacon_vs, "Illegal value: %d"));
192                         break;
193
194                 case 0x02: /* Upstream Neighbor's Address */
195                         if (sv_length != 8) {
196                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
197                                     "Subvector length is != 8");
198                                 break;
199                         }
200                         proto_tree_add_item(sv_tree, hf_trmac_naun, tvb, svoff+2, sv_length-2, ENC_NA);
201                         proto_item_append_text(sv_item, ": %s",
202                                         tvb_ether_to_str(tvb, svoff+2));
203                         break;
204
205                 case 0x03: /* Local Ring Number */
206                         if (sv_length != 4) {
207                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
208                                     "Subvector length is != 4");
209                                 break;
210                         }
211                         ring = tvb_get_ntohs(tvb, svoff+2);
212                         proto_tree_add_item(sv_tree, hf_trmac_local_ring_number, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
213                         proto_item_append_text(sv_item,
214                                 ": 0x%04X (%d)", ring, ring);
215                         break;
216
217                 case 0x04: /* Assign Physical Drop Number */
218                         if (sv_length != 6) {
219                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
220                                     "Subvector length is != 6");
221                                 break;
222                         }
223                         proto_tree_add_item(sv_tree, hf_trmac_assign_physical_drop_number, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
224                         proto_item_append_text(sv_item,
225                                 ": 0x%08X", tvb_get_ntohl(tvb, svoff+2) );
226                         break;
227
228                 case 0x05: /* Error Report Timer Value */
229                         if (sv_length != 4) {
230                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
231                                     "Subvector length is != 4");
232                                 break;
233                         }
234
235                         error_report_timer_value = 10 * tvb_get_ntohs(tvb, svoff+2);
236                         proto_tree_add_uint(sv_tree, hf_trmac_error_report_timer_value, tvb, svoff+2, sv_length-2, error_report_timer_value);
237                         proto_item_append_text(sv_item,
238                                 ": %u ms", error_report_timer_value );
239                         break;
240
241                 case 0x06: /* Authorized Function Classes */
242                         if (sv_length != 4) {
243                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
244                                     "Subvector length is != 4");
245                                 break;
246                         }
247                         proto_tree_add_item(sv_tree, hf_trmac_authorized_function_classes, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
248                         proto_item_append_text(sv_item,
249                                 ": %04X",  tvb_get_ntohs(tvb, svoff+2) );
250                         break;
251
252                 case 0x07: /* Authorized Access Priority */
253                         if (sv_length != 4) {
254                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
255                                     "Subvector length is != 4");
256                                 break;
257                         }
258                         proto_tree_add_item(sv_tree, hf_trmac_authorized_access_priority, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
259                         proto_item_append_text(sv_item,
260                                 ": %04X",  tvb_get_ntohs(tvb, svoff+2) );
261                         break;
262
263                 case 0x09: /* Correlator */
264                         if (sv_length != 4) {
265                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
266                                     "Subvector length is != 4");
267                                 break;
268                         }
269                         proto_tree_add_item(sv_tree, hf_trmac_correlator, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
270                         proto_item_append_text(sv_item,
271                                 ": %04X",  tvb_get_ntohs(tvb, svoff+2) );
272                         break;
273
274                 case 0x0A: /* SA of Last AMP or SMP Frame */
275                         if (sv_length != 8) {
276                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
277                                     "Subvector length is != 8");
278                                 break;
279                         }
280                         proto_tree_add_item(sv_tree, hf_trmac_sa_of_last_amp_or_smp_frame, tvb, svoff+2, sv_length-2, ENC_NA);
281                         proto_item_append_text(sv_item,
282                                 ": %s",
283                                 tvb_ether_to_str(tvb, svoff+2));
284                         break;
285
286                 case 0x0B: /* Physical Drop Number */
287                         if (sv_length != 6) {
288                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
289                                     "Subvector length is != 6");
290                                 break;
291                         }
292                         proto_tree_add_item(sv_tree, hf_trmac_physical_drop_number, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
293                         proto_item_append_text(sv_item,
294                                 ": 0x%08X", tvb_get_ntohl(tvb, svoff+2) );
295                         break;
296
297                 case 0x20: /* Response Code */
298                         if (sv_length != 4 && sv_length != 6) {
299                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
300                                     "Subvector length is != 4 and != 6");
301                                 break;
302                         }
303                         if (sv_length == 4) {
304                                 proto_tree_add_uint_format_value(sv_tree, hf_trmac_response_code32, tvb, svoff+2, sv_length-2,
305                                         tvb_get_ntohl(tvb, svoff+2), "0x%04X 0x%02X 0x%02x",
306                                         tvb_get_ntohs(tvb, svoff+2), tvb_get_guint8(tvb, svoff+4), tvb_get_guint8(tvb, svoff+5));
307                                 proto_item_append_text(sv_item,
308                                         ": 0x%04X 0x%02X 0x%02x",
309                                         tvb_get_ntohs(tvb, svoff+2),
310                                         tvb_get_guint8(tvb, svoff+4),
311                                         tvb_get_guint8(tvb, svoff+5));
312                         } else {
313                                 proto_tree_add_uint64_format_value(sv_tree, hf_trmac_response_code48, tvb, svoff+2, sv_length-2,
314                                         tvb_get_ntoh48(tvb, svoff+2), "0x%04X 0x%02X 0x%06X",
315                                         tvb_get_ntohs(tvb, svoff+2),
316                                         tvb_get_guint8(tvb, svoff+4),
317                                         tvb_get_ntoh24(tvb, svoff+5));
318                                 proto_item_append_text(sv_item,
319                                         ": 0x%04X 0x%02X 0x%06X",
320                                         tvb_get_ntohs(tvb, svoff+2),
321                                         tvb_get_guint8(tvb, svoff+4),
322                                         tvb_get_ntoh24(tvb, svoff+5));
323                         }
324                         break;
325
326                 case 0x21: /* Individual Address Count */
327                         if (sv_length != 4) {
328                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
329                                     "Subvector length is != 4");
330                                 break;
331                         }
332                         proto_tree_add_item(sv_tree, hf_trmac_individual_address_count, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
333                         proto_item_append_text(sv_item,
334                                 ": %u", tvb_get_ntohs(tvb, svoff+2) );
335                         break;
336
337                 case 0x22: /* Product Instance ID */
338                         proto_tree_add_item(sv_tree, hf_trmac_product_instance_id, tvb, svoff+2, sv_length-2, ENC_NA);
339                         break;
340
341                 case 0x23: /* Ring Station Version Number */
342                         proto_tree_add_item(sv_tree, hf_trmac_ring_station_version_number, tvb, svoff+2, sv_length-2, ENC_NA);
343                         break;
344
345                 case 0x26: /* Wrap data */
346                         proto_tree_add_item(sv_tree, hf_trmac_wrap_data, tvb, svoff+2, sv_length-2, ENC_NA);
347                         break;
348
349                 case 0x27: /* Frame Forward */
350                         proto_tree_add_item(sv_tree, hf_trmac_frame_forward, tvb, svoff+2, sv_length-2, ENC_NA);
351                         break;
352
353                 case 0x28: /* Station Identifier */
354                         if (sv_length != 8) {
355                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
356                                     "Subvector length is != 8");
357                                 break;
358                         }
359                         proto_tree_add_item(sv_tree, hf_trmac_station_identifier, tvb, svoff+2, sv_length-2, ENC_NA);
360                         proto_item_append_text(sv_item,
361                                 ": %s",
362                                 tvb_ether_to_str(tvb, svoff+2));
363                         break;
364
365                 case 0x29: /* Ring Station Status */
366                         proto_tree_add_item(sv_tree, hf_trmac_ring_station_status, tvb, svoff+2, sv_length-2, ENC_NA);
367                         break;
368
369                 case 0x2A: /* Transmit Status Code */
370                         if (sv_length != 4) {
371                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
372                                     "Subvector length is != 4");
373                                 break;
374                         }
375                         proto_tree_add_item(sv_tree, hf_trmac_transmit_status_code, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
376                         proto_item_append_text(sv_item,
377                                 ": %04X", tvb_get_ntohs(tvb, svoff+2) );
378                         break;
379
380                 case 0x2B: /* Group Address */
381                         if (sv_length != 6 && sv_length != 8) {
382                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
383                                     "Subvector length is != 6 and != 8");
384                                 break;
385                         }
386                         if (sv_length == 6) {
387                                 proto_tree_add_item(sv_tree, hf_trmac_group_address32, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
388                                 proto_item_append_text(sv_item,
389                                         ": %08X", tvb_get_ntohl(tvb, svoff+2) );
390                         } else {
391                                 proto_tree_add_item(sv_tree, hf_trmac_group_address_ether, tvb, svoff+2, sv_length-2, ENC_NA);
392                                 proto_item_append_text(sv_item,
393                                         ": %s",
394                                         tvb_ether_to_str(tvb, svoff+2));
395                         }
396                         break;
397
398                 case 0x2C: /* Functional Addresses */
399                         if (sv_length != 6) {
400                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
401                                     "Subvector length is != 6");
402                                 break;
403                         }
404                         proto_tree_add_item(sv_tree, hf_trmac_functional_addresses, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
405                         proto_item_append_text(sv_item,
406                                 ": %08X", tvb_get_ntohl(tvb, svoff+2) );
407                         break;
408
409                 case 0x2D: /* Isolating Error Counts */
410                         if (sv_length != 8) {
411                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
412                                     "Subvector length is != 8");
413                                 break;
414                         }
415                         tvb_memcpy(tvb, errors, svoff+2, 6);
416                         ti = proto_tree_add_uint(sv_tree, hf_trmac_errors_iso, tvb, svoff+2, sv_length-2,
417                                 errors[0] + errors[1] + errors[2] + errors[3] + errors[4]);
418                         sv_subtree = proto_item_add_subtree(ti, ett_tr_ierr_cnt);
419
420                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_line, tvb, svoff+2, 1, errors[0]);
421                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_internal, tvb, svoff+3, 1, errors[1]);
422                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_burst, tvb, svoff+4, 1, errors[2]);
423                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_ac, tvb, svoff+5, 1, errors[3]);
424                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_abort, tvb, svoff+6, 1, errors[4]);
425
426                         break;
427
428                 case 0x2E: /* Non-Isolating Error Counts */
429                         if (sv_length != 8) {
430                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
431                                     "Subvector length is != 8");
432                                 break;
433                         }
434                         tvb_memcpy(tvb, errors, svoff+2, 6);
435                         ti = proto_tree_add_uint(sv_tree, hf_trmac_errors_noniso, tvb, svoff+2, sv_length-2,
436                                 errors[0] + errors[1] + errors[2] + errors[3] + errors[4]);
437                         sv_subtree = proto_item_add_subtree(ti, ett_tr_nerr_cnt);
438
439                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_lost, tvb, svoff+2, 1, errors[0]);
440                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_congestion, tvb, svoff+3, 1, errors[1]);
441                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_fc, tvb, svoff+4, 1, errors[2]);
442                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_freq, tvb, svoff+5, 1, errors[3]);
443                         proto_tree_add_uint(sv_subtree, hf_trmac_errors_token, tvb, svoff+6, 1, errors[4]);
444                         break;
445
446                 case 0x30: /* Error Code */
447                         if (sv_length != 4) {
448                                 expert_add_info_format(pinfo, len_item, &ei_trmac_sv_len,
449                                     "Subvector length is != 4");
450                                 break;
451                         }
452                         proto_tree_add_item(sv_tree, hf_trmac_error_code, tvb, svoff+2, sv_length-2, ENC_BIG_ENDIAN);
453                         proto_item_append_text(sv_item,
454                                 ": %04X", tvb_get_ntohs(tvb, svoff+2) );
455                         break;
456
457                 default: /* Unknown */
458                         proto_tree_add_item(sv_tree, hf_trmac_unknown_subvector, tvb, svoff+2, sv_length-2, ENC_NA);
459                         break;
460         }
461         return sv_length;
462 }
463
464 static int
465 dissect_trmac(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
466 {
467         proto_tree      *mac_tree;
468         proto_item      *ti;
469         int             sv_additional;
470         guint32         mv_val, mv_length, sv_offset;
471
472         if (tvb_captured_length(tvb) < 3)
473                 return 0;
474
475         col_set_str(pinfo->cinfo, COL_PROTOCOL, "TR MAC");
476         col_clear(pinfo->cinfo, COL_INFO);
477
478         ti = proto_tree_add_item(tree, proto_trmac, tvb, 0, -1, ENC_NA);
479         mac_tree = proto_item_add_subtree(ti, ett_tr_mac);
480
481         proto_tree_add_item_ret_uint(mac_tree, hf_trmac_mv, tvb, 3, 1, ENC_NA, &mv_val);
482         proto_tree_add_item_ret_uint(mac_tree, hf_trmac_length, tvb, 0, 2, ENC_BIG_ENDIAN, &mv_length);
483         proto_item_set_len(ti, mv_length);
484         proto_tree_add_item(mac_tree, hf_trmac_srcclass, tvb, 2, 1, ENC_NA);
485         proto_tree_add_item(mac_tree, hf_trmac_dstclass, tvb, 2, 1, ENC_NA);
486
487         /* Interpret the major vector */
488         col_add_str(pinfo->cinfo, COL_INFO,
489                     val_to_str_ext(mv_val, &major_vector_vs_ext, "Unknown Major Vector: %u"));
490
491         /* interpret the subvectors */
492         sv_offset = 4;
493         while (sv_offset < mv_length) {
494                 sv_additional = sv_text(tvb, sv_offset, pinfo, mac_tree);
495
496                 /* if this is a bad packet, we could get a 0-length added here,
497                         * looping forever */
498                 if (sv_additional > 0)
499                         sv_offset += sv_additional;
500                 else
501                         break;
502         }
503
504         return tvb_captured_length(tvb);
505 }
506
507 void
508 proto_register_trmac(void)
509 {
510         static hf_register_info hf[] = {
511                 { &hf_trmac_mv,
512                 { "Major Vector",                       "trmac.mvec", FT_UINT8, BASE_HEX|BASE_EXT_STRING, &major_vector_vs_ext, 0x0,
513                         NULL, HFILL }},
514
515                 { &hf_trmac_length,
516                 { "Total Length",                       "trmac.length", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, &units_byte_bytes, 0x0,
517                         NULL, HFILL }},
518
519                 { &hf_trmac_srcclass,
520                 { "Source Class",                       "trmac.srcclass", FT_UINT8, BASE_HEX, VALS(classes_vs), 0x0F,
521                         NULL, HFILL }},
522
523                 { &hf_trmac_dstclass,
524                 { "Destination Class",                  "trmac.dstclass", FT_UINT8, BASE_HEX, VALS(classes_vs), 0xF0,
525                         NULL, HFILL }},
526
527                 { &hf_trmac_sv_len,
528                 { "Subvector Length",                   "trmac.svec.len", FT_UINT8, BASE_DEC, NULL, 0x0,
529                         NULL, HFILL }},
530
531                 { &hf_trmac_sv_id,
532                 { "Subvector Identifier",               "trmac.svec.id", FT_UINT8, BASE_HEX|BASE_EXT_STRING, &subvector_vs_ext, 0x0,
533                         NULL, HFILL }},
534
535                 { &hf_trmac_errors_iso,
536                 { "Isolating Errors",                   "trmac.errors.iso", FT_UINT16, BASE_DEC, NULL, 0x0,
537                         NULL, HFILL }},
538
539                 { &hf_trmac_errors_line,
540                 { "Line Errors",                        "trmac.errors.line", FT_UINT8, BASE_DEC, NULL, 0x0,
541                         NULL, HFILL }},
542
543                 { &hf_trmac_errors_internal,
544                 { "Internal Errors",                    "trmac.errors.internal", FT_UINT8, BASE_DEC, NULL, 0x0,
545                         NULL, HFILL }},
546
547                 { &hf_trmac_errors_burst,
548                 { "Burst Errors",                       "trmac.errors.burst", FT_UINT8, BASE_DEC, NULL, 0x0,
549                         NULL, HFILL }},
550
551                 { &hf_trmac_errors_ac,
552                 { "A/C Errors",                         "trmac.errors.ac", FT_UINT8, BASE_DEC, NULL, 0x0,
553                         NULL, HFILL }},
554
555                 { &hf_trmac_errors_abort,
556                 { "Abort Delimiter Transmitted Errors", "trmac.errors.abort", FT_UINT8, BASE_DEC, NULL, 0x0,
557                         NULL, HFILL }},
558
559                 { &hf_trmac_errors_noniso,
560                 { "Non-Isolating Errors",               "trmac.errors.noniso", FT_UINT16, BASE_DEC, NULL, 0x0,
561                         NULL, HFILL }},
562
563                 { &hf_trmac_errors_lost,
564                 { "Lost Frame Errors",                  "trmac.errors.lost", FT_UINT8, BASE_DEC, NULL, 0x0,
565                         NULL, HFILL }},
566
567                 { &hf_trmac_errors_congestion,
568                 { "Receiver Congestion Errors",         "trmac.errors.congestion", FT_UINT8, BASE_DEC, NULL, 0x0,
569                         NULL, HFILL }},
570
571                 { &hf_trmac_errors_fc,
572                 { "Frame-Copied Errors",                "trmac.errors.fc", FT_UINT8, BASE_DEC, NULL, 0x0,
573                         NULL, HFILL }},
574
575                 { &hf_trmac_errors_freq,
576                 { "Frequency Errors",                   "trmac.errors.freq", FT_UINT8, BASE_DEC, NULL, 0x0,
577                         NULL, HFILL }},
578
579                 { &hf_trmac_errors_token,
580                 { "Token Errors",                       "trmac.errors.token", FT_UINT8, BASE_DEC, NULL, 0x0,
581                         NULL, HFILL }},
582
583                 { &hf_trmac_naun,
584                 { "Upstream Neighbor's Address",        "trmac.naun", FT_ETHER, BASE_NONE, NULL, 0x0,
585                         NULL, HFILL }},
586
587                 { &hf_trmac_beacon_type,
588                 { "Beacon Type",                        "trmac.beacon_type", FT_UINT16, BASE_DEC, VALS(beacon_vs), 0x0,
589                         NULL, HFILL }},
590
591                 { &hf_trmac_local_ring_number,
592                 { "Local Ring Number",                  "trmac.local_ring_number", FT_UINT16, BASE_HEX_DEC, NULL, 0x0,
593                         NULL, HFILL }},
594
595                 { &hf_trmac_assign_physical_drop_number,
596                 { "Assign Physical Drop Number",        "trmac.assign_physical_drop_number", FT_UINT32, BASE_HEX, NULL, 0x0,
597                         NULL, HFILL }},
598
599                 { &hf_trmac_error_report_timer_value,
600                 { "Error Report Timer Value",           "trmac.error_report_timer_value", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, &units_milliseconds, 0x0,
601                         NULL, HFILL }},
602
603                 { &hf_trmac_authorized_function_classes,
604                 { "Authorized Function Classes",        "trmac.authorized_function_classes", FT_UINT16, BASE_HEX, NULL, 0x0,
605                         NULL, HFILL }},
606
607                 { &hf_trmac_authorized_access_priority,
608                 { "Authorized Access Priority",         "trmac.authorized_access_priority", FT_UINT16, BASE_HEX, NULL, 0x0,
609                         NULL, HFILL }},
610
611                 { &hf_trmac_correlator,
612                 { "Correlator",                         "trmac.correlator", FT_UINT16, BASE_HEX, NULL, 0x0,
613                         NULL, HFILL }},
614
615                 { &hf_trmac_sa_of_last_amp_or_smp_frame,
616                 { "SA of Last AMP or SMP Frame",        "trmac.sa_of_last_amp_or_smp_frame", FT_ETHER, BASE_NONE, NULL, 0x0,
617                         NULL, HFILL }},
618
619                 { &hf_trmac_physical_drop_number,
620                 { "Physical Drop Number",               "trmac.physical_drop_number", FT_UINT32, BASE_HEX, NULL, 0x0,
621                         NULL, HFILL }},
622
623                 { &hf_trmac_individual_address_count,
624                 { "Individual Address Count",           "trmac.individual_address_count", FT_UINT16, BASE_DEC, NULL, 0x0,
625                         NULL, HFILL }},
626
627                 { &hf_trmac_station_identifier,
628                 { "Station Identifier",                 "trmac.station_identifier", FT_ETHER, BASE_NONE, NULL, 0x0,
629                         NULL, HFILL }},
630
631                 { &hf_trmac_transmit_status_code,
632                 { "Transmit Status Code",               "trmac.transmit_status_code", FT_UINT16, BASE_HEX, NULL, 0x0,
633                         NULL, HFILL }},
634
635                 { &hf_trmac_group_address32,
636                 { "Group Address",                      "trmac.group_addres32s", FT_UINT32, BASE_HEX, NULL, 0x0,
637                         NULL, HFILL }},
638
639                 { &hf_trmac_group_address_ether,
640                 { "Group Address",                      "trmac.group_address_ether", FT_ETHER, BASE_NONE, NULL, 0x0,
641                         NULL, HFILL }},
642
643                 { &hf_trmac_functional_addresses,
644                 { "Functional Addresses",               "trmac.functional_addresses", FT_UINT32, BASE_HEX, NULL, 0x0,
645                         NULL, HFILL }},
646
647                 { &hf_trmac_error_code,
648                 { "Error Code",                         "trmac.error_code", FT_UINT16, BASE_HEX, NULL, 0x0,
649                         NULL, HFILL }},
650
651                 /* Generated from convert_proto_tree_add_text.pl */
652                 { &hf_trmac_response_code32, { "Response Code", "trmac.response_code", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }},
653                 { &hf_trmac_response_code48, { "Response Code", "trmac.response_code48", FT_UINT64, BASE_HEX, NULL, 0x0, NULL, HFILL }},
654                 { &hf_trmac_product_instance_id, { "Product Instance ID", "trmac.product_instance_id", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
655                 { &hf_trmac_ring_station_version_number, { "Ring Station Version Number", "trmac.ring_station_version_number", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
656                 { &hf_trmac_wrap_data, { "Wrap Data", "trmac.wrap_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
657                 { &hf_trmac_frame_forward, { "Frame Forward", "trmac.frame_forward", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
658                 { &hf_trmac_ring_station_status, { "Ring Station Status", "trmac.ring_station_status", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
659                 { &hf_trmac_unknown_subvector, { "Unknown Subvector", "trmac.unknown_subvector", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
660
661         };
662         static gint *ett[] = {
663                 &ett_tr_mac,
664                 &ett_tr_sv,
665                 &ett_tr_ierr_cnt,
666                 &ett_tr_nerr_cnt,
667         };
668
669         static ei_register_info ei[] = {
670                 { &ei_trmac_sv_len, { "trmac.svec.len.invalid", PI_MALFORMED, PI_ERROR, "Invalid length", EXPFILL }},
671         };
672
673         expert_module_t* expert_trmac;
674
675         proto_trmac = proto_register_protocol("Token-Ring Media Access Control", "TR MAC", "trmac");
676         proto_register_field_array(proto_trmac, hf, array_length(hf));
677         proto_register_subtree_array(ett, array_length(ett));
678         expert_trmac = expert_register_protocol(proto_trmac);
679         expert_register_field_array(expert_trmac, ei, array_length(ei));
680
681         register_dissector("trmac", dissect_trmac, proto_trmac);
682 }
683
684 /*
685  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
686  *
687  * Local variables:
688  * c-basic-offset: 8
689  * tab-width: 8
690  * indent-tabs-mode: t
691  * End:
692  *
693  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
694  * :indentSize=8:tabSize=8:noTabs=false:
695  */