166458Sdfr/*
266458Sdfr * Copyright (c) 1997 Yen Yen Lim and North Dakota State University
366458Sdfr * All rights reserved.
466458Sdfr *
566458Sdfr * Redistribution and use in source and binary forms, with or without
666458Sdfr * modification, are permitted provided that the following conditions
766458Sdfr * are met:
866458Sdfr * 1. Redistributions of source code must retain the above copyright
966458Sdfr *    notice, this list of conditions and the following disclaimer.
1066458Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1166458Sdfr *    notice, this list of conditions and the following disclaimer in the
1266458Sdfr *    documentation and/or other materials provided with the distribution.
1366458Sdfr * 3. All advertising materials mentioning features or use of this software
1466458Sdfr *    must display the following acknowledgement:
1566458Sdfr *      This product includes software developed by Yen Yen Lim and
1666458Sdfr	North Dakota State University
1766458Sdfr * 4. The name of the author may not be used to endorse or promote products
1866458Sdfr *    derived from this software without specific prior written permission.
1966458Sdfr *
2066458Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2166458Sdfr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2266458Sdfr * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2366458Sdfr * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2466458Sdfr * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2566458Sdfr * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2666458Sdfr * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2766458Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2866458Sdfr * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2966458Sdfr * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3066458Sdfr * POSSIBILITY OF SUCH DAMAGE.
3166458Sdfr */
3266458Sdfr
3366458Sdfr#include <sys/cdefs.h>
3466458Sdfr#ifndef lint
3566458Sdfr__RCSID("$NetBSD: print-sunatm.c,v 1.7 2023/08/17 20:19:40 christos Exp $");
3666458Sdfr#endif
3766458Sdfr
3866458Sdfr/* \summary: SunATM DLPI capture printer */
3966458Sdfr
4066458Sdfr#ifdef HAVE_CONFIG_H
4166458Sdfr#include <config.h>
4266458Sdfr#endif
4366458Sdfr
4466458Sdfr#include "netdissect-stdinc.h"
4566458Sdfr
4666458Sdfr#define ND_LONGJMP_FROM_TCHECK
4766458Sdfr#include "netdissect.h"
4866458Sdfr#include "extract.h"
4966458Sdfr
5066458Sdfr#include "atm.h"
5166458Sdfr
52115084Smarcel/* SunATM header for ATM packet */
53115084Smarcel#define DIR_POS		0	/* Direction (0x80 = transmit, 0x00 = receive) */
5466458Sdfr#define VPI_POS		1	/* VPI */
5566458Sdfr#define VCI_POS		2	/* VCI */
56115084Smarcel#define PKT_BEGIN_POS   4	/* Start of the ATM packet */
5766458Sdfr
58115084Smarcel/* Protocol type values in the bottom for bits of the byte at SUNATM_DIR_POS. */
59115084Smarcel#define PT_LANE		0x01	/* LANE */
60115084Smarcel#define PT_LLC		0x02	/* LLC encapsulation */
61115084Smarcel
62115084Smarcel/*
63115084Smarcel * This is the top level routine of the printer.  'p' points
64115084Smarcel * to the SunATM pseudo-header for the packet, 'h->ts' is the timestamp,
65115913Smarcel * 'h->len' is the length of the packet off the wire, and 'h->caplen'
66115913Smarcel * is the number of bytes actually captured.
67115913Smarcel */
68115913Smarcelvoid
69115913Smarcelsunatm_if_print(netdissect_options *ndo,
70115913Smarcel                const struct pcap_pkthdr *h, const u_char *p)
71115913Smarcel{
72115913Smarcel	u_int caplen = h->caplen;
7372892Sjhb	u_int length = h->len;
7466458Sdfr	u_short vci;
7566458Sdfr	u_char vpi;
7666458Sdfr	u_int traftype;
7766458Sdfr
78118414Smarcel	ndo->ndo_protocol = "sunatm";
79118414Smarcel
80118414Smarcel	if (ndo->ndo_eflag) {
81118414Smarcel		ND_PRINT(GET_U_1(p + DIR_POS) & 0x80 ? "Tx: " : "Rx: ");
8266458Sdfr	}
8366458Sdfr
8466458Sdfr	switch (GET_U_1(p + DIR_POS) & 0x0f) {
8566458Sdfr
8666458Sdfr	case PT_LANE:
8766458Sdfr		traftype = ATM_LANE;
8866458Sdfr		break;
8966458Sdfr
9066458Sdfr	case PT_LLC:
9166458Sdfr		traftype = ATM_LLC;
9266458Sdfr		break;
9369003Smarkm
9469003Smarkm	default:
9569003Smarkm		traftype = ATM_UNKNOWN;
9669003Smarkm		break;
97118990Smarcel	}
9869003Smarkm
99118990Smarcel	vpi = GET_U_1(p + VPI_POS);
100118990Smarcel	vci = GET_BE_U_2(p + VCI_POS);
101118990Smarcel
102118990Smarcel	p += PKT_BEGIN_POS;
103118990Smarcel	caplen -= PKT_BEGIN_POS;
10466458Sdfr	length -= PKT_BEGIN_POS;
10566458Sdfr	ndo->ndo_ll_hdr_len += PKT_BEGIN_POS;
10666458Sdfr	atm_print(ndo, vpi, vci, traftype, p, length, caplen);
107}
108