Add wtap-int.h. Move definitions relevant to the internal workins of wiretap
[metze/wireshark/wip.git] / packet-atm.c
1 /* packet-atm.c
2  * Routines for ATM packet disassembly
3  *
4  * $Id: packet-atm.c,v 1.20 2000/05/19 23:06:08 gram 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(const u_char *pd, int offset, frame_data *fd, 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, NullTVB, offset, 2, "ATM LANE");
158     lane_tree = proto_item_add_subtree(ti, ett_atm_lane);
159
160     proto_tree_add_text(lane_tree, NullTVB, offset, 2, "LE Client: 0x%04X",
161                         pntohs(&pd[offset]));
162   }
163 }
164
165 static void
166 dissect_lan_destination(const u_char *pd, 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, NullTVB, offset, 8, "%s LAN destination",
176                         type);
177   dest_tree = proto_item_add_subtree(td, ett_atm_lane_lc_lan_dest);
178   tag = pntohs(&pd[offset]);
179   proto_tree_add_text(dest_tree, NullTVB, 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, NullTVB, offset, 6, "MAC address: %s",
188                         ether_to_str((u_char *)&pd[offset]));
189     break;
190
191   case TAG_ROUTE_DESCRIPTOR:
192     offset += 4;
193     route_descriptor = pntohs(&pd[offset]);
194     trd = proto_tree_add_text(dest_tree, NullTVB, 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, NullTVB, offset, 2,
198             decode_numeric_bitfield(route_descriptor, 0xFFF0, 2*8,
199                         "LAN ID = %u"));
200     proto_tree_add_text(rd_tree, NullTVB, 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(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) 
249 {
250   proto_item *ti;
251   proto_tree *lane_tree;
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(fd, COL_INFO))
263     col_add_str(fd, COL_INFO, "LE Control");
264
265   if (tree) {
266     ti = proto_tree_add_protocol_format(tree, proto_atm_lane, NullTVB, offset, 108, "ATM LANE");
267     lane_tree = proto_item_add_subtree(ti, ett_atm_lane);
268
269     proto_tree_add_text(lane_tree, NullTVB, offset, 2, "Marker: 0x%04X",
270                         pntohs(&pd[offset]));
271     offset += 2;
272
273     proto_tree_add_text(lane_tree, NullTVB, offset, 1, "Protocol: 0x%02X",
274                         pd[offset]);
275     offset += 1;
276
277     proto_tree_add_text(lane_tree, NullTVB, offset, 1, "Version: 0x%02X",
278                         pd[offset]);
279     offset += 1;
280
281     opcode = pntohs(&pd[offset]);
282     proto_tree_add_text(lane_tree, NullTVB, 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, NullTVB, offset, 2, "Status: %s",
295         val_to_str(pntohs(&pd[offset]), le_control_status_vals,
296                                 "Unknown (0x%04X)"));
297     }
298     offset += 2;
299
300     proto_tree_add_text(lane_tree, NullTVB, offset, 4, "Transaction ID: 0x%08X",
301                         pntohl(&pd[offset]));
302     offset += 4;
303
304     proto_tree_add_text(lane_tree, NullTVB, offset, 2, "Requester LECID: 0x%04X",
305                         pntohs(&pd[offset]));
306     offset += 2;
307
308     flags = pntohs(&pd[offset]);
309     tf = proto_tree_add_text(lane_tree, NullTVB, offset, 2, "Flags: 0x%04X",
310                         pntohs(&pd[offset]));
311     flags_tree = proto_item_add_subtree(tf, ett_atm_lane_lc_flags);
312     proto_tree_add_text(flags_tree, NullTVB, offset, 2, "%s",
313         decode_boolean_bitfield(flags, 0x0001, 8*2,
314                                 "Remote address", "Local address"));
315     proto_tree_add_text(flags_tree, NullTVB, offset, 2, "%s",
316         decode_boolean_bitfield(flags, 0x0080, 8*2,
317                                 "Proxy", "Not proxy"));
318     proto_tree_add_text(flags_tree, NullTVB, 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(pd, offset, "Source", lane_tree);
324     offset += 8;
325
326     dissect_lan_destination(pd, offset, "Target", lane_tree);
327     offset += 8;
328
329     proto_tree_add_text(lane_tree, NullTVB, offset, 20, "Source ATM Address: %s",
330                         bytes_to_str(&pd[offset], 20));
331     offset += 20;
332
333     proto_tree_add_text(lane_tree, NullTVB, offset, 1, "LAN type: %s",
334         val_to_str(pd[offset], le_control_lan_type_vals,
335                                 "Unknown (0x%02X)"));
336     offset += 1;
337
338     proto_tree_add_text(lane_tree, NullTVB, offset, 1, "Maximum frame size: %u",
339                         pd[offset]);
340     offset += 1;
341
342     num_tlvs = pd[offset];
343     proto_tree_add_text(lane_tree, NullTVB, offset, 1, "Number of TLVs: %u",
344                         num_tlvs);
345     offset += 1;
346
347     proto_tree_add_text(lane_tree, NullTVB, offset, 1, "ELAN name size: %u",
348                         pd[offset]);
349     offset += 1;
350
351     proto_tree_add_text(lane_tree, NullTVB, offset, 20, "Target ATM Address: %s",
352                         bytes_to_str(&pd[offset], 20));
353     offset += 20;
354
355     proto_tree_add_text(lane_tree, NullTVB, offset, 32, "ELAN name: %s",
356                         bytes_to_str(&pd[offset], 32));
357     offset += 32;
358
359     while (num_tlvs != 0) {
360       tlv_type = pntohl(&pd[offset]);
361       tlv_length = pd[offset+4];
362       ttlv = proto_tree_add_text(lane_tree, NullTVB, 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, NullTVB, 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, NullTVB, 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(const union wtap_pseudo_header *pseudo_header, const u_char *pd,
376                 int offset, frame_data *fd, proto_tree *tree) 
377 {
378   tvbuff_t      *next_tvb;
379   tvbuff_t      *next_tvb_le_client;
380
381
382   if (check_col(fd, COL_PROTOCOL))
383     col_add_str(fd, COL_PROTOCOL, "ATM LANE");
384   if (check_col(fd, COL_INFO))
385     col_add_str(fd, COL_INFO, "ATM LANE");
386
387   /* Is it LE Control, 802.3, 802.5, or "none of the above"? */
388   switch (pseudo_header->ngsniffer_atm.AppHLType) {
389
390   case AHLT_LANE_LE_CTRL:
391     dissect_le_control(pd, offset, fd, tree);
392     break;
393
394   case AHLT_LANE_802_3:
395   case AHLT_LANE_802_3_MC:
396     dissect_le_client(pd, offset, fd, tree);
397
398     /* Dissect as Ethernet */
399     next_tvb_le_client  = tvb_new_subset(pi.compat_top_tvb, offset+2, -1, -1);
400     dissect_eth(next_tvb_le_client, &pi, tree);
401     break;
402
403   case AHLT_LANE_802_5:
404   case AHLT_LANE_802_5_MC:
405     dissect_le_client(pd, offset, fd, tree);
406
407     /* Dissect as Token-Ring */
408     next_tvb_le_client  = tvb_new_subset(pi.compat_top_tvb, offset+2, -1, -1);
409     dissect_tr(next_tvb_le_client, &pi, tree);
410     break;
411
412   default:
413     /* Dump it as raw data. */
414     next_tvb            = tvb_new_subset(pi.compat_top_tvb, offset,   -1, -1);
415     dissect_data_tvb(next_tvb, &pi, tree);
416     break;
417   }
418 }
419
420 /* AAL types */
421 static const value_string aal_vals[] = {
422         { ATT_AAL_UNKNOWN,    "Unknown AAL" },
423         { ATT_AAL1,           "AAL1" },
424         { ATT_AAL3_4,         "AAL3/4" },
425         { ATT_AAL5,           "AAL5" },
426         { ATT_AAL_USER,       "User AAL" },
427         { ATT_AAL_SIGNALLING, "Signalling AAL" },
428         { ATT_OAMCELL,        "OAM cell" },
429         { 0,                  NULL }
430 };
431
432 /* AAL5 higher-level traffic types */
433 static const value_string aal5_hltype_vals[] = {
434         { ATT_HL_UNKNOWN, "Unknown traffic type" },
435         { ATT_HL_LLCMX,   "LLC multiplexed" },
436         { ATT_HL_VCMX,    "VC multiplexed" },
437         { ATT_HL_LANE,    "LANE" },
438         { ATT_HL_ILMI,    "ILMI" },
439         { ATT_HL_FRMR,    "Frame Relay" },
440         { ATT_HL_SPANS,   "FORE SPANS" },
441         { ATT_HL_IPSILON, "Ipsilon" },
442         { 0,              NULL }
443 };
444
445 /* Traffic subtypes for VC multiplexed traffic */
446 static const value_string vcmx_type_vals[] = {
447         { AHLT_UNKNOWN,        "Unknown VC multiplexed traffic type" },
448         { AHLT_VCMX_802_3_FCS, "802.3 FCS" },
449         { AHLT_VCMX_802_4_FCS, "802.4 FCS" },
450         { AHLT_VCMX_802_5_FCS, "802.5 FCS" },
451         { AHLT_VCMX_FDDI_FCS,  "FDDI FCS" },
452         { AHLT_VCMX_802_6_FCS, "802.6 FCS" },
453         { AHLT_VCMX_802_3,     "802.3" },
454         { AHLT_VCMX_802_4,     "802.4" },
455         { AHLT_VCMX_802_5,     "802.5" },
456         { AHLT_VCMX_FDDI,      "FDDI" },
457         { AHLT_VCMX_802_6,     "802.6" },
458         { AHLT_VCMX_FRAGMENTS, "Fragments" },
459         { AHLT_VCMX_BPDU,      "BPDU" },
460         { 0,                   NULL }
461 };
462
463 /* Traffic subtypes for LANE traffic */
464 static const value_string lane_type_vals[] = {
465         { AHLT_UNKNOWN,       "Unknown LANE traffic type" },
466         { AHLT_LANE_LE_CTRL,  "LE Control" },
467         { AHLT_LANE_802_3,    "802.3" },
468         { AHLT_LANE_802_5,    "802.5" },
469         { AHLT_LANE_802_3_MC, "802.3 multicast" },
470         { AHLT_LANE_802_5_MC, "802.5 multicast" },
471         { 0,                  NULL }
472 };
473
474 /* Traffic subtypes for Ipsilon traffic */
475 static const value_string ipsilon_type_vals[] = {
476         { AHLT_UNKNOWN,     "Unknown Ipsilon traffic type" },
477         { AHLT_IPSILON_FT0, "Flow type 0" },
478         { AHLT_IPSILON_FT1, "Flow type 1" },
479         { AHLT_IPSILON_FT2, "Flow type 2" },
480         { 0,                NULL }
481 };
482
483 /*
484  * We don't know what kind of traffic this is; try to guess.
485  * We at least know it's AAL5....
486  */
487 static void
488 atm_guess_content(union wtap_pseudo_header *pseudo_header, const u_char *pd,
489     frame_data *fd)
490 {
491         if (pseudo_header->ngsniffer_atm.Vpi == 0) {
492                 /*
493                  * Traffic on some PVCs with a VPI of 0 and certain
494                  * VCIs is of particular types.
495                  */
496                 switch (pseudo_header->ngsniffer_atm.Vci) {
497
498                 case 5:
499                         /*
500                          * Signalling AAL.
501                          */
502                         pseudo_header->ngsniffer_atm.AppTrafType =
503                             ATT_AAL_SIGNALLING;
504                         return;
505
506                 case 16:
507                         /*
508                          * ILMI.
509                          */
510                         pseudo_header->ngsniffer_atm.AppTrafType |=
511                             ATT_HL_ILMI;
512                         return;
513                 }
514         }
515
516         /*
517          * OK, we can't tell what it is based on the VPI/VCI; try
518          * guessing based on the contents.
519          */
520         if (pd[0] == 0xaa && pd[1] == 0xaa && pd[2] == 0x03) {
521                 /*
522                  * Looks like a SNAP header; assume it's LLC multiplexed
523                  * RFC 1483 traffic.
524                  */
525                 pseudo_header->ngsniffer_atm.AppTrafType |= ATT_HL_LLCMX;
526         } else {
527                 /*
528                  * Assume it's LANE.
529                  */
530                 pseudo_header->ngsniffer_atm.AppTrafType |= ATT_HL_LANE;
531                 if (pd[0] == 0xff && pd[1] == 0x00) {
532                         /*
533                          * Looks like LE Control traffic.
534                          */
535                         pseudo_header->ngsniffer_atm.AppHLType =
536                             AHLT_LANE_LE_CTRL;
537                 } else {
538                         /*
539                          * XXX - Ethernet, or Token Ring?
540                          * Assume Ethernet for now; if we see earlier
541                          * LANE traffic, we may be able to figure out
542                          * the traffic type from that, but there may
543                          * still be situations where the user has to
544                          * tell us.
545                          */
546                         pseudo_header->ngsniffer_atm.AppHLType =
547                             AHLT_LANE_802_3;
548                 }
549         }
550 }
551
552 void
553 dissect_atm(union wtap_pseudo_header *pseudo_header, const u_char *pd,
554                 frame_data *fd, proto_tree *tree) 
555 {
556   int        offset = 0;
557   proto_tree *atm_tree;
558   proto_item *ti;
559   guint       aal_type;
560   guint       hl_type;
561   tvbuff_t*   next_tvb;
562
563   aal_type = pseudo_header->ngsniffer_atm.AppTrafType & ATT_AALTYPE;
564   hl_type = pseudo_header->ngsniffer_atm.AppTrafType & ATT_HLTYPE;
565   if (aal_type == ATT_AAL5) {
566     if (hl_type == ATT_HL_UNKNOWN ||
567         pseudo_header->ngsniffer_atm.AppHLType == AHLT_UNKNOWN) {
568       /*
569        * The joys of a connection-oriented link layer; the type of
570        * traffic may be implied by the connection on which it's
571        * traveling, rather than being specified in the packet itself.
572        *
573        * For this packet, the program that captured the packet didn't
574        * save the type of traffic, presumably because it didn't know
575        * the traffic type (either it didn't see the connection setup
576        * and wasn't running on one of the endpoints, and wasn't later
577        * told, e.g. by the human running it, what type of traffic was
578        * on that circuit, or was running on one of the endpoints but
579        * was using, to capture the packets, a mechanism that either
580        * doesn't have access to data saying what's going over the
581        * connection or doesn't bother providing that information).
582        *
583        * For now, we try to guess the traffic type based on the VPI/VCI
584        * or the packet header; later, we should provide a mechanism
585        * by which the user can specify what sort of traffic is on a
586        * particular circuit.
587        */
588       atm_guess_content(pseudo_header, pd, fd);
589
590       /*
591        * OK, now get the AAL type and high-layer type again.
592        */
593       aal_type = pseudo_header->ngsniffer_atm.AppTrafType & ATT_AALTYPE;
594       hl_type = pseudo_header->ngsniffer_atm.AppTrafType & ATT_HLTYPE;
595     }
596   }
597
598   if (check_col(fd, COL_PROTOCOL))
599     col_add_str(fd, COL_PROTOCOL, "ATM");
600
601   switch (pseudo_header->ngsniffer_atm.channel) {
602
603   case 0:
604     /* Traffic from DCE to DTE. */
605     if (check_col(fd, COL_RES_DL_DST))
606       col_add_str(fd, COL_RES_DL_DST, "DTE");
607     if (check_col(fd, COL_RES_DL_SRC))
608       col_add_str(fd, COL_RES_DL_SRC, "DCE");
609     break;
610
611   case 1:
612     /* Traffic from DTE to DCE. */
613     if (check_col(fd, COL_RES_DL_DST))
614       col_add_str(fd, COL_RES_DL_DST, "DCE");
615     if (check_col(fd, COL_RES_DL_SRC))
616       col_add_str(fd, COL_RES_DL_SRC, "DTE");
617     break;
618   }
619
620   if (check_col(fd, COL_INFO)) {
621     if (aal_type == ATT_AAL5) {
622       col_add_fstr(fd, COL_INFO, "AAL5 %s",
623                 val_to_str(hl_type, aal5_hltype_vals,
624                                 "Unknown traffic type (%x)"));
625     } else {
626       col_add_str(fd, COL_INFO,
627                 val_to_str(aal_type, aal_vals, "Unknown AAL (%x)"));
628     }
629   }
630
631   if (tree) {
632     ti = proto_tree_add_protocol_format(tree, proto_atm, NullTVB, 0, 0, "ATM");
633     atm_tree = proto_item_add_subtree(ti, ett_atm);
634
635     proto_tree_add_text(atm_tree, NullTVB, 0, 0, "AAL: %s",
636         val_to_str(aal_type, aal_vals, "Unknown AAL (%x)"));
637     if (aal_type == ATT_AAL5) {
638       proto_tree_add_text(atm_tree, NullTVB, 0, 0, "Traffic type: %s",
639         val_to_str(hl_type, aal5_hltype_vals, "Unknown AAL5 traffic type (%x)"));
640       switch (hl_type) {
641
642       case ATT_HL_LLCMX:
643         proto_tree_add_text(atm_tree, NullTVB, 0, 0, "LLC multiplexed traffic");
644         break;
645
646       case ATT_HL_VCMX:
647         proto_tree_add_text(atm_tree, NullTVB, 0, 0, "VC multiplexed traffic type: %s",
648                 val_to_str(pseudo_header->ngsniffer_atm.AppHLType,
649                         vcmx_type_vals, "Unknown VCMX traffic type (%x)"));
650         break;
651
652       case ATT_HL_LANE:
653         proto_tree_add_text(atm_tree, NullTVB, 0, 0, "LANE traffic type: %s",
654                 val_to_str(pseudo_header->ngsniffer_atm.AppHLType,
655                         lane_type_vals, "Unknown LANE traffic type (%x)"));
656         break;
657
658       case ATT_HL_IPSILON:
659         proto_tree_add_text(atm_tree, NullTVB, 0, 0, "Ipsilon traffic type: %s",
660                 val_to_str(pseudo_header->ngsniffer_atm.AppHLType,
661                         ipsilon_type_vals, "Unknown Ipsilon traffic type (%x)"));
662         break;
663       }
664     }
665     proto_tree_add_item(atm_tree, hf_atm_vpi, NullTVB, 0, 0,
666                 pseudo_header->ngsniffer_atm.Vpi);
667     proto_tree_add_item(atm_tree, hf_atm_vci, NullTVB, 0, 0,
668                 pseudo_header->ngsniffer_atm.Vci);
669     switch (pseudo_header->ngsniffer_atm.channel) {
670
671     case 0:
672       /* Traffic from DCE to DTE. */
673       proto_tree_add_text(atm_tree, NullTVB, 0, 0, "Channel: DCE->DTE");
674       break;
675
676     case 1:
677       /* Traffic from DTE to DCE. */
678       proto_tree_add_text(atm_tree, NullTVB, 0, 0, "Channel: DTE->DCE");
679       break;
680
681     default:
682       /* Sniffers shouldn't provide anything other than 0 or 1. */
683       proto_tree_add_text(atm_tree, NullTVB, 0, 0, "Channel: %u",
684                 pseudo_header->ngsniffer_atm.channel);
685       break;
686     }
687     if (pseudo_header->ngsniffer_atm.cells != 0) {
688       /*
689        * If the cell count is 0, assume it means we don't know how
690        * many cells it was.
691        *
692        * XXX - also, if this is AAL5 traffic, assume it means we don't
693        * know what was in the AAL5 trailer.  We may, however, find
694        * some capture program that can give us the AAL5 trailer
695        * information but not the cell count, in which case we need
696        * some other way of indicating whether we have the AAL5 trailer
697        * information.
698        */
699       proto_tree_add_text(atm_tree, NullTVB, 0, 0, "Cells: %u",
700                 pseudo_header->ngsniffer_atm.cells);
701       if (aal_type == ATT_AAL5) {
702         proto_tree_add_text(atm_tree, NullTVB, 0, 0, "AAL5 U2U: %u",
703                 pseudo_header->ngsniffer_atm.aal5t_u2u);
704         proto_tree_add_text(atm_tree, NullTVB, 0, 0, "AAL5 len: %u",
705                 pseudo_header->ngsniffer_atm.aal5t_len);
706         proto_tree_add_text(atm_tree, NullTVB, 0, 0, "AAL5 checksum: 0x%08X",
707                 pseudo_header->ngsniffer_atm.aal5t_chksum);
708       }
709     }
710   }
711
712   switch (aal_type) {
713
714   case ATT_AAL_SIGNALLING:
715     dissect_sscop(pd, offset, fd, tree);
716     break;
717
718   case ATT_AAL5:
719     switch (hl_type) {
720
721     case ATT_HL_LLCMX:
722       /* Dissect as WTAP_ENCAP_ATM_RFC1483 */
723       /* The ATM iptrace capture that we have hows LLC at this point,
724        * so that's what I'm calling */
725       next_tvb = tvb_new_subset(pi.compat_top_tvb, offset, -1, -1);
726       dissect_llc(next_tvb, &pi, tree);
727       break;
728
729     case ATT_HL_LANE:
730       dissect_lane(pseudo_header, pd, offset, fd, tree);
731       break;
732
733     case ATT_HL_ILMI:
734       dissect_snmp_pdu(pd, offset, fd, tree, "ILMI", proto_ilmi, ett_ilmi);
735       break;
736
737     default:
738       if (tree) {
739         /* Dump it as raw data. */
740         dissect_data(pd, offset, fd, tree);
741         break;
742       }
743     }
744     break;
745
746   default:
747     if (tree) {
748       /* Dump it as raw data.  (Is this a single cell?) */
749       dissect_data(pd, offset, fd, tree);
750     }
751     break;
752   }
753 }
754
755 void
756 proto_register_atm(void)
757 {
758         static hf_register_info hf[] = {
759                 { &hf_atm_vpi,
760                 { "VPI",                "atm.vpi", FT_UINT8, BASE_DEC, NULL, 0x0,
761                         "" }},
762
763                 { &hf_atm_vci,
764                 { "VCI",                "atm.vci", FT_UINT16, BASE_DEC, NULL, 0x0,
765                         "" }},
766         };
767         static gint *ett[] = {
768                 &ett_atm,
769                 &ett_ilmi,
770                 &ett_atm_lane,
771                 &ett_atm_lane_lc_lan_dest,
772                 &ett_atm_lane_lc_lan_dest_rd,
773                 &ett_atm_lane_lc_flags,
774                 &ett_atm_lane_lc_tlv,
775         };
776         proto_atm = proto_register_protocol("ATM", "atm");
777         proto_register_field_array(proto_atm, hf, array_length(hf));
778         proto_ilmi = proto_register_protocol("ILMI", "ilmi");
779         proto_atm_lane = proto_register_protocol("ATM LANE", "lane");
780         proto_register_subtree_array(ett, array_length(ett));
781 }