Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-atm.c
1 /* packet-atm.c
2  * Routines for ATM packet disassembly
3  *
4  * $Id: packet-atm.c,v 1.49 2002/08/28 21:00:07 jmayer Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <stdio.h>
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include "oui.h"
33 #include <epan/resolv.h>
34
35 #include "packet-atm.h"
36 #include "packet-snmp.h"
37 #include "packet-eth.h"
38 #include "packet-tr.h"
39 #include "packet-llc.h"
40
41 static int proto_atm = -1;
42 static int hf_atm_vpi = -1;
43 static int hf_atm_vci = -1;
44 static int proto_atm_lane = -1;
45 static int proto_ilmi = -1;
46
47 static gint ett_atm = -1;
48 static gint ett_atm_lane = -1;
49 static gint ett_atm_lane_lc_lan_dest = -1;
50 static gint ett_atm_lane_lc_lan_dest_rd = -1;
51 static gint ett_atm_lane_lc_flags = -1;
52 static gint ett_atm_lane_lc_tlv = -1;
53 static gint ett_ilmi = -1;
54
55 static dissector_handle_t eth_handle;
56 static dissector_handle_t tr_handle;
57 static dissector_handle_t llc_handle;
58 static dissector_handle_t sscop_handle;
59 static dissector_handle_t lane_handle;
60 static dissector_handle_t ilmi_handle;
61 static dissector_handle_t data_handle;
62
63 /*
64  * See
65  *
66  *      http://www.atmforum.org/atmforum/specs/approved.html
67  *
68  * for a number of ATM Forum specifications, e.g. the LAN Emulation
69  * over ATM 1.0 spec, whence I got most of this.
70  */
71
72 /* LE Control opcodes */
73 #define LE_CONFIGURE_REQUEST    0x0001
74 #define LE_CONFIGURE_RESPONSE   0x0101
75 #define LE_JOIN_REQUEST         0x0002
76 #define LE_JOIN_RESPONSE        0x0102
77 #define READY_QUERY             0x0003
78 #define READY_IND               0x0103
79 #define LE_REGISTER_REQUEST     0x0004
80 #define LE_REGISTER_RESPONSE    0x0104
81 #define LE_UNREGISTER_REQUEST   0x0005
82 #define LE_UNREGISTER_RESPONSE  0x0105
83 #define LE_ARP_REQUEST          0x0006
84 #define LE_ARP_RESPONSE         0x0106
85 #define LE_FLUSH_REQUEST        0x0007
86 #define LE_FLUSH_RESPONSE       0x0107
87 #define LE_NARP_REQUEST         0x0008
88 #define LE_TOPOLOGY_REQUEST     0x0009
89 #define LE_VERIFY_REQUEST       0x000A
90 #define LE_VERIFY_RESPONSE      0x010A
91
92 static const value_string le_control_opcode_vals[] = {
93         { LE_CONFIGURE_REQUEST,   "LE_CONFIGURE_REQUEST" },
94         { LE_CONFIGURE_RESPONSE,  "LE_CONFIGURE_RESPONSE" },
95         { LE_JOIN_REQUEST,        "LE_JOIN_REQUEST" },
96         { LE_JOIN_RESPONSE,       "LE_JOIN_RESPONSE" },
97         { READY_QUERY,            "READY_QUERY" },
98         { READY_IND,              "READY_IND" },
99         { LE_REGISTER_REQUEST,    "LE_REGISTER_REQUEST" },
100         { LE_REGISTER_RESPONSE,   "LE_REGISTER_RESPONSE" },
101         { LE_UNREGISTER_REQUEST,  "LE_UNREGISTER_REQUEST" },
102         { LE_UNREGISTER_RESPONSE, "LE_UNREGISTER_RESPONSE" },
103         { LE_ARP_REQUEST,         "LE_ARP_REQUEST" },
104         { LE_ARP_RESPONSE,        "LE_ARP_RESPONSE" },
105         { LE_FLUSH_REQUEST,       "LE_FLUSH_REQUEST" },
106         { LE_FLUSH_RESPONSE,      "LE_FLUSH_RESPONSE" },
107         { LE_NARP_REQUEST,        "LE_NARP_REQUEST" },
108         { LE_TOPOLOGY_REQUEST,    "LE_TOPOLOGY_REQUEST" },
109         { LE_VERIFY_REQUEST,      "LE_VERIFY_REQUEST" },
110         { LE_VERIFY_RESPONSE,     "LE_VERIFY_RESPONSE" },
111         { 0,                      NULL }
112 };
113
114 /* LE Control statuses */
115 static const value_string le_control_status_vals[] = {
116         { 0,  "Success" },
117         { 1,  "Version not supported" },
118         { 2,  "Invalid request parameters" },
119         { 4,  "Duplicate LAN destination registration" },
120         { 5,  "Duplicate ATM address" },
121         { 6,  "Insufficient resources to grant request" },
122         { 7,  "Access denied" },
123         { 8,  "Invalid REQUESTOR-ID" },
124         { 9,  "Invalid LAN destination" },
125         { 10, "Invalid ATM address" },
126         { 20, "No configuraton" },
127         { 21, "LE_CONFIGURE error" },
128         { 22, "Insufficient information" },
129         { 24, "TLV not found" },
130         { 0,  NULL }
131 };
132
133 /* LE Control LAN destination tags */
134 #define TAG_NOT_PRESENT         0x0000
135 #define TAG_MAC_ADDRESS         0x0001
136 #define TAG_ROUTE_DESCRIPTOR    0x0002
137
138 static const value_string le_control_landest_tag_vals[] = {
139         { TAG_NOT_PRESENT,       "Not present" },
140         { TAG_MAC_ADDRESS,       "MAC address" },
141         { TAG_ROUTE_DESCRIPTOR,  "Route descriptor" },
142         { 0,                     NULL }
143 };
144
145 /* LE Control LAN types */
146 #define LANT_UNSPEC     0x00
147 #define LANT_802_3      0x01
148 #define LANT_802_5      0x02
149
150 static const value_string le_control_lan_type_vals[] = {
151         { LANT_UNSPEC, "Unspecified" },
152         { LANT_802_3,  "Ethernet/802.3" },
153         { LANT_802_5,  "802.5" },
154         { 0,           NULL }
155 };
156
157 static const value_string le_control_frame_size_vals[] = {
158         { 0x00, "Unspecified" },
159         { 0x01, "1516/1528/1580/1592" },
160         { 0x02, "4544/4556/1580/1592" },
161         { 0x03, "9234/9246" },
162         { 0x04, "18190/18202" },
163         { 0,    NULL }
164 };
165
166 static void
167 dissect_le_client(tvbuff_t *tvb, proto_tree *tree)
168 {
169   proto_item *ti;
170   proto_tree *lane_tree;
171
172   if (tree) {
173     ti = proto_tree_add_protocol_format(tree, proto_atm_lane, tvb, 0, 2, "ATM LANE");
174     lane_tree = proto_item_add_subtree(ti, ett_atm_lane);
175
176     proto_tree_add_text(lane_tree, tvb, 0, 2, "LE Client: 0x%04X",
177                         tvb_get_ntohs(tvb, 0));
178   }
179 }
180
181 static void
182 dissect_lan_destination(tvbuff_t *tvb, int offset, const char *type, proto_tree *tree)
183 {
184   proto_item *td;
185   proto_tree *dest_tree;
186   guint16 tag;
187   proto_item *trd;
188   proto_tree *rd_tree;
189   guint16 route_descriptor;
190
191   td = proto_tree_add_text(tree, tvb, offset, 8, "%s LAN destination",
192                         type);
193   dest_tree = proto_item_add_subtree(td, ett_atm_lane_lc_lan_dest);
194   tag = tvb_get_ntohs(tvb, offset);
195   proto_tree_add_text(dest_tree, tvb, offset, 2, "Tag: %s",
196         val_to_str(tag, le_control_landest_tag_vals,
197                                 "Unknown (0x%04X)"));
198   offset += 2;
199
200   switch (tag) {
201
202   case TAG_MAC_ADDRESS:
203     proto_tree_add_text(dest_tree, tvb, offset, 6, "MAC address: %s",
204                         ether_to_str(tvb_get_ptr(tvb, offset, 6)));
205     break;
206
207   case TAG_ROUTE_DESCRIPTOR:
208     offset += 4;
209     route_descriptor = tvb_get_ntohs(tvb, offset);
210     trd = proto_tree_add_text(dest_tree, tvb, offset, 2, "Route descriptor: 0x%02X",
211                         route_descriptor);
212     rd_tree = proto_item_add_subtree(td, ett_atm_lane_lc_lan_dest_rd);
213     proto_tree_add_text(rd_tree, tvb, offset, 2,
214             decode_numeric_bitfield(route_descriptor, 0xFFF0, 2*8,
215                         "LAN ID = %u"));
216     proto_tree_add_text(rd_tree, tvb, offset, 2,
217             decode_numeric_bitfield(route_descriptor, 0x000F, 2*8,
218                         "Bridge number = %u"));
219     break;
220   }
221 }
222
223 /*
224  * TLV values in LE Control frames.
225  */
226 #define TLV_TYPE(oui, ident)            (((oui) << 8) | (ident))
227
228 #define LE_CONTROL_TIMEOUT              TLV_TYPE(OUI_ATM_FORUM, 0x01)
229 #define LE_MAX_UNK_FRAME_COUNT          TLV_TYPE(OUI_ATM_FORUM, 0x02)
230 #define LE_MAX_UNK_FRAME_TIME           TLV_TYPE(OUI_ATM_FORUM, 0x03)
231 #define LE_VCC_TIMEOUT_PERIOD           TLV_TYPE(OUI_ATM_FORUM, 0x04)
232 #define LE_MAX_RETRY_COUNT              TLV_TYPE(OUI_ATM_FORUM, 0x05)
233 #define LE_AGING_TIME                   TLV_TYPE(OUI_ATM_FORUM, 0x06)
234 #define LE_FORWARD_DELAY_TIME           TLV_TYPE(OUI_ATM_FORUM, 0x07)
235 #define LE_EXPECTED_ARP_RESPONSE_TIME   TLV_TYPE(OUI_ATM_FORUM, 0x08)
236 #define LE_FLUSH_TIMEOUT                TLV_TYPE(OUI_ATM_FORUM, 0x09)
237 #define LE_PATH_SWITCHING_DELAY         TLV_TYPE(OUI_ATM_FORUM, 0x0A)
238 #define LE_LOCAL_SEGMENT_ID             TLV_TYPE(OUI_ATM_FORUM, 0x0B)
239 #define LE_MCAST_SEND_VCC_TYPE          TLV_TYPE(OUI_ATM_FORUM, 0x0C)
240 #define LE_MCAST_SEND_VCC_AVGRATE       TLV_TYPE(OUI_ATM_FORUM, 0x0D)
241 #define LE_MCAST_SEND_VCC_PEAKRATE      TLV_TYPE(OUI_ATM_FORUM, 0x0E)
242 #define LE_CONN_COMPLETION_TIMER        TLV_TYPE(OUI_ATM_FORUM, 0x0F)
243 #define LE_CONFIG_FRAG_INFO             TLV_TYPE(OUI_ATM_FORUM, 0x10)
244 #define LE_LAYER_3_ADDRESS              TLV_TYPE(OUI_ATM_FORUM, 0x11)
245 #define LE_ELAN_ID                      TLV_TYPE(OUI_ATM_FORUM, 0x12)
246 #define LE_SERVICE_CATEGORY             TLV_TYPE(OUI_ATM_FORUM, 0x13)
247 #define LE_LLC_MUXED_ATM_ADDRESS        TLV_TYPE(OUI_ATM_FORUM, 0x2B)
248 #define LE_X5_ADJUSTMENT                TLV_TYPE(OUI_ATM_FORUM, 0x2C)
249 #define LE_PREFERRED_LES                TLV_TYPE(OUI_ATM_FORUM, 0x2D)
250
251 static const value_string le_tlv_type_vals[] = {
252         { LE_CONTROL_TIMEOUT,           "Control Time-out" },
253         { LE_MAX_UNK_FRAME_COUNT,       "Maximum Unknown Frame Count" },
254         { LE_MAX_UNK_FRAME_TIME,        "Maximum Unknown Frame Time" },
255         { LE_VCC_TIMEOUT_PERIOD,        "VCC Time-out" },
256         { LE_MAX_RETRY_COUNT,           "Maximum Retry Count" },
257         { LE_AGING_TIME,                "Aging Time" },
258         { LE_FORWARD_DELAY_TIME,        "Forwarding Delay Time" },
259         { LE_EXPECTED_ARP_RESPONSE_TIME, "Expected LE_ARP Response Time" },
260         { LE_FLUSH_TIMEOUT,             "Flush Time-out" },
261         { LE_PATH_SWITCHING_DELAY,      "Path Switching Delay" },
262         { LE_LOCAL_SEGMENT_ID,          "Local Segment ID" },
263         { LE_MCAST_SEND_VCC_TYPE,       "Mcast Send VCC Type" },
264         { LE_MCAST_SEND_VCC_AVGRATE,    "Mcast Send VCC AvgRate" },
265         { LE_MCAST_SEND_VCC_PEAKRATE,   "Mcast Send VCC PeakRate" },
266         { LE_CONN_COMPLETION_TIMER,     "Connection Completion Timer" },
267         { LE_CONFIG_FRAG_INFO,          "Config Frag Info" },
268         { LE_LAYER_3_ADDRESS,           "Layer 3 Address" },
269         { LE_ELAN_ID,                   "ELAN ID" },
270         { LE_SERVICE_CATEGORY,          "Service Category" },
271         { LE_LLC_MUXED_ATM_ADDRESS,     "LLC-muxed ATM Address" },
272         { LE_X5_ADJUSTMENT,             "X5 Adjustment" },
273         { LE_PREFERRED_LES,             "Preferred LES" },
274         { 0,                            NULL },
275 };
276
277 static void
278 dissect_le_control_tlvs(tvbuff_t *tvb, int offset, guint num_tlvs,
279                         proto_tree *tree)
280 {
281   guint32 tlv_type;
282   guint8 tlv_length;
283   proto_item *ttlv;
284   proto_tree *tlv_tree;
285
286   while (num_tlvs != 0) {
287     tlv_type = tvb_get_ntohl(tvb, offset);
288     tlv_length = tvb_get_guint8(tvb, offset+4);
289     ttlv = proto_tree_add_text(tree, tvb, offset, 5+tlv_length, "TLV type: %s",
290         val_to_str(tlv_type, le_tlv_type_vals, "Unknown (0x%08x)"));
291     tlv_tree = proto_item_add_subtree(ttlv, ett_atm_lane_lc_tlv);
292     proto_tree_add_text(tlv_tree, tvb, offset, 4, "TLV Type: %s",
293         val_to_str(tlv_type, le_tlv_type_vals, "Unknown (0x%08x)"));
294     proto_tree_add_text(tlv_tree, tvb, offset+4, 1, "TLV Length: %u", tlv_length);
295     offset += 5+tlv_length;
296     num_tlvs--;
297   }
298 }
299
300 static void
301 dissect_le_configure_join_frame(tvbuff_t *tvb, int offset, proto_tree *tree)
302 {
303   guint8 num_tlvs;
304   guint8 name_size;
305
306   dissect_lan_destination(tvb, offset, "Source", tree);
307   offset += 8;
308
309   dissect_lan_destination(tvb, offset, "Target", tree);
310   offset += 8;
311
312   proto_tree_add_text(tree, tvb, offset, 20, "Source ATM Address: %s",
313                       tvb_bytes_to_str(tvb, offset, 20));
314   offset += 20;
315
316   proto_tree_add_text(tree, tvb, offset, 1, "LAN type: %s",
317         val_to_str(tvb_get_guint8(tvb, offset), le_control_lan_type_vals,
318                                 "Unknown (0x%02X)"));
319   offset += 1;
320
321   proto_tree_add_text(tree, tvb, offset, 1, "Maximum frame size: %s",
322         val_to_str(tvb_get_guint8(tvb, offset), le_control_frame_size_vals,
323                                 "Unknown (0x%02X)"));
324   offset += 1;
325
326   num_tlvs = tvb_get_guint8(tvb, offset);
327   proto_tree_add_text(tree, tvb, offset, 1, "Number of TLVs: %u", num_tlvs);
328   offset += 1;
329
330   name_size = tvb_get_guint8(tvb, offset);
331   proto_tree_add_text(tree, tvb, offset, 1, "ELAN name size: %u", name_size);
332   offset += 1;
333
334   proto_tree_add_text(tree, tvb, offset, 20, "Target ATM Address: %s",
335                       tvb_bytes_to_str(tvb, offset, 20));
336   offset += 20;
337
338   if (name_size > 32)
339     name_size = 32;
340   if (name_size != 0) {
341     proto_tree_add_text(tree, tvb, offset, name_size, "ELAN name: %s",
342                         tvb_bytes_to_str(tvb, offset, name_size));
343   }
344   offset += 32;
345
346   dissect_le_control_tlvs(tvb, offset, num_tlvs, tree);
347 }
348
349 static void
350 dissect_le_registration_frame(tvbuff_t *tvb, int offset, proto_tree *tree)
351 {
352   guint8 num_tlvs;
353
354   dissect_lan_destination(tvb, offset, "Source", tree);
355   offset += 8;
356
357   dissect_lan_destination(tvb, offset, "Target", tree);
358   offset += 8;
359
360   proto_tree_add_text(tree, tvb, offset, 20, "Source ATM Address: %s",
361                       tvb_bytes_to_str(tvb, offset, 20));
362   offset += 20;
363
364   /* Reserved */
365   offset += 2;
366
367   num_tlvs = tvb_get_guint8(tvb, offset);
368   proto_tree_add_text(tree, tvb, offset, 1, "Number of TLVs: %u", num_tlvs);
369   offset += 1;
370
371   /* Reserved */
372   offset += 53;
373
374   dissect_le_control_tlvs(tvb, offset, num_tlvs, tree);
375 }
376
377 static void
378 dissect_le_arp_frame(tvbuff_t *tvb, int offset, proto_tree *tree)
379 {
380   guint8 num_tlvs;
381
382   dissect_lan_destination(tvb, offset, "Source", tree);
383   offset += 8;
384
385   dissect_lan_destination(tvb, offset, "Target", tree);
386   offset += 8;
387
388   proto_tree_add_text(tree, tvb, offset, 20, "Source ATM Address: %s",
389                       tvb_bytes_to_str(tvb, offset, 20));
390   offset += 20;
391
392   /* Reserved */
393   offset += 2;
394
395   num_tlvs = tvb_get_guint8(tvb, offset);
396   proto_tree_add_text(tree, tvb, offset, 1, "Number of TLVs: %u", num_tlvs);
397   offset += 1;
398
399   /* Reserved */
400   offset += 1;
401
402   proto_tree_add_text(tree, tvb, offset, 20, "Target ATM Address: %s",
403                       tvb_bytes_to_str(tvb, offset, 20));
404   offset += 20;
405
406   /* Reserved */
407   offset += 32;
408
409   dissect_le_control_tlvs(tvb, offset, num_tlvs, tree);
410 }
411
412 static void
413 dissect_le_verify_frame(tvbuff_t *tvb, int offset, proto_tree *tree)
414 {
415   guint8 num_tlvs;
416
417   /* Reserved */
418   offset += 38;
419
420   num_tlvs = tvb_get_guint8(tvb, offset);
421   proto_tree_add_text(tree, tvb, offset, 1, "Number of TLVs: %u", num_tlvs);
422   offset += 1;
423
424   /* Reserved */
425   offset += 1;
426
427   proto_tree_add_text(tree, tvb, offset, 20, "Target ATM Address: %s",
428                       tvb_bytes_to_str(tvb, offset, 20));
429   offset += 20;
430
431   /* Reserved */
432   offset += 32;
433
434   dissect_le_control_tlvs(tvb, offset, num_tlvs, tree);
435 }
436
437 static void
438 dissect_le_flush_frame(tvbuff_t *tvb, int offset, proto_tree *tree)
439 {
440   dissect_lan_destination(tvb, offset, "Source", tree);
441   offset += 8;
442
443   dissect_lan_destination(tvb, offset, "Target", tree);
444   offset += 8;
445
446   proto_tree_add_text(tree, tvb, offset, 20, "Source ATM Address: %s",
447                       tvb_bytes_to_str(tvb, offset, 20));
448   offset += 20;
449
450   /* Reserved */
451   offset += 4;
452
453   proto_tree_add_text(tree, tvb, offset, 20, "Target ATM Address: %s",
454                       tvb_bytes_to_str(tvb, offset, 20));
455   offset += 20;
456
457   /* Reserved */
458   offset += 32;
459 }
460
461 static void
462 dissect_le_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
463 {
464   proto_item *ti;
465   proto_tree *lane_tree = NULL;
466   int offset = 0;
467   proto_item *tf;
468   proto_tree *flags_tree;
469   guint16 opcode;
470   guint16 flags;
471
472   if (check_col(pinfo->cinfo, COL_INFO))
473     col_set_str(pinfo->cinfo, COL_INFO, "LE Control");
474
475   if (tree) {
476     ti = proto_tree_add_protocol_format(tree, proto_atm_lane, tvb, offset, 108, "ATM LANE");
477     lane_tree = proto_item_add_subtree(ti, ett_atm_lane);
478
479     proto_tree_add_text(lane_tree, tvb, offset, 2, "Marker: 0x%04X",
480                         tvb_get_ntohs(tvb, offset));
481   }
482   offset += 2;
483
484   if (tree) {
485     proto_tree_add_text(lane_tree, tvb, offset, 1, "Protocol: 0x%02X",
486                         tvb_get_guint8(tvb, offset));
487   }
488   offset += 1;
489
490   if (tree) {
491     proto_tree_add_text(lane_tree, tvb, offset, 1, "Version: 0x%02X",
492                         tvb_get_guint8(tvb, offset));
493   }
494   offset += 1;
495
496   opcode = tvb_get_ntohs(tvb, offset);
497   if (check_col(pinfo->cinfo, COL_INFO)) {
498     col_append_fstr(pinfo->cinfo, COL_INFO, ": %s",
499         val_to_str(opcode, le_control_opcode_vals,
500                                 "Unknown opcode (0x%04X)"));
501   }
502   if (tree) {
503     proto_tree_add_text(lane_tree, tvb, offset, 2, "Opcode: %s",
504         val_to_str(opcode, le_control_opcode_vals,
505                                 "Unknown (0x%04X)"));
506   }
507   offset += 2;
508
509   if (opcode == READY_QUERY || opcode == READY_IND) {
510     /* There's nothing more in this packet. */
511     return;
512   }
513
514   if (tree) {
515     if (opcode & 0x0100) {
516       /* Response; decode status. */
517       proto_tree_add_text(lane_tree, tvb, offset, 2, "Status: %s",
518         val_to_str(tvb_get_ntohs(tvb, offset), le_control_status_vals,
519                                 "Unknown (0x%04X)"));
520     }
521     offset += 2;
522
523     proto_tree_add_text(lane_tree, tvb, offset, 4, "Transaction ID: 0x%08X",
524                         tvb_get_ntohl(tvb, offset));
525     offset += 4;
526
527     proto_tree_add_text(lane_tree, tvb, offset, 2, "Requester LECID: 0x%04X",
528                         tvb_get_ntohs(tvb, offset));
529     offset += 2;
530
531     flags = tvb_get_ntohs(tvb, offset);
532     tf = proto_tree_add_text(lane_tree, tvb, offset, 2, "Flags: 0x%04X",
533                         flags);
534     flags_tree = proto_item_add_subtree(tf, ett_atm_lane_lc_flags);
535
536     switch (opcode) {
537
538     case LE_CONFIGURE_REQUEST:
539     case LE_CONFIGURE_RESPONSE:
540       proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
541         decode_boolean_bitfield(flags, 0x0002, 8*2,
542                                 "V2 capable", "Not V2 capable"));
543       offset += 2;
544       dissect_le_configure_join_frame(tvb, offset, lane_tree);
545       break;
546
547     case LE_JOIN_REQUEST:
548     case LE_JOIN_RESPONSE:
549       proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
550         decode_boolean_bitfield(flags, 0x0002, 8*2,
551                                 "V2 capable", "Not V2 capable"));
552       if (opcode == LE_JOIN_REQUEST) {
553         proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
554                 decode_boolean_bitfield(flags, 0x0004, 8*2,
555                                 "Selective multicast", "No selective multicast"));
556       } else {
557         proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
558                 decode_boolean_bitfield(flags, 0x0008, 8*2,
559                                 "V2 required", "V2 not required"));
560       }
561       proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
562         decode_boolean_bitfield(flags, 0x0080, 8*2,
563                                 "Proxy", "Not proxy"));
564       proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
565         decode_boolean_bitfield(flags, 0x0200, 8*2,
566                                 "Exclude explorer frames",
567                                 "Don't exclude explorer frames"));
568       offset += 2;
569       dissect_le_configure_join_frame(tvb, offset, lane_tree);
570       break;
571
572     case LE_REGISTER_REQUEST:
573     case LE_REGISTER_RESPONSE:
574     case LE_UNREGISTER_REQUEST:
575     case LE_UNREGISTER_RESPONSE:
576       offset += 2;
577       dissect_le_registration_frame(tvb, offset, lane_tree);
578       break;
579
580     case LE_ARP_REQUEST:
581     case LE_ARP_RESPONSE:
582     case LE_NARP_REQUEST:
583       if (opcode != LE_NARP_REQUEST) {
584         proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
585                 decode_boolean_bitfield(flags, 0x0001, 8*2,
586                                 "Remote address", "Local address"));
587       }
588       offset += 2;
589       dissect_le_arp_frame(tvb, offset, lane_tree);
590       break;
591
592     case LE_TOPOLOGY_REQUEST:
593       proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
594         decode_boolean_bitfield(flags, 0x0100, 8*2,
595                                 "Topology change", "No topology change"));
596       offset += 2;
597       /* 92 reserved bytes */
598       break;
599
600     case LE_VERIFY_REQUEST:
601     case LE_VERIFY_RESPONSE:
602       offset += 2;
603       dissect_le_verify_frame(tvb, offset, lane_tree);
604       break;
605
606     case LE_FLUSH_REQUEST:
607     case LE_FLUSH_RESPONSE:
608       offset += 2;
609       dissect_le_flush_frame(tvb, offset, lane_tree);
610       break;
611     }
612   }
613 }
614
615 static void
616 capture_lane(const union wtap_pseudo_header *pseudo_header, const guchar *pd,
617     int len, packet_counts *ld)
618 {
619   /* Is it LE Control, 802.3, 802.5, or "none of the above"? */
620   switch (pseudo_header->atm.subtype) {
621
622   case TRAF_ST_LANE_802_3:
623   case TRAF_ST_LANE_802_3_MC:
624     /* Dissect as Ethernet */
625     capture_eth(pd, 2, len, ld);
626     break;
627
628   case TRAF_ST_LANE_802_5:
629   case TRAF_ST_LANE_802_5_MC:
630     /* Dissect as Token-Ring */
631     capture_tr(pd, 2, len, ld);
632     break;
633
634   default:
635     ld->other++;
636     break;
637   }
638 }
639
640 static void
641 dissect_lane(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
642 {
643   tvbuff_t      *next_tvb;
644   tvbuff_t      *next_tvb_le_client;
645
646   if (check_col(pinfo->cinfo, COL_PROTOCOL))
647     col_set_str(pinfo->cinfo, COL_PROTOCOL, "ATM LANE");
648
649   /* Is it LE Control, 802.3, 802.5, or "none of the above"? */
650   switch (pinfo->pseudo_header->atm.subtype) {
651
652   case TRAF_ST_LANE_LE_CTRL:
653     dissect_le_control(tvb, pinfo, tree);
654     break;
655
656   case TRAF_ST_LANE_802_3:
657   case TRAF_ST_LANE_802_3_MC:
658     if (check_col(pinfo->cinfo, COL_INFO))
659       col_set_str(pinfo->cinfo, COL_INFO, "LE Client - Ethernet/802.3");
660     dissect_le_client(tvb, tree);
661
662     /* Dissect as Ethernet */
663     next_tvb_le_client  = tvb_new_subset(tvb, 2, -1, -1);
664     call_dissector(eth_handle, next_tvb_le_client, pinfo, tree);
665     break;
666
667   case TRAF_ST_LANE_802_5:
668   case TRAF_ST_LANE_802_5_MC:
669     if (check_col(pinfo->cinfo, COL_INFO))
670       col_set_str(pinfo->cinfo, COL_INFO, "LE Client - 802.5");
671     dissect_le_client(tvb, tree);
672
673     /* Dissect as Token-Ring */
674     next_tvb_le_client  = tvb_new_subset(tvb, 2, -1, -1);
675     call_dissector(tr_handle, next_tvb_le_client, pinfo, tree);
676     break;
677
678   default:
679     /* Dump it as raw data. */
680     if (check_col(pinfo->cinfo, COL_INFO))
681       col_set_str(pinfo->cinfo, COL_INFO, "Unknown LANE traffic type");
682     next_tvb            = tvb_new_subset(tvb, 0, -1, -1);
683     call_dissector(data_handle,next_tvb, pinfo, tree);
684     break;
685   }
686 }
687
688 static void
689 dissect_ilmi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
690 {
691   dissect_snmp_pdu(tvb, 0, pinfo, tree, "ILMI", proto_ilmi, ett_ilmi);
692 }
693
694 /* AAL types */
695 static const value_string aal_vals[] = {
696         { AAL_UNKNOWN,    "Unknown AAL" },
697         { AAL_1,          "AAL1" },
698         { AAL_2,          "AAL2" },
699         { AAL_3_4,        "AAL3/4" },
700         { AAL_5,          "AAL5" },
701         { AAL_USER,       "User AAL" },
702         { AAL_SIGNALLING, "Signalling AAL" },
703         { AAL_OAMCELL,    "OAM cell" },
704         { 0,              NULL }
705 };
706
707 /* AAL5 higher-level traffic types */
708 static const value_string aal5_hltype_vals[] = {
709         { TRAF_UNKNOWN, "Unknown traffic type" },
710         { TRAF_LLCMX,   "LLC multiplexed" },
711         { TRAF_VCMX,    "VC multiplexed" },
712         { TRAF_LANE,    "LANE" },
713         { TRAF_ILMI,    "ILMI" },
714         { TRAF_FR,      "Frame Relay" },
715         { TRAF_SPANS,   "FORE SPANS" },
716         { TRAF_IPSILON, "Ipsilon" },
717         { 0,              NULL }
718 };
719
720 /* Traffic subtypes for VC multiplexed traffic */
721 static const value_string vcmx_type_vals[] = {
722         { TRAF_ST_UNKNOWN,        "Unknown VC multiplexed traffic type" },
723         { TRAF_ST_VCMX_802_3_FCS, "802.3 FCS" },
724         { TRAF_ST_VCMX_802_4_FCS, "802.4 FCS" },
725         { TRAF_ST_VCMX_802_5_FCS, "802.5 FCS" },
726         { TRAF_ST_VCMX_FDDI_FCS,  "FDDI FCS" },
727         { TRAF_ST_VCMX_802_6_FCS, "802.6 FCS" },
728         { TRAF_ST_VCMX_802_3,     "802.3" },
729         { TRAF_ST_VCMX_802_4,     "802.4" },
730         { TRAF_ST_VCMX_802_5,     "802.5" },
731         { TRAF_ST_VCMX_FDDI,      "FDDI" },
732         { TRAF_ST_VCMX_802_6,     "802.6" },
733         { TRAF_ST_VCMX_FRAGMENTS, "Fragments" },
734         { TRAF_ST_VCMX_BPDU,      "BPDU" },
735         { 0,                   NULL }
736 };
737
738 /* Traffic subtypes for LANE traffic */
739 static const value_string lane_type_vals[] = {
740         { TRAF_ST_UNKNOWN,       "Unknown LANE traffic type" },
741         { TRAF_ST_LANE_LE_CTRL,  "LE Control" },
742         { TRAF_ST_LANE_802_3,    "802.3" },
743         { TRAF_ST_LANE_802_5,    "802.5" },
744         { TRAF_ST_LANE_802_3_MC, "802.3 multicast" },
745         { TRAF_ST_LANE_802_5_MC, "802.5 multicast" },
746         { 0,                     NULL }
747 };
748
749 /* Traffic subtypes for Ipsilon traffic */
750 static const value_string ipsilon_type_vals[] = {
751         { TRAF_ST_UNKNOWN,     "Unknown Ipsilon traffic type" },
752         { TRAF_ST_IPSILON_FT0, "Flow type 0" },
753         { TRAF_ST_IPSILON_FT1, "Flow type 1" },
754         { TRAF_ST_IPSILON_FT2, "Flow type 2" },
755         { 0,                NULL }
756 };
757
758 void
759 capture_atm(const union wtap_pseudo_header *pseudo_header, const guchar *pd,
760     int len, packet_counts *ld)
761 {
762   if (pseudo_header->atm.aal == AAL_5) {
763     switch (pseudo_header->atm.type) {
764
765     case TRAF_LLCMX:
766       /* Dissect as WTAP_ENCAP_ATM_RFC1483 */
767       /* The ATM iptrace capture that we have shows LLC at this point,
768        * so that's what I'm calling */
769       capture_llc(pd, 0, len, ld);
770       break;
771
772     case TRAF_LANE:
773       capture_lane(pseudo_header, pd, len, ld);
774       break;
775
776     default:
777       ld->other++;
778       break;
779     }
780   } else
781     ld->other++;
782 }
783
784 static void
785 dissect_atm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
786 {
787   proto_tree   *atm_tree;
788   proto_item   *ti;
789
790   if (check_col(pinfo->cinfo, COL_PROTOCOL))
791     col_set_str(pinfo->cinfo, COL_PROTOCOL, "ATM");
792
793   switch (pinfo->pseudo_header->atm.channel) {
794
795   case 0:
796     /* Traffic from DCE to DTE. */
797     if (check_col(pinfo->cinfo, COL_RES_DL_DST))
798       col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DTE");
799     if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
800       col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DCE");
801     break;
802
803   case 1:
804     /* Traffic from DTE to DCE. */
805     if (check_col(pinfo->cinfo, COL_RES_DL_DST))
806       col_set_str(pinfo->cinfo, COL_RES_DL_DST, "DCE");
807     if (check_col(pinfo->cinfo, COL_RES_DL_SRC))
808       col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "DTE");
809     break;
810   }
811
812   if (check_col(pinfo->cinfo, COL_INFO)) {
813     if (pinfo->pseudo_header->atm.aal == AAL_5) {
814       col_add_fstr(pinfo->cinfo, COL_INFO, "AAL5 %s",
815                 val_to_str(pinfo->pseudo_header->atm.type, aal5_hltype_vals,
816                                 "Unknown traffic type (%u)"));
817     } else {
818       col_add_str(pinfo->cinfo, COL_INFO,
819                 val_to_str(pinfo->pseudo_header->atm.aal, aal_vals,
820                         "Unknown AAL (%u)"));
821     }
822   }
823
824   if (tree) {
825     ti = proto_tree_add_protocol_format(tree, proto_atm, tvb, 0, 0, "ATM");
826     atm_tree = proto_item_add_subtree(ti, ett_atm);
827
828     proto_tree_add_text(atm_tree, tvb, 0, 0, "AAL: %s",
829         val_to_str(pinfo->pseudo_header->atm.aal, aal_vals,
830         "Unknown AAL (%u)"));
831     if (pinfo->pseudo_header->atm.aal == AAL_5) {
832       proto_tree_add_text(atm_tree, tvb, 0, 0, "Traffic type: %s",
833         val_to_str(pinfo->pseudo_header->atm.type, aal5_hltype_vals,
834         "Unknown AAL5 traffic type (%u)"));
835       switch (pinfo->pseudo_header->atm.type) {
836
837       case TRAF_VCMX:
838         proto_tree_add_text(atm_tree, tvb, 0, 0, "VC multiplexed traffic type: %s",
839                 val_to_str(pinfo->pseudo_header->atm.subtype,
840                         vcmx_type_vals, "Unknown VCMX traffic type (%u)"));
841         break;
842
843       case TRAF_LANE:
844         proto_tree_add_text(atm_tree, tvb, 0, 0, "LANE traffic type: %s",
845                 val_to_str(pinfo->pseudo_header->atm.subtype,
846                         lane_type_vals, "Unknown LANE traffic type (%u)"));
847         break;
848
849       case TRAF_IPSILON:
850         proto_tree_add_text(atm_tree, tvb, 0, 0, "Ipsilon traffic type: %s",
851                 val_to_str(pinfo->pseudo_header->atm.subtype,
852                         ipsilon_type_vals, "Unknown Ipsilon traffic type (%u)"));
853         break;
854       }
855     }
856     proto_tree_add_uint(atm_tree, hf_atm_vpi, tvb, 0, 0,
857                 pinfo->pseudo_header->atm.vpi);
858     proto_tree_add_uint(atm_tree, hf_atm_vci, tvb, 0, 0,
859                 pinfo->pseudo_header->atm.vci);
860     switch (pinfo->pseudo_header->atm.channel) {
861
862     case 0:
863       /* Traffic from DCE to DTE. */
864       proto_tree_add_text(atm_tree, tvb, 0, 0, "Channel: DCE->DTE");
865       break;
866
867     case 1:
868       /* Traffic from DTE to DCE. */
869       proto_tree_add_text(atm_tree, tvb, 0, 0, "Channel: DTE->DCE");
870       break;
871
872     default:
873       /* Sniffers shouldn't provide anything other than 0 or 1. */
874       proto_tree_add_text(atm_tree, tvb, 0, 0, "Channel: %u",
875                 pinfo->pseudo_header->atm.channel);
876       break;
877     }
878     if (pinfo->pseudo_header->atm.cells != 0) {
879       /*
880        * If the cell count is 0, assume it means we don't know how
881        * many cells it was.
882        *
883        * XXX - also, if this is AAL5 traffic, assume it means we don't
884        * know what was in the AAL5 trailer.  We may, however, find
885        * some capture program that can give us the AAL5 trailer
886        * information but not the cell count, in which case we need
887        * some other way of indicating whether we have the AAL5 trailer
888        * information.
889        */
890       proto_tree_add_text(atm_tree, tvb, 0, 0, "Cells: %u",
891                 pinfo->pseudo_header->atm.cells);
892       if (pinfo->pseudo_header->atm.aal == AAL_5) {
893         proto_tree_add_text(atm_tree, tvb, 0, 0, "AAL5 U2U: %u",
894                 pinfo->pseudo_header->atm.aal5t_u2u);
895         proto_tree_add_text(atm_tree, tvb, 0, 0, "AAL5 len: %u",
896                 pinfo->pseudo_header->atm.aal5t_len);
897         proto_tree_add_text(atm_tree, tvb, 0, 0, "AAL5 checksum: 0x%08X",
898                 pinfo->pseudo_header->atm.aal5t_chksum);
899       }
900     }
901   }
902
903   switch (pinfo->pseudo_header->atm.aal) {
904
905   case AAL_SIGNALLING:
906     call_dissector(sscop_handle, tvb, pinfo, tree);
907     break;
908
909   case AAL_5:
910     switch (pinfo->pseudo_header->atm.type) {
911
912     case TRAF_LLCMX:
913       /* Dissect as WTAP_ENCAP_ATM_RFC1483 */
914       /* The ATM iptrace capture that we have shows LLC at this point,
915        * so that's what I'm calling */
916       call_dissector(llc_handle, tvb, pinfo, tree);
917       break;
918
919     case TRAF_LANE:
920       call_dissector(lane_handle, tvb, pinfo, tree);
921       break;
922
923     case TRAF_ILMI:
924       call_dissector(ilmi_handle, tvb, pinfo, tree);
925       break;
926
927     default:
928       if (tree) {
929         /* Dump it as raw data. */
930         call_dissector(data_handle,tvb, pinfo, tree);
931         break;
932       }
933     }
934     break;
935
936   default:
937     if (tree) {
938       /* Dump it as raw data.  (Is this a single cell?) */
939       call_dissector(data_handle,tvb, pinfo, tree);
940     }
941     break;
942   }
943 }
944
945 void
946 proto_register_atm(void)
947 {
948         static hf_register_info hf[] = {
949                 { &hf_atm_vpi,
950                 { "VPI",                "atm.vpi", FT_UINT8, BASE_DEC, NULL, 0x0,
951                         "", HFILL }},
952
953                 { &hf_atm_vci,
954                 { "VCI",                "atm.vci", FT_UINT16, BASE_DEC, NULL, 0x0,
955                         "", HFILL }},
956         };
957         static gint *ett[] = {
958                 &ett_atm,
959                 &ett_ilmi,
960                 &ett_atm_lane,
961                 &ett_atm_lane_lc_lan_dest,
962                 &ett_atm_lane_lc_lan_dest_rd,
963                 &ett_atm_lane_lc_flags,
964                 &ett_atm_lane_lc_tlv,
965         };
966         proto_atm = proto_register_protocol("ATM", "ATM", "atm");
967         proto_register_field_array(proto_atm, hf, array_length(hf));
968         proto_register_subtree_array(ett, array_length(ett));
969
970         proto_ilmi = proto_register_protocol("ILMI", "ILMI", "ilmi");
971
972         register_dissector("ilmi", dissect_ilmi, proto_ilmi);
973
974         proto_atm_lane = proto_register_protocol("ATM LAN Emulation",
975             "ATM LANE", "lane");
976
977         register_dissector("lane", dissect_lane, proto_atm_lane);
978 }
979
980 void
981 proto_reg_handoff_atm(void)
982 {
983         dissector_handle_t atm_handle;
984
985         /*
986          * Get handles for the Ethernet, Token Ring, LLC, SSCOP, LANE,
987          * and ILMI dissectors.
988          */
989         eth_handle = find_dissector("eth");
990         tr_handle = find_dissector("tr");
991         llc_handle = find_dissector("llc");
992         sscop_handle = find_dissector("sscop");
993         lane_handle = find_dissector("lane");
994         ilmi_handle = find_dissector("ilmi");
995         data_handle = find_dissector("data");
996
997         atm_handle = create_dissector_handle(dissect_atm, proto_atm);
998
999         dissector_add("wtap_encap", WTAP_ENCAP_ATM_SNIFFER, atm_handle);
1000 }