1127668Sbms/*
2127668Sbms * Copyright (c) 1997 Yen Yen Lim and North Dakota State University
3127668Sbms * All rights reserved.
4127668Sbms *
5127668Sbms * Redistribution and use in source and binary forms, with or without
6127668Sbms * modification, are permitted provided that the following conditions
7127668Sbms * are met:
8127668Sbms * 1. Redistributions of source code must retain the above copyright
9127668Sbms *    notice, this list of conditions and the following disclaimer.
10127668Sbms * 2. Redistributions in binary form must reproduce the above copyright
11127668Sbms *    notice, this list of conditions and the following disclaimer in the
12127668Sbms *    documentation and/or other materials provided with the distribution.
13127668Sbms * 3. All advertising materials mentioning features or use of this software
14127668Sbms *    must display the following acknowledgement:
15127668Sbms *      This product includes software developed by Yen Yen Lim and
16127668Sbms	North Dakota State University
17127668Sbms * 4. The name of the author may not be used to endorse or promote products
18127668Sbms *    derived from this software without specific prior written permission.
19127668Sbms *
20127668Sbms * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21127668Sbms * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22127668Sbms * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23127668Sbms * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24127668Sbms * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25127668Sbms * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26127668Sbms * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27127668Sbms * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28127668Sbms * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29127668Sbms * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30127668Sbms * POSSIBILITY OF SUCH DAMAGE.
31127668Sbms */
32127668Sbms
33276788Sdelphij#define NETDISSECT_REWORKED
34127668Sbms#ifdef HAVE_CONFIG_H
35127668Sbms#include "config.h"
36127668Sbms#endif
37127668Sbms
38127668Sbms#include <tcpdump-stdinc.h>
39276788Sdelphij
40127668Sbmsstruct mbuf;
41127668Sbmsstruct rtentry;
42127668Sbms
43127668Sbms#include "interface.h"
44127668Sbms#include "extract.h"
45127668Sbms
46127668Sbms#include "atm.h"
47127668Sbms
48127668Sbms/* SunATM header for ATM packet */
49127668Sbms#define DIR_POS		0	/* Direction (0x80 = transmit, 0x00 = receive) */
50127668Sbms#define VPI_POS		1	/* VPI */
51127668Sbms#define VCI_POS		2	/* VCI */
52127668Sbms#define PKT_BEGIN_POS   4	/* Start of the ATM packet */
53127668Sbms
54127668Sbms/* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */
55127668Sbms#define PT_LANE		0x01	/* LANE */
56127668Sbms#define PT_LLC		0x02	/* LLC encapsulation */
57127668Sbms
58127668Sbms/*
59127668Sbms * This is the top level routine of the printer.  'p' points
60127668Sbms * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp,
61146773Ssam * 'h->len' is the length of the packet off the wire, and 'h->caplen'
62127668Sbms * is the number of bytes actually captured.
63127668Sbms */
64127668Sbmsu_int
65276788Sdelphijsunatm_if_print(netdissect_options *ndo,
66276788Sdelphij                const struct pcap_pkthdr *h, const u_char *p)
67127668Sbms{
68127668Sbms	u_int caplen = h->caplen;
69127668Sbms	u_int length = h->len;
70127668Sbms	u_short vci;
71127668Sbms	u_char vpi;
72127668Sbms	u_int traftype;
73127668Sbms
74127668Sbms	if (caplen < PKT_BEGIN_POS) {
75276788Sdelphij		ND_PRINT((ndo, "[|atm]"));
76127668Sbms		return (caplen);
77127668Sbms	}
78127668Sbms
79276788Sdelphij	if (ndo->ndo_eflag) {
80276788Sdelphij		ND_PRINT((ndo, p[DIR_POS] & 0x80 ? "Tx: " : "Rx: "));
81127668Sbms	}
82127668Sbms
83127668Sbms	switch (p[DIR_POS] & 0x0f) {
84127668Sbms
85127668Sbms	case PT_LANE:
86127668Sbms		traftype = ATM_LANE;
87127668Sbms		break;
88127668Sbms
89127668Sbms	case PT_LLC:
90127668Sbms		traftype = ATM_LLC;
91127668Sbms		break;
92127668Sbms
93127668Sbms	default:
94127668Sbms		traftype = ATM_UNKNOWN;
95127668Sbms		break;
96127668Sbms	}
97127668Sbms
98127668Sbms	vci = EXTRACT_16BITS(&p[VCI_POS]);
99127668Sbms	vpi = p[VPI_POS];
100127668Sbms
101127668Sbms	p += PKT_BEGIN_POS;
102127668Sbms	caplen -= PKT_BEGIN_POS;
103127668Sbms	length -= PKT_BEGIN_POS;
104276788Sdelphij	atm_print(ndo, vpi, vci, traftype, p, length, caplen);
105127668Sbms
106127668Sbms	return (PKT_BEGIN_POS);
107127668Sbms}
108