Call the LANE dissector through a handle.
[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.35 2001/05/27 07:46:57 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * 
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33
34 #include <stdio.h>
35 #include <glib.h>
36 #include "packet.h"
37 #include "oui.h"
38 #include "resolv.h"
39
40 #include "packet-snmp.h"
41
42 static int proto_atm = -1;
43 static int hf_atm_vpi = -1;
44 static int hf_atm_vci = -1;
45 static int proto_atm_lane = -1;
46 static int proto_ilmi = -1;
47
48 static gint ett_atm = -1;
49 static gint ett_atm_lane = -1;
50 static gint ett_atm_lane_lc_lan_dest = -1;
51 static gint ett_atm_lane_lc_lan_dest_rd = -1;
52 static gint ett_atm_lane_lc_flags = -1;
53 static gint ett_atm_lane_lc_tlv = -1;
54 static gint ett_ilmi = -1;
55
56 static dissector_handle_t eth_handle;
57 static dissector_handle_t tr_handle;
58 static dissector_handle_t llc_handle;
59 static dissector_handle_t sscop_handle;
60 static dissector_handle_t lane_handle;
61 static dissector_handle_t ilmi_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
90 static const value_string le_control_opcode_vals[] = {
91         { LE_CONFIGURE_REQUEST,   "LE_CONFIGURE_REQUEST" },
92         { LE_CONFIGURE_RESPONSE,  "LE_CONFIGURE_RESPONSE" },
93         { LE_JOIN_REQUEST,        "LE_JOIN_REQUEST" },
94         { LE_JOIN_RESPONSE,       "LE_JOIN_RESPONSE" },
95         { READY_QUERY,            "READY_QUERY" },
96         { READY_IND,              "READY_IND" },
97         { LE_REGISTER_REQUEST,    "LE_REGISTER_REQUEST" },
98         { LE_REGISTER_RESPONSE,   "LE_REGISTER_RESPONSE" },
99         { LE_UNREGISTER_REQUEST,  "LE_UNREGISTER_REQUEST" },
100         { LE_UNREGISTER_RESPONSE, "LE_UNREGISTER_RESPONSE" },
101         { LE_ARP_REQUEST,         "LE_ARP_REQUEST" },
102         { LE_ARP_RESPONSE,        "LE_ARP_RESPONSE" },
103         { LE_FLUSH_REQUEST,       "LE_FLUSH_REQUEST" },
104         { LE_FLUSH_RESPONSE,      "LE_FLUSH_RESPONSE" },
105         { LE_NARP_REQUEST,        "LE_NARP_REQUEST" },
106         { LE_TOPOLOGY_REQUEST,    "LE_TOPOLOGY_REQUEST" },
107         { 0,                      NULL }
108 };
109
110 /* LE Control statuses */
111 static const value_string le_control_status_vals[] = {
112         { 0,  "Success" },
113         { 1,  "Version not supported" },
114         { 2,  "Invalid request parameters" },
115         { 4,  "Duplicate LAN destination registration" },
116         { 5,  "Duplicate ATM address" },
117         { 6,  "Insufficient resources to grant request" },
118         { 7,  "Access denied" },
119         { 8,  "Invalid REQUESTOR-ID" },
120         { 9,  "Invalid LAN destination" },
121         { 10, "Invalid ATM address" },
122         { 20, "No configuraton" },
123         { 21, "LE_CONFIGURE error" },
124         { 22, "Insufficient information" },
125         { 0,  NULL }
126 };
127
128 /* LE Control LAN destination tags */
129 #define TAG_NOT_PRESENT         0x0000
130 #define TAG_MAC_ADDRESS         0x0001
131 #define TAG_ROUTE_DESCRIPTOR    0x0002
132
133 static const value_string le_control_landest_tag_vals[] = {
134         { TAG_NOT_PRESENT,       "Not present" },
135         { TAG_MAC_ADDRESS,       "MAC address" },
136         { TAG_ROUTE_DESCRIPTOR,  "Route descriptor" },
137         { 0,                     NULL }
138 };
139
140 /* LE Control LAN types */
141 #define LANT_UNSPEC     0x00
142 #define LANT_802_3      0x01
143 #define LANT_802_5      0x02
144
145 static const value_string le_control_lan_type_vals[] = {
146         { LANT_UNSPEC, "Unspecified" },
147         { LANT_802_3,  "Ethernet/802.3" },
148         { LANT_802_5,  "802.5" },
149         { 0,           NULL }
150 };
151
152 static void
153 dissect_le_client(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
154 {
155   proto_item *ti;
156   proto_tree *lane_tree;
157
158   if (tree) {
159     ti = proto_tree_add_protocol_format(tree, proto_atm_lane, tvb, 0, 2, "ATM LANE");
160     lane_tree = proto_item_add_subtree(ti, ett_atm_lane);
161
162     proto_tree_add_text(lane_tree, tvb, 0, 2, "LE Client: 0x%04X",
163                         tvb_get_ntohs(tvb, 0));
164   }
165 }
166
167 static void
168 dissect_lan_destination(tvbuff_t *tvb, int offset, const char *type, proto_tree *tree) 
169 {
170   proto_item *td;
171   proto_tree *dest_tree;
172   guint16 tag;
173   proto_item *trd;
174   proto_tree *rd_tree;
175   guint16 route_descriptor;
176
177   td = proto_tree_add_text(tree, tvb, offset, 8, "%s LAN destination",
178                         type);
179   dest_tree = proto_item_add_subtree(td, ett_atm_lane_lc_lan_dest);
180   tag = tvb_get_ntohs(tvb, offset);
181   proto_tree_add_text(dest_tree, tvb, offset, 2, "Tag: %s",
182         val_to_str(tag, le_control_landest_tag_vals,
183                                 "Unknown (0x%04X)"));
184   offset += 2;
185
186   switch (tag) {
187
188   case TAG_MAC_ADDRESS:
189     proto_tree_add_text(dest_tree, tvb, offset, 6, "MAC address: %s",
190                         ether_to_str(tvb_get_ptr(tvb, offset, 6)));
191     break;
192
193   case TAG_ROUTE_DESCRIPTOR:
194     offset += 4;
195     route_descriptor = tvb_get_ntohs(tvb, offset);
196     trd = proto_tree_add_text(dest_tree, tvb, offset, 2, "Route descriptor: 0x%02X",
197                         route_descriptor);
198     rd_tree = proto_item_add_subtree(td, ett_atm_lane_lc_lan_dest_rd);
199     proto_tree_add_text(rd_tree, tvb, offset, 2,
200             decode_numeric_bitfield(route_descriptor, 0xFFF0, 2*8,
201                         "LAN ID = %u"));
202     proto_tree_add_text(rd_tree, tvb, offset, 2,
203             decode_numeric_bitfield(route_descriptor, 0x000F, 2*8,
204                         "Bridge number = %u"));
205     break;
206   }
207 }
208
209 /*
210  * TLV values in LE Control frames.
211  */
212 #define TLV_TYPE(oui, ident)            (((oui) << 8) | (ident))
213
214 #define LE_CONTROL_TIMEOUT              TLV_TYPE(OUI_ATM_FORUM, 0x01)
215 #define LE_MAX_UNK_FRAME_COUNT          TLV_TYPE(OUI_ATM_FORUM, 0x02)
216 #define LE_MAX_UNK_FRAME_TIME           TLV_TYPE(OUI_ATM_FORUM, 0x03)
217 #define LE_VCC_TIMEOUT_PERIOD           TLV_TYPE(OUI_ATM_FORUM, 0x04)
218 #define LE_MAX_RETRY_COUNT              TLV_TYPE(OUI_ATM_FORUM, 0x05)
219 #define LE_AGING_TIME                   TLV_TYPE(OUI_ATM_FORUM, 0x06)
220 #define LE_FORWARD_DELAY_TIME           TLV_TYPE(OUI_ATM_FORUM, 0x07)
221 #define LE_EXPECTED_ARP_RESPONSE_TIME   TLV_TYPE(OUI_ATM_FORUM, 0x08)
222 #define LE_FLUSH_TIMEOUT                TLV_TYPE(OUI_ATM_FORUM, 0x09)
223 #define LE_PATH_SWITCHING_DELAY         TLV_TYPE(OUI_ATM_FORUM, 0x0A)
224 #define LE_LOCAL_SEGMENT_ID             TLV_TYPE(OUI_ATM_FORUM, 0x0B)
225 #define LE_MCAST_SEND_VCC_TYPE          TLV_TYPE(OUI_ATM_FORUM, 0x0C)
226 #define LE_MCAST_SEND_VCC_AVGRATE       TLV_TYPE(OUI_ATM_FORUM, 0x0D)
227 #define LE_MCAST_SEND_VCC_PEAKRATE      TLV_TYPE(OUI_ATM_FORUM, 0x0E)
228 #define LE_CONN_COMPLETION_TIMER        TLV_TYPE(OUI_ATM_FORUM, 0x0F)
229
230 static const value_string le_tlv_type_vals[] = {
231         { LE_CONTROL_TIMEOUT,           "Control Time-out" },
232         { LE_MAX_UNK_FRAME_COUNT,       "Maximum Unknown Frame Count" },
233         { LE_MAX_UNK_FRAME_TIME,        "Maximum Unknown Frame Time" },
234         { LE_VCC_TIMEOUT_PERIOD,        "VCC Time-out" },
235         { LE_MAX_RETRY_COUNT,           "Maximum Retry Count" },
236         { LE_AGING_TIME,                "Aging Time" },
237         { LE_FORWARD_DELAY_TIME,        "Forwarding Delay Time" },
238         { LE_EXPECTED_ARP_RESPONSE_TIME, "Expected LE_ARP Response Time" },
239         { LE_FLUSH_TIMEOUT,             "Flush Time-out" },
240         { LE_PATH_SWITCHING_DELAY,      "Path Switching Delay" },
241         { LE_LOCAL_SEGMENT_ID,          "Local Segment ID" },
242         { LE_MCAST_SEND_VCC_TYPE,       "Mcast Send VCC Type" },
243         { LE_MCAST_SEND_VCC_AVGRATE,    "Mcast Send VCC AvgRate" },
244         { LE_MCAST_SEND_VCC_PEAKRATE,   "Mcast Send VCC PeakRate" },
245         { LE_CONN_COMPLETION_TIMER,     "Connection Completion Timer" },
246         { 0,                            NULL },
247 };
248
249 static void
250 dissect_le_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
251 {
252   proto_item *ti;
253   proto_tree *lane_tree;
254   int offset = 0;
255   proto_item *tf;
256   proto_tree *flags_tree;
257   proto_item *ttlv;
258   proto_tree *tlv_tree;
259   guint16 opcode;
260   guint16 flags;
261   guint8 num_tlvs;
262   guint32 tlv_type;
263   guint8 tlv_length;
264
265   if (check_col(pinfo->fd, COL_INFO))
266     col_set_str(pinfo->fd, COL_INFO, "LE Control");
267
268   if (tree) {
269     ti = proto_tree_add_protocol_format(tree, proto_atm_lane, tvb, offset, 108, "ATM LANE");
270     lane_tree = proto_item_add_subtree(ti, ett_atm_lane);
271
272     proto_tree_add_text(lane_tree, tvb, offset, 2, "Marker: 0x%04X",
273                         tvb_get_ntohs(tvb, offset));
274     offset += 2;
275
276     proto_tree_add_text(lane_tree, tvb, offset, 1, "Protocol: 0x%02X",
277                         tvb_get_guint8(tvb, offset));
278     offset += 1;
279
280     proto_tree_add_text(lane_tree, tvb, offset, 1, "Version: 0x%02X",
281                         tvb_get_guint8(tvb, offset));
282     offset += 1;
283
284     opcode = tvb_get_ntohs(tvb, offset);
285     proto_tree_add_text(lane_tree, tvb, offset, 2, "Opcode: %s",
286         val_to_str(opcode, le_control_opcode_vals,
287                                 "Unknown (0x%04X)"));
288     offset += 2;
289
290     if (opcode == READY_QUERY || opcode == READY_IND) {
291       /* There's nothing more in this packet. */
292       return;
293     }
294
295     if (opcode & 0x0100) {
296       /* Response; decode status. */
297       proto_tree_add_text(lane_tree, tvb, offset, 2, "Status: %s",
298         val_to_str(tvb_get_ntohs(tvb, offset), le_control_status_vals,
299                                 "Unknown (0x%04X)"));
300     }
301     offset += 2;
302
303     proto_tree_add_text(lane_tree, tvb, offset, 4, "Transaction ID: 0x%08X",
304                         tvb_get_ntohl(tvb, offset));
305     offset += 4;
306
307     proto_tree_add_text(lane_tree, tvb, offset, 2, "Requester LECID: 0x%04X",
308                         tvb_get_ntohs(tvb, offset));
309     offset += 2;
310
311     flags = tvb_get_ntohs(tvb, offset);
312     tf = proto_tree_add_text(lane_tree, tvb, offset, 2, "Flags: 0x%04X",
313                         flags);
314     flags_tree = proto_item_add_subtree(tf, ett_atm_lane_lc_flags);
315     proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
316         decode_boolean_bitfield(flags, 0x0001, 8*2,
317                                 "Remote address", "Local address"));
318     proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
319         decode_boolean_bitfield(flags, 0x0080, 8*2,
320                                 "Proxy", "Not proxy"));
321     proto_tree_add_text(flags_tree, tvb, offset, 2, "%s",
322         decode_boolean_bitfield(flags, 0x0100, 8*2,
323                                 "Topology change", "No topology change"));
324     offset += 2;
325
326     dissect_lan_destination(tvb, offset, "Source", lane_tree);
327     offset += 8;
328
329     dissect_lan_destination(tvb, offset, "Target", lane_tree);
330     offset += 8;
331
332     proto_tree_add_text(lane_tree, tvb, offset, 20, "Source ATM Address: %s",
333                         tvb_bytes_to_str(tvb, offset, 20));
334     offset += 20;
335
336     proto_tree_add_text(lane_tree, tvb, offset, 1, "LAN type: %s",
337         val_to_str(tvb_get_guint8(tvb, offset), le_control_lan_type_vals,
338                                 "Unknown (0x%02X)"));
339     offset += 1;
340
341     proto_tree_add_text(lane_tree, tvb, offset, 1, "Maximum frame size: %u",
342                         tvb_get_guint8(tvb, offset));
343     offset += 1;
344
345     num_tlvs = tvb_get_guint8(tvb, offset);
346     proto_tree_add_text(lane_tree, tvb, offset, 1, "Number of TLVs: %u",
347                         num_tlvs);
348     offset += 1;
349
350     proto_tree_add_text(lane_tree, tvb, offset, 1, "ELAN name size: %u",
351                         tvb_get_guint8(tvb, offset));
352     offset += 1;
353
354     proto_tree_add_text(lane_tree, tvb, offset, 20, "Target ATM Address: %s",
355                         tvb_bytes_to_str(tvb, offset, 20));
356     offset += 20;
357
358     proto_tree_add_text(lane_tree, tvb, offset, 32, "ELAN name: %s",
359                         tvb_bytes_to_str(tvb, offset, 32));
360     offset += 32;
361
362     while (num_tlvs != 0) {
363       tlv_type = tvb_get_ntohl(tvb, offset);
364       tlv_length = tvb_get_guint8(tvb, offset+4);
365       ttlv = proto_tree_add_text(lane_tree, tvb, offset, 5+tlv_length, "TLV type: %s",
366         val_to_str(tlv_type, le_tlv_type_vals, "Unknown (0x%08x)"));
367       tlv_tree = proto_item_add_subtree(ttlv, ett_atm_lane_lc_tlv);
368       proto_tree_add_text(tlv_tree, tvb, offset, 4, "TLV Type: %s",
369         val_to_str(tlv_type, le_tlv_type_vals, "Unknown (0x%08x)"));
370       proto_tree_add_text(tlv_tree, tvb, offset+4, 1, "TLV Length: %u", tlv_length);
371       offset += 5+tlv_length;
372       num_tlvs--;
373     }
374   }
375 }
376
377 static void
378 dissect_lane(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
379 {
380   tvbuff_t      *next_tvb;
381   tvbuff_t      *next_tvb_le_client;
382
383   if (check_col(pinfo->fd, COL_PROTOCOL))
384     col_set_str(pinfo->fd, COL_PROTOCOL, "ATM LANE");
385   if (check_col(pinfo->fd, COL_INFO))
386     col_set_str(pinfo->fd, COL_INFO, "ATM LANE");
387
388   /* Is it LE Control, 802.3, 802.5, or "none of the above"? */
389   switch (pinfo->pseudo_header->ngsniffer_atm.AppHLType) {
390
391   case AHLT_LANE_LE_CTRL:
392     dissect_le_control(tvb, pinfo, tree);
393     break;
394
395   case AHLT_LANE_802_3:
396   case AHLT_LANE_802_3_MC:
397     dissect_le_client(tvb, pinfo, tree);
398
399     /* Dissect as Ethernet */
400     next_tvb_le_client  = tvb_new_subset(tvb, 2, -1, -1);
401     call_dissector(eth_handle, next_tvb_le_client, pinfo, tree);
402     break;
403
404   case AHLT_LANE_802_5:
405   case AHLT_LANE_802_5_MC:
406     dissect_le_client(tvb, pinfo, tree);
407
408     /* Dissect as Token-Ring */
409     next_tvb_le_client  = tvb_new_subset(tvb, 2, -1, -1);
410     call_dissector(tr_handle, next_tvb_le_client, pinfo, tree);
411     break;
412
413   default:
414     /* Dump it as raw data. */
415     next_tvb            = tvb_new_subset(tvb, 0, -1, -1);
416     dissect_data(next_tvb, 0, pinfo, tree);
417     break;
418   }
419 }
420
421 static void
422 dissect_ilmi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
423 {
424   dissect_snmp_pdu(tvb, 0, pinfo, tree, "ILMI", proto_ilmi, ett_ilmi);
425 }
426
427 /* AAL types */
428 static const value_string aal_vals[] = {
429         { ATT_AAL_UNKNOWN,    "Unknown AAL" },
430         { ATT_AAL1,           "AAL1" },
431         { ATT_AAL3_4,         "AAL3/4" },
432         { ATT_AAL5,           "AAL5" },
433         { ATT_AAL_USER,       "User AAL" },
434         { ATT_AAL_SIGNALLING, "Signalling AAL" },
435         { ATT_OAMCELL,        "OAM cell" },
436         { 0,                  NULL }
437 };
438
439 /* AAL5 higher-level traffic types */
440 static const value_string aal5_hltype_vals[] = {
441         { ATT_HL_UNKNOWN, "Unknown traffic type" },
442         { ATT_HL_LLCMX,   "LLC multiplexed" },
443         { ATT_HL_VCMX,    "VC multiplexed" },
444         { ATT_HL_LANE,    "LANE" },
445         { ATT_HL_ILMI,    "ILMI" },
446         { ATT_HL_FRMR,    "Frame Relay" },
447         { ATT_HL_SPANS,   "FORE SPANS" },
448         { ATT_HL_IPSILON, "Ipsilon" },
449         { 0,              NULL }
450 };
451
452 /* Traffic subtypes for VC multiplexed traffic */
453 static const value_string vcmx_type_vals[] = {
454         { AHLT_UNKNOWN,        "Unknown VC multiplexed traffic type" },
455         { AHLT_VCMX_802_3_FCS, "802.3 FCS" },
456         { AHLT_VCMX_802_4_FCS, "802.4 FCS" },
457         { AHLT_VCMX_802_5_FCS, "802.5 FCS" },
458         { AHLT_VCMX_FDDI_FCS,  "FDDI FCS" },
459         { AHLT_VCMX_802_6_FCS, "802.6 FCS" },
460         { AHLT_VCMX_802_3,     "802.3" },
461         { AHLT_VCMX_802_4,     "802.4" },
462         { AHLT_VCMX_802_5,     "802.5" },
463         { AHLT_VCMX_FDDI,      "FDDI" },
464         { AHLT_VCMX_802_6,     "802.6" },
465         { AHLT_VCMX_FRAGMENTS, "Fragments" },
466         { AHLT_VCMX_BPDU,      "BPDU" },
467         { 0,                   NULL }
468 };
469
470 /* Traffic subtypes for LANE traffic */
471 static const value_string lane_type_vals[] = {
472         { AHLT_UNKNOWN,       "Unknown LANE traffic type" },
473         { AHLT_LANE_LE_CTRL,  "LE Control" },
474         { AHLT_LANE_802_3,    "802.3" },
475         { AHLT_LANE_802_5,    "802.5" },
476         { AHLT_LANE_802_3_MC, "802.3 multicast" },
477         { AHLT_LANE_802_5_MC, "802.5 multicast" },
478         { 0,                  NULL }
479 };
480
481 /* Traffic subtypes for Ipsilon traffic */
482 static const value_string ipsilon_type_vals[] = {
483         { AHLT_UNKNOWN,     "Unknown Ipsilon traffic type" },
484         { AHLT_IPSILON_FT0, "Flow type 0" },
485         { AHLT_IPSILON_FT1, "Flow type 1" },
486         { AHLT_IPSILON_FT2, "Flow type 2" },
487         { 0,                NULL }
488 };
489
490 /*
491  * We don't know what kind of traffic this is; try to guess.
492  * We at least know it's AAL5....
493  */
494 static void
495 atm_guess_content(tvbuff_t *tvb, packet_info *pinfo)
496 {
497         guint8 byte0, byte1, byte2;
498
499         if (pinfo->pseudo_header->ngsniffer_atm.Vpi == 0) {
500                 /*
501                  * Traffic on some PVCs with a VPI of 0 and certain
502                  * VCIs is of particular types.
503                  */
504                 switch (pinfo->pseudo_header->ngsniffer_atm.Vci) {
505
506                 case 5:
507                         /*
508                          * Signalling AAL.
509                          */
510                         pinfo->pseudo_header->ngsniffer_atm.AppTrafType =
511                             ATT_AAL_SIGNALLING;
512                         return;
513
514                 case 16:
515                         /*
516                          * ILMI.
517                          */
518                         pinfo->pseudo_header->ngsniffer_atm.AppTrafType |=
519                             ATT_HL_ILMI;
520                         return;
521                 }
522         }
523
524         /*
525          * OK, we can't tell what it is based on the VPI/VCI; try
526          * guessing based on the contents.
527          */
528         byte0 = tvb_get_guint8(tvb, 0);
529         byte1 = tvb_get_guint8(tvb, 1);
530         byte2 = tvb_get_guint8(tvb, 2);
531         if (byte0 == 0xaa && byte1 == 0xaa && byte2 == 0x03) {
532                 /*
533                  * Looks like a SNAP header; assume it's LLC multiplexed
534                  * RFC 1483 traffic.
535                  */
536                 pinfo->pseudo_header->ngsniffer_atm.AppTrafType |= ATT_HL_LLCMX;
537         } else {
538                 /*
539                  * Assume it's LANE.
540                  */
541                 pinfo->pseudo_header->ngsniffer_atm.AppTrafType |= ATT_HL_LANE;
542                 if (byte0 == 0xff && byte1 == 0x00) {
543                         /*
544                          * Looks like LE Control traffic.
545                          */
546                         pinfo->pseudo_header->ngsniffer_atm.AppHLType =
547                             AHLT_LANE_LE_CTRL;
548                 } else {
549                         /*
550                          * XXX - Ethernet, or Token Ring?
551                          * Assume Ethernet for now; if we see earlier
552                          * LANE traffic, we may be able to figure out
553                          * the traffic type from that, but there may
554                          * still be situations where the user has to
555                          * tell us.
556                          */
557                         pinfo->pseudo_header->ngsniffer_atm.AppHLType =
558                             AHLT_LANE_802_3;
559                 }
560         }
561 }
562
563 static void
564 dissect_atm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
565 {
566   proto_tree   *atm_tree;
567   proto_item   *ti;
568   guint         aal_type;
569   guint         hl_type;
570
571   aal_type = pinfo->pseudo_header->ngsniffer_atm.AppTrafType & ATT_AALTYPE;
572   hl_type = pinfo->pseudo_header->ngsniffer_atm.AppTrafType & ATT_HLTYPE;
573   if (aal_type == ATT_AAL5) {
574     if (hl_type == ATT_HL_UNKNOWN ||
575         pinfo->pseudo_header->ngsniffer_atm.AppHLType == AHLT_UNKNOWN) {
576       /*
577        * The joys of a connection-oriented link layer; the type of
578        * traffic may be implied by the connection on which it's
579        * traveling, rather than being specified in the packet itself.
580        *
581        * For this packet, the program that captured the packet didn't
582        * save the type of traffic, presumably because it didn't know
583        * the traffic type (either it didn't see the connection setup
584        * and wasn't running on one of the endpoints, and wasn't later
585        * told, e.g. by the human running it, what type of traffic was
586        * on that circuit, or was running on one of the endpoints but
587        * was using, to capture the packets, a mechanism that either
588        * doesn't have access to data saying what's going over the
589        * connection or doesn't bother providing that information).
590        *
591        * For now, we try to guess the traffic type based on the VPI/VCI
592        * or the packet header; later, we should provide a mechanism
593        * by which the user can specify what sort of traffic is on a
594        * particular circuit.
595        */
596       atm_guess_content(tvb, pinfo);
597
598       /*
599        * OK, now get the AAL type and high-layer type again.
600        */
601       aal_type = pinfo->pseudo_header->ngsniffer_atm.AppTrafType & ATT_AALTYPE;
602       hl_type = pinfo->pseudo_header->ngsniffer_atm.AppTrafType & ATT_HLTYPE;
603     }
604   }
605
606   if (check_col(pinfo->fd, COL_PROTOCOL))
607     col_set_str(pinfo->fd, COL_PROTOCOL, "ATM");
608
609   switch (pinfo->pseudo_header->ngsniffer_atm.channel) {
610
611   case 0:
612     /* Traffic from DCE to DTE. */
613     if (check_col(pinfo->fd, COL_RES_DL_DST))
614       col_set_str(pinfo->fd, COL_RES_DL_DST, "DTE");
615     if (check_col(pinfo->fd, COL_RES_DL_SRC))
616       col_set_str(pinfo->fd, COL_RES_DL_SRC, "DCE");
617     break;
618
619   case 1:
620     /* Traffic from DTE to DCE. */
621     if (check_col(pinfo->fd, COL_RES_DL_DST))
622       col_set_str(pinfo->fd, COL_RES_DL_DST, "DCE");
623     if (check_col(pinfo->fd, COL_RES_DL_SRC))
624       col_set_str(pinfo->fd, COL_RES_DL_SRC, "DTE");
625     break;
626   }
627
628   if (check_col(pinfo->fd, COL_INFO)) {
629     if (aal_type == ATT_AAL5) {
630       col_add_fstr(pinfo->fd, COL_INFO, "AAL5 %s",
631                 val_to_str(hl_type, aal5_hltype_vals,
632                                 "Unknown traffic type (%x)"));
633     } else {
634       col_add_str(pinfo->fd, COL_INFO,
635                 val_to_str(aal_type, aal_vals, "Unknown AAL (%x)"));
636     }
637   }
638
639   if (tree) {
640     ti = proto_tree_add_protocol_format(tree, proto_atm, tvb, 0, 0, "ATM");
641     atm_tree = proto_item_add_subtree(ti, ett_atm);
642
643     proto_tree_add_text(atm_tree, tvb, 0, 0, "AAL: %s",
644         val_to_str(aal_type, aal_vals, "Unknown AAL (%x)"));
645     if (aal_type == ATT_AAL5) {
646       proto_tree_add_text(atm_tree, tvb, 0, 0, "Traffic type: %s",
647         val_to_str(hl_type, aal5_hltype_vals, "Unknown AAL5 traffic type (%x)"));
648       switch (hl_type) {
649
650       case ATT_HL_LLCMX:
651         proto_tree_add_text(atm_tree, tvb, 0, 0, "LLC multiplexed traffic");
652         break;
653
654       case ATT_HL_VCMX:
655         proto_tree_add_text(atm_tree, tvb, 0, 0, "VC multiplexed traffic type: %s",
656                 val_to_str(pinfo->pseudo_header->ngsniffer_atm.AppHLType,
657                         vcmx_type_vals, "Unknown VCMX traffic type (%x)"));
658         break;
659
660       case ATT_HL_LANE:
661         proto_tree_add_text(atm_tree, tvb, 0, 0, "LANE traffic type: %s",
662                 val_to_str(pinfo->pseudo_header->ngsniffer_atm.AppHLType,
663                         lane_type_vals, "Unknown LANE traffic type (%x)"));
664         break;
665
666       case ATT_HL_IPSILON:
667         proto_tree_add_text(atm_tree, tvb, 0, 0, "Ipsilon traffic type: %s",
668                 val_to_str(pinfo->pseudo_header->ngsniffer_atm.AppHLType,
669                         ipsilon_type_vals, "Unknown Ipsilon traffic type (%x)"));
670         break;
671       }
672     }
673     proto_tree_add_uint(atm_tree, hf_atm_vpi, tvb, 0, 0,
674                 pinfo->pseudo_header->ngsniffer_atm.Vpi);
675     proto_tree_add_uint(atm_tree, hf_atm_vci, tvb, 0, 0,
676                 pinfo->pseudo_header->ngsniffer_atm.Vci);
677     switch (pinfo->pseudo_header->ngsniffer_atm.channel) {
678
679     case 0:
680       /* Traffic from DCE to DTE. */
681       proto_tree_add_text(atm_tree, tvb, 0, 0, "Channel: DCE->DTE");
682       break;
683
684     case 1:
685       /* Traffic from DTE to DCE. */
686       proto_tree_add_text(atm_tree, tvb, 0, 0, "Channel: DTE->DCE");
687       break;
688
689     default:
690       /* Sniffers shouldn't provide anything other than 0 or 1. */
691       proto_tree_add_text(atm_tree, tvb, 0, 0, "Channel: %u",
692                 pinfo->pseudo_header->ngsniffer_atm.channel);
693       break;
694     }
695     if (pinfo->pseudo_header->ngsniffer_atm.cells != 0) {
696       /*
697        * If the cell count is 0, assume it means we don't know how
698        * many cells it was.
699        *
700        * XXX - also, if this is AAL5 traffic, assume it means we don't
701        * know what was in the AAL5 trailer.  We may, however, find
702        * some capture program that can give us the AAL5 trailer
703        * information but not the cell count, in which case we need
704        * some other way of indicating whether we have the AAL5 trailer
705        * information.
706        */
707       proto_tree_add_text(atm_tree, tvb, 0, 0, "Cells: %u",
708                 pinfo->pseudo_header->ngsniffer_atm.cells);
709       if (aal_type == ATT_AAL5) {
710         proto_tree_add_text(atm_tree, tvb, 0, 0, "AAL5 U2U: %u",
711                 pinfo->pseudo_header->ngsniffer_atm.aal5t_u2u);
712         proto_tree_add_text(atm_tree, tvb, 0, 0, "AAL5 len: %u",
713                 pinfo->pseudo_header->ngsniffer_atm.aal5t_len);
714         proto_tree_add_text(atm_tree, tvb, 0, 0, "AAL5 checksum: 0x%08X",
715                 pinfo->pseudo_header->ngsniffer_atm.aal5t_chksum);
716       }
717     }
718   }
719
720   switch (aal_type) {
721
722   case ATT_AAL_SIGNALLING:
723     call_dissector(sscop_handle, tvb, pinfo, tree);
724     break;
725
726   case ATT_AAL5:
727     switch (hl_type) {
728
729     case ATT_HL_LLCMX:
730       /* Dissect as WTAP_ENCAP_ATM_RFC1483 */
731       /* The ATM iptrace capture that we have shows LLC at this point,
732        * so that's what I'm calling */
733       call_dissector(llc_handle, tvb, pinfo, tree);
734       break;
735
736     case ATT_HL_LANE:
737       call_dissector(lane_handle, tvb, pinfo, tree);
738       break;
739
740     case ATT_HL_ILMI:
741       call_dissector(ilmi_handle, tvb, pinfo, tree);
742       break;
743
744     default:
745       if (tree) {
746         /* Dump it as raw data. */
747         dissect_data(tvb, 0, pinfo, tree);
748         break;
749       }
750     }
751     break;
752
753   default:
754     if (tree) {
755       /* Dump it as raw data.  (Is this a single cell?) */
756       dissect_data(tvb, 0, pinfo, tree);
757     }
758     break;
759   }
760 }
761
762 void
763 proto_register_atm(void)
764 {
765         static hf_register_info hf[] = {
766                 { &hf_atm_vpi,
767                 { "VPI",                "atm.vpi", FT_UINT8, BASE_DEC, NULL, 0x0,
768                         "" }},
769
770                 { &hf_atm_vci,
771                 { "VCI",                "atm.vci", FT_UINT16, BASE_DEC, NULL, 0x0,
772                         "" }},
773         };
774         static gint *ett[] = {
775                 &ett_atm,
776                 &ett_ilmi,
777                 &ett_atm_lane,
778                 &ett_atm_lane_lc_lan_dest,
779                 &ett_atm_lane_lc_lan_dest_rd,
780                 &ett_atm_lane_lc_flags,
781                 &ett_atm_lane_lc_tlv,
782         };
783         proto_atm = proto_register_protocol("ATM", "ATM", "atm");
784         proto_register_field_array(proto_atm, hf, array_length(hf));
785         proto_register_subtree_array(ett, array_length(ett));
786
787         proto_ilmi = proto_register_protocol("ILMI", "ILMI", "ilmi");
788
789         register_dissector("ilmi", dissect_ilmi, proto_ilmi);
790
791         proto_atm_lane = proto_register_protocol("ATM LAN Emulation",
792             "ATM LANE", "lane");
793
794         register_dissector("lane", dissect_lane, proto_atm_lane);
795 }
796
797 void
798 proto_reg_handoff_atm(void)
799 {
800         /*
801          * Get handles for the Ethernet, Token Ring, LLC, SSCOP, LANE,
802          * and ILMI dissectors.
803          */
804         eth_handle = find_dissector("eth");
805         tr_handle = find_dissector("tr");
806         llc_handle = find_dissector("llc");
807         sscop_handle = find_dissector("sscop");
808         lane_handle = find_dissector("lane");
809         ilmi_handle = find_dissector("ilmi");
810
811         dissector_add("wtap_encap", WTAP_ENCAP_ATM_SNIFFER, dissect_atm,
812             proto_atm);
813 }