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