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