2 * Routines for ATM packet disassembly
4 * $Id: packet-atm.c,v 1.10 1999/12/05 02:32:41 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
39 #include "packet-snmp.h"
41 static int proto_atm = -1;
42 static int hf_atm_vpi = -1;
43 static int hf_atm_vci = -1;
44 static int proto_atm_lane = -1;
45 static int proto_ilmi = -1;
47 static gint ett_atm = -1;
48 static gint ett_atm_lane = -1;
49 static gint ett_atm_lane_lc_lan_dest = -1;
50 static gint ett_atm_lane_lc_lan_dest_rd = -1;
51 static gint ett_atm_lane_lc_flags = -1;
52 static gint ett_ilmi = -1;
57 * http://www.atmforum.org/atmforum/specs/approved.html
59 * for a number of ATM Forum specifications, e.g. the LAN Emulation
60 * over ATM 1.0 spec, whence I got most of this.
63 /* LE Control opcodes */
64 #define LE_CONFIGURE_REQUEST 0x0001
65 #define LE_CONFIGURE_RESPONSE 0x0101
66 #define LE_JOIN_REQUEST 0x0002
67 #define LE_JOIN_RESPONSE 0x0102
68 #define READY_QUERY 0x0003
69 #define READY_IND 0x0103
70 #define LE_REGISTER_REQUEST 0x0004
71 #define LE_REGISTER_RESPONSE 0x0104
72 #define LE_UNREGISTER_REQUEST 0x0005
73 #define LE_UNREGISTER_RESPONSE 0x0105
74 #define LE_ARP_REQUEST 0x0006
75 #define LE_ARP_RESPONSE 0x0106
76 #define LE_FLUSH_REQUEST 0x0007
77 #define LE_FLUSH_RESPONSE 0x0107
78 #define LE_NARP_REQUEST 0x0008
79 #define LE_TOPOLOGY_REQUEST 0x0009
81 static const value_string le_control_opcode_vals[] = {
82 { LE_CONFIGURE_REQUEST, "LE_CONFIGURE_REQUEST" },
83 { LE_CONFIGURE_RESPONSE, "LE_CONFIGURE_RESPONSE" },
84 { LE_JOIN_REQUEST, "LE_JOIN_REQUEST" },
85 { LE_JOIN_RESPONSE, "LE_JOIN_RESPONSE" },
86 { READY_QUERY, "READY_QUERY" },
87 { READY_IND, "READY_IND" },
88 { LE_REGISTER_REQUEST, "LE_REGISTER_REQUEST" },
89 { LE_REGISTER_RESPONSE, "LE_REGISTER_RESPONSE" },
90 { LE_UNREGISTER_REQUEST, "LE_UNREGISTER_REQUEST" },
91 { LE_UNREGISTER_RESPONSE, "LE_UNREGISTER_RESPONSE" },
92 { LE_ARP_REQUEST, "LE_ARP_REQUEST" },
93 { LE_ARP_RESPONSE, "LE_ARP_RESPONSE" },
94 { LE_FLUSH_REQUEST, "LE_FLUSH_REQUEST" },
95 { LE_FLUSH_RESPONSE, "LE_FLUSH_RESPONSE" },
96 { LE_NARP_REQUEST, "LE_NARP_REQUEST" },
97 { LE_TOPOLOGY_REQUEST, "LE_TOPOLOGY_REQUEST" },
101 /* LE Control statuses */
102 static const value_string le_control_status_vals[] = {
104 { 1, "Version not supported" },
105 { 2, "Invalid request parameters" },
106 { 4, "Duplicate LAN destination registration" },
107 { 5, "Duplicate ATM address" },
108 { 6, "Insufficient resources to grant request" },
109 { 7, "Access denied" },
110 { 8, "Invalid REQUESTOR-ID" },
111 { 9, "Invalid LAN destination" },
112 { 10, "Invalid ATM address" },
113 { 20, "No configuraton" },
114 { 21, "LE_CONFIGURE error" },
115 { 22, "Insufficient information" },
119 /* LE Control LAN destination tags */
120 #define TAG_NOT_PRESENT 0x0000
121 #define TAG_MAC_ADDRESS 0x0001
122 #define TAG_ROUTE_DESCRIPTOR 0x0002
124 static const value_string le_control_landest_tag_vals[] = {
125 { TAG_NOT_PRESENT, "Not present" },
126 { TAG_MAC_ADDRESS, "MAC address" },
127 { TAG_ROUTE_DESCRIPTOR, "Route descriptor" },
131 /* LE Control LAN types */
132 #define LANT_UNSPEC 0x00
133 #define LANT_802_3 0x01
134 #define LANT_802_5 0x02
136 static const value_string le_control_lan_type_vals[] = {
137 { LANT_UNSPEC, "Unspecified" },
138 { LANT_802_3, "Ethernet/802.3" },
139 { LANT_802_5, "802.5" },
144 dissect_le_client(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
147 proto_tree *lane_tree;
150 ti = proto_tree_add_item_format(tree, proto_atm_lane, offset, 2, NULL,
152 lane_tree = proto_item_add_subtree(ti, ett_atm_lane);
154 proto_tree_add_text(lane_tree, offset, 2, "LE Client: 0x%04X",
155 pntohs(&pd[offset]));
160 dissect_lan_destination(const u_char *pd, int offset, const char *type, proto_tree *tree)
163 proto_tree *dest_tree;
167 guint16 route_descriptor;
169 td = proto_tree_add_text(tree, offset, 8, "%s LAN destination",
171 dest_tree = proto_item_add_subtree(td, ett_atm_lane_lc_lan_dest);
172 tag = pntohs(&pd[offset]);
173 proto_tree_add_text(dest_tree, offset, 2, "Tag: %s",
174 val_to_str(tag, le_control_landest_tag_vals,
180 case TAG_MAC_ADDRESS:
181 proto_tree_add_text(dest_tree, offset, 6, "MAC address: %s",
182 ether_to_str((u_char *)&pd[offset]));
185 case TAG_ROUTE_DESCRIPTOR:
187 route_descriptor = pntohs(&pd[offset]);
188 trd = proto_tree_add_text(dest_tree, offset, 2, "Route descriptor: 0x%02X",
190 rd_tree = proto_item_add_subtree(td, ett_atm_lane_lc_lan_dest_rd);
191 proto_tree_add_text(rd_tree, offset, 2,
192 decode_numeric_bitfield(route_descriptor, 0xFFF0, 2*8,
194 proto_tree_add_text(rd_tree, offset, 2,
195 decode_numeric_bitfield(route_descriptor, 0x000F, 2*8,
196 "Bridge number = %u"));
202 dissect_le_control(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
205 proto_tree *lane_tree;
207 proto_tree *flags_tree;
211 if (check_col(fd, COL_INFO))
212 col_add_str(fd, COL_INFO, "LE Control");
215 ti = proto_tree_add_item_format(tree, proto_atm_lane, offset, 108, NULL,
217 lane_tree = proto_item_add_subtree(ti, ett_atm_lane);
219 proto_tree_add_text(lane_tree, offset, 2, "Marker: 0x%04X",
220 pntohs(&pd[offset]));
223 proto_tree_add_text(lane_tree, offset, 1, "Protocol: 0x%02X",
227 proto_tree_add_text(lane_tree, offset, 1, "Version: 0x%02X",
231 opcode = pntohs(&pd[offset]);
232 proto_tree_add_text(lane_tree, offset, 2, "Opcode: %s",
233 val_to_str(opcode, le_control_opcode_vals,
237 if (opcode == READY_QUERY || opcode == READY_IND) {
238 /* There's nothing more in this packet. */
242 if (opcode & 0x0100) {
243 /* Response; decode status. */
244 proto_tree_add_text(lane_tree, offset, 2, "Status: %s",
245 val_to_str(pntohs(&pd[offset]), le_control_status_vals,
250 proto_tree_add_text(lane_tree, offset, 4, "Transaction ID: 0x%08X",
251 pntohl(&pd[offset]));
254 proto_tree_add_text(lane_tree, offset, 2, "Requester LECID: 0x%04X",
255 pntohs(&pd[offset]));
258 flags = pntohs(&pd[offset]);
259 tf = proto_tree_add_text(lane_tree, offset, 2, "Flags: 0x%04X",
260 pntohs(&pd[offset]));
261 flags_tree = proto_item_add_subtree(tf, ett_atm_lane_lc_flags);
262 proto_tree_add_text(flags_tree, offset, 2, "%s",
263 decode_boolean_bitfield(flags, 0x0001, 8*2,
264 "Remote address", "Local address"));
265 proto_tree_add_text(flags_tree, offset, 2, "%s",
266 decode_boolean_bitfield(flags, 0x0080, 8*2,
267 "Proxy", "Not proxy"));
268 proto_tree_add_text(flags_tree, offset, 2, "%s",
269 decode_boolean_bitfield(flags, 0x0100, 8*2,
270 "Topology change", "No topology change"));
273 dissect_lan_destination(pd, offset, "Source", lane_tree);
276 dissect_lan_destination(pd, offset, "Target", lane_tree);
279 proto_tree_add_text(lane_tree, offset, 20, "Source ATM Address: %s",
280 bytes_to_str(&pd[offset], 20));
283 proto_tree_add_text(lane_tree, offset, 1, "LAN type: %s",
284 val_to_str(pd[offset], le_control_lan_type_vals,
288 proto_tree_add_text(lane_tree, offset, 1, "Maximum frame size: %u",
292 proto_tree_add_text(lane_tree, offset, 1, "Number of TLVs: %u",
296 proto_tree_add_text(lane_tree, offset, 1, "ELAN name size: %u",
300 proto_tree_add_text(lane_tree, offset, 20, "Target ATM Address: %s",
301 bytes_to_str(&pd[offset], 20));
304 proto_tree_add_text(lane_tree, offset, 32, "ELAN name: %s",
305 bytes_to_str(&pd[offset], 32));
311 dissect_lane(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
313 if (check_col(fd, COL_PROTOCOL))
314 col_add_str(fd, COL_PROTOCOL, "ATM LANE");
315 if (check_col(fd, COL_INFO))
316 col_add_str(fd, COL_INFO, "ATM LANE");
318 /* Is it LE Control, 802.3, 802.5, or "none of the above"? */
319 switch (fd->pseudo_header.ngsniffer_atm.AppHLType) {
321 case AHLT_LANE_LE_CTRL:
322 dissect_le_control(pd, offset, fd, tree);
325 case AHLT_LANE_802_3:
326 case AHLT_LANE_802_3_MC:
327 dissect_le_client(pd, offset, fd, tree);
330 /* Dissect as Ethernet */
331 dissect_eth(pd, offset, fd, tree);
334 case AHLT_LANE_802_5:
335 case AHLT_LANE_802_5_MC:
336 dissect_le_client(pd, offset, fd, tree);
339 /* Dissect as Token-Ring */
340 dissect_tr(pd, offset, fd, tree);
344 /* Dump it as raw data. */
345 dissect_data(pd, offset, fd, tree);
351 static const value_string aal_vals[] = {
352 { ATT_AAL_UNKNOWN, "Unknown AAL" },
353 { ATT_AAL1, "AAL1" },
354 { ATT_AAL3_4, "AAL3/4" },
355 { ATT_AAL5, "AAL5" },
356 { ATT_AAL_USER, "User AAL" },
357 { ATT_AAL_SIGNALLING, "Signalling AAL" },
358 { ATT_OAMCELL, "OAM cell" },
362 /* AAL5 higher-level traffic types */
363 static const value_string aal5_hltype_vals[] = {
364 { ATT_HL_UNKNOWN, "Unknown traffic type" },
365 { ATT_HL_LLCMX, "LLC multiplexed" },
366 { ATT_HL_VCMX, "VC multiplexed" },
367 { ATT_HL_LANE, "LANE" },
368 { ATT_HL_ILMI, "ILMI" },
369 { ATT_HL_FRMR, "Frame Relay" },
370 { ATT_HL_SPANS, "FORE SPANS" },
371 { ATT_HL_IPSILON, "Ipsilon" },
375 /* Traffic subtypes for VC multiplexed traffic */
376 static const value_string vcmx_type_vals[] = {
377 { AHLT_UNKNOWN, "Unknown VC multiplexed traffic type" },
378 { AHLT_VCMX_802_3_FCS, "802.3 FCS" },
379 { AHLT_VCMX_802_4_FCS, "802.4 FCS" },
380 { AHLT_VCMX_802_5_FCS, "802.5 FCS" },
381 { AHLT_VCMX_FDDI_FCS, "FDDI FCS" },
382 { AHLT_VCMX_802_6_FCS, "802.6 FCS" },
383 { AHLT_VCMX_802_3, "802.3" },
384 { AHLT_VCMX_802_4, "802.4" },
385 { AHLT_VCMX_802_5, "802.5" },
386 { AHLT_VCMX_FDDI, "FDDI" },
387 { AHLT_VCMX_802_6, "802.6" },
388 { AHLT_VCMX_FRAGMENTS, "Fragments" },
389 { AHLT_VCMX_BPDU, "BPDU" },
393 /* Traffic subtypes for LANE traffic */
394 static const value_string lane_type_vals[] = {
395 { AHLT_UNKNOWN, "Unknown LANE traffic type" },
396 { AHLT_LANE_LE_CTRL, "LE Control" },
397 { AHLT_LANE_802_3, "802.3" },
398 { AHLT_LANE_802_5, "802.5" },
399 { AHLT_LANE_802_3_MC, "802.3 multicast" },
400 { AHLT_LANE_802_5_MC, "802.5 multicast" },
404 /* Traffic subtypes for Ipsilon traffic */
405 static const value_string ipsilon_type_vals[] = {
406 { AHLT_UNKNOWN, "Unknown Ipsilon traffic type" },
407 { AHLT_IPSILON_FT0, "Flow type 0" },
408 { AHLT_IPSILON_FT1, "Flow type 1" },
409 { AHLT_IPSILON_FT2, "Flow type 2" },
414 * We don't know what kind of traffic this is; try to guess.
415 * We at least know it's AAL5....
418 atm_guess_content(const u_char *pd, frame_data *fd)
420 if (fd->pseudo_header.ngsniffer_atm.Vpi == 0) {
422 * Traffic on some PVCs with a VPI of 0 and certain
423 * VCIs is of particular types.
425 switch (fd->pseudo_header.ngsniffer_atm.Vci) {
431 fd->pseudo_header.ngsniffer_atm.AppTrafType =
439 fd->pseudo_header.ngsniffer_atm.AppTrafType |=
446 * OK, we can't tell what it is based on the VPI/VCI; try
447 * guessing based on the contents.
449 if (pd[0] == 0xaa && pd[1] == 0xaa && pd[2] == 0x03) {
451 * Looks like a SNAP header; assume it's LLC multiplexed
454 fd->pseudo_header.ngsniffer_atm.AppTrafType |= ATT_HL_LLCMX;
459 fd->pseudo_header.ngsniffer_atm.AppTrafType |= ATT_HL_LANE;
460 if (pd[0] == 0xff && pd[1] == 0x00) {
462 * Looks like LE Control traffic.
464 fd->pseudo_header.ngsniffer_atm.AppHLType =
468 * XXX - Ethernet, or Token Ring?
469 * Assume Ethernet for now; if we see earlier
470 * LANE traffic, we may be able to figure out
471 * the traffic type from that, but there may
472 * still be situations where the user has to
475 fd->pseudo_header.ngsniffer_atm.AppHLType =
482 dissect_atm(const u_char *pd, frame_data *fd, proto_tree *tree)
485 proto_tree *atm_tree;
490 aal_type = fd->pseudo_header.ngsniffer_atm.AppTrafType & ATT_AALTYPE;
491 hl_type = fd->pseudo_header.ngsniffer_atm.AppTrafType & ATT_HLTYPE;
492 if (aal_type == ATT_AAL5) {
493 if (hl_type == ATT_HL_UNKNOWN ||
494 fd->pseudo_header.ngsniffer_atm.AppHLType == AHLT_UNKNOWN) {
496 * The joys of a connection-oriented link layer; the type of
497 * traffic may be implied by the connection on which it's
498 * traveling, rather than being specified in the packet itself.
500 * For this packet, the program that captured the packet didn't
501 * save the type of traffic, presumably because it didn't know
502 * the traffic type (either it didn't see the connection setup
503 * and wasn't running on one of the endpoints, and wasn't later
504 * told, e.g. by the human running it, what type of traffic was
505 * on that circuit, or was running on one of the endpoints but
506 * was using, to capture the packets, a mechanism that either
507 * doesn't have access to data saying what's going over the
508 * connection or doesn't bother providing that information).
510 * For now, we try to guess the traffic type based on the VPI/VCI
511 * or the packet header; later, we should provide a mechanism
512 * by which the user can specify what sort of traffic is on a
513 * particular circuit.
515 atm_guess_content(pd, fd);
518 * OK, now get the AAL type and high-layer type again.
520 aal_type = fd->pseudo_header.ngsniffer_atm.AppTrafType & ATT_AALTYPE;
521 hl_type = fd->pseudo_header.ngsniffer_atm.AppTrafType & ATT_HLTYPE;
525 if (check_col(fd, COL_PROTOCOL))
526 col_add_str(fd, COL_PROTOCOL, "ATM");
528 switch (fd->pseudo_header.ngsniffer_atm.channel) {
531 /* Traffic from DCE to DTE. */
532 if (check_col(fd, COL_RES_DL_DST))
533 col_add_str(fd, COL_RES_DL_DST, "DTE");
534 if (check_col(fd, COL_RES_DL_SRC))
535 col_add_str(fd, COL_RES_DL_SRC, "DCE");
539 /* Traffic from DTE to DCE. */
540 if (check_col(fd, COL_RES_DL_DST))
541 col_add_str(fd, COL_RES_DL_DST, "DCE");
542 if (check_col(fd, COL_RES_DL_SRC))
543 col_add_str(fd, COL_RES_DL_SRC, "DTE");
547 if (check_col(fd, COL_INFO)) {
548 if (aal_type == ATT_AAL5) {
549 col_add_fstr(fd, COL_INFO, "AAL5 %s",
550 val_to_str(hl_type, aal5_hltype_vals,
551 "Unknown traffic type (%x)"));
553 col_add_str(fd, COL_INFO,
554 val_to_str(aal_type, aal_vals, "Unknown AAL (%x)"));
559 ti = proto_tree_add_item_format(tree, proto_atm, 0, 0, NULL,
561 atm_tree = proto_item_add_subtree(ti, ett_atm);
563 proto_tree_add_text(atm_tree, 0, 0, "AAL: %s",
564 val_to_str(aal_type, aal_vals, "Unknown AAL (%x)"));
565 if (aal_type == ATT_AAL5) {
566 proto_tree_add_text(atm_tree, 0, 0, "Traffic type: %s",
567 val_to_str(hl_type, aal5_hltype_vals, "Unknown AAL5 traffic type (%x)"));
571 proto_tree_add_text(atm_tree, 0, 0, "LLC multiplexed traffic");
575 proto_tree_add_text(atm_tree, 0, 0, "VC multiplexed traffic type: %s",
576 val_to_str(fd->pseudo_header.ngsniffer_atm.AppHLType,
577 vcmx_type_vals, "Unknown VCMX traffic type (%x)"));
581 proto_tree_add_text(atm_tree, 0, 0, "LANE traffic type: %s",
582 val_to_str(fd->pseudo_header.ngsniffer_atm.AppHLType,
583 lane_type_vals, "Unknown LANE traffic type (%x)"));
587 proto_tree_add_text(atm_tree, 0, 0, "Ipsilon traffic type: %s",
588 val_to_str(fd->pseudo_header.ngsniffer_atm.AppHLType,
589 ipsilon_type_vals, "Unknown Ipsilon traffic type (%x)"));
593 proto_tree_add_item(atm_tree, hf_atm_vpi, 0, 0,
594 fd->pseudo_header.ngsniffer_atm.Vpi);
595 proto_tree_add_item(atm_tree, hf_atm_vci, 0, 0,
596 fd->pseudo_header.ngsniffer_atm.Vci);
597 switch (fd->pseudo_header.ngsniffer_atm.channel) {
600 /* Traffic from DCE to DTE. */
601 proto_tree_add_text(atm_tree, 0, 0, "Channel: DCE->DTE");
605 /* Traffic from DTE to DCE. */
606 proto_tree_add_text(atm_tree, 0, 0, "Channel: DTE->DCE");
610 /* Sniffers shouldn't provide anything other than 0 or 1. */
611 proto_tree_add_text(atm_tree, 0, 0, "Channel: %u",
612 fd->pseudo_header.ngsniffer_atm.channel);
615 if (fd->pseudo_header.ngsniffer_atm.cells != 0) {
617 * If the cell count is 0, assume it means we don't know how
620 * XXX - also, if this is AAL5 traffic, assume it means we don't
621 * know what was in the AAL5 trailer. We may, however, find
622 * some capture program that can give us the AAL5 trailer
623 * information but not the cell count, in which case we need
624 * some other way of indicating whether we have the AAL5 trailer
627 proto_tree_add_text(atm_tree, 0, 0, "Cells: %u",
628 fd->pseudo_header.ngsniffer_atm.cells);
629 if (aal_type == ATT_AAL5) {
630 proto_tree_add_text(atm_tree, 0, 0, "AAL5 U2U: %u",
631 fd->pseudo_header.ngsniffer_atm.aal5t_u2u);
632 proto_tree_add_text(atm_tree, 0, 0, "AAL5 len: %u",
633 fd->pseudo_header.ngsniffer_atm.aal5t_len);
634 proto_tree_add_text(atm_tree, 0, 0, "AAL5 checksum: 0x%08X",
635 fd->pseudo_header.ngsniffer_atm.aal5t_chksum);
642 case ATT_AAL_SIGNALLING:
643 dissect_sscop(pd, offset, fd, tree);
650 /* Dissect as WTAP_ENCAP_ATM_RFC1483 */
651 /* The ATM iptrace capture that we have hows LLC at this point,
652 * so that's what I'm calling */
653 dissect_llc(pd, offset, fd, tree);
657 dissect_lane(pd, offset, fd, tree);
661 dissect_snmp_pdu(pd, offset, fd, tree, "ILMI", proto_ilmi, ett_ilmi);
666 /* Dump it as raw data. */
667 dissect_data(pd, offset, fd, tree);
675 /* Dump it as raw data. (Is this a single cell?) */
676 dissect_data(pd, offset, fd, tree);
683 proto_register_atm(void)
685 static hf_register_info hf[] = {
687 { "VPI", "atm.vpi", FT_UINT8, BASE_DEC, NULL, 0x0,
691 { "VCI", "atm.vci", FT_UINT16, BASE_DEC, NULL, 0x0,
694 static gint *ett[] = {
698 &ett_atm_lane_lc_lan_dest,
699 &ett_atm_lane_lc_lan_dest_rd,
700 &ett_atm_lane_lc_flags,
702 proto_atm = proto_register_protocol("ATM", "atm");
703 proto_register_field_array(proto_atm, hf, array_length(hf));
704 proto_ilmi = proto_register_protocol("ILMI", "ilmi");
705 proto_atm_lane = proto_register_protocol("ATM LANE", "lane");
706 proto_register_subtree_array(ett, array_length(ett));