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