1249259Sdim/*
2249259Sdim * Marko Kiiskila carnil@cs.tut.fi
3249259Sdim *
4249259Sdim * Tampere University of Technology - Telecommunications Laboratory
5249259Sdim *
6249259Sdim * Permission to use, copy, modify and distribute this
7249259Sdim * software and its documentation is hereby granted,
8249259Sdim * provided that both the copyright notice and this
9249259Sdim * permission notice appear in all copies of the software,
10249259Sdim * derivative works or modified versions, and any portions
11249259Sdim * thereof, that both notices appear in supporting
12249259Sdim * documentation, and that the use of this software is
13249259Sdim * acknowledged in any publications resulting from using
14249259Sdim * the software.
15249259Sdim *
16249259Sdim * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17249259Sdim * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18249259Sdim * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
19249259Sdim * SOFTWARE.
20249259Sdim *
21249259Sdim */
22249259Sdim
23249259Sdim#include <sys/cdefs.h>
24249259Sdim#ifndef lint
25249259Sdim__RCSID("$NetBSD: print-lane.c,v 1.7 2023/08/17 20:19:40 christos Exp $");
26249259Sdim#endif
27249259Sdim
28249259Sdim/* \summary: ATM LANE printer */
29249259Sdim
30249259Sdim#ifdef HAVE_CONFIG_H
31249259Sdim#include <config.h>
32249259Sdim#endif
33249259Sdim
34249259Sdim#include "netdissect-stdinc.h"
35249259Sdim
36249259Sdim#define ND_LONGJMP_FROM_TCHECK
37249259Sdim#include "netdissect.h"
38249259Sdim#include "extract.h"
39249259Sdim
40249259Sdimstruct lecdatahdr_8023 {
41249259Sdim  nd_uint16_t le_header;
42249259Sdim  nd_mac_addr h_dest;
43249259Sdim  nd_mac_addr h_source;
44249259Sdim  nd_uint16_t h_type;
45249259Sdim};
46249259Sdim
47249259Sdimstruct lane_controlhdr {
48249259Sdim  nd_uint16_t lec_header;
49249259Sdim  nd_uint8_t  lec_proto;
50249259Sdim  nd_uint8_t  lec_vers;
51249259Sdim  nd_uint16_t lec_opcode;
52249259Sdim};
53249259Sdim
54249259Sdimstatic const struct tok lecop2str[] = {
55249259Sdim	{ 0x0001,	"configure request" },
56249259Sdim	{ 0x0101,	"configure response" },
57249259Sdim	{ 0x0002,	"join request" },
58249259Sdim	{ 0x0102,	"join response" },
59249259Sdim	{ 0x0003,	"ready query" },
60249259Sdim	{ 0x0103,	"ready indication" },
61249259Sdim	{ 0x0004,	"register request" },
62249259Sdim	{ 0x0104,	"register response" },
63249259Sdim	{ 0x0005,	"unregister request" },
64249259Sdim	{ 0x0105,	"unregister response" },
65249259Sdim	{ 0x0006,	"ARP request" },
66249259Sdim	{ 0x0106,	"ARP response" },
67249259Sdim	{ 0x0007,	"flush request" },
68249259Sdim	{ 0x0107,	"flush response" },
69249259Sdim	{ 0x0008,	"NARP request" },
70249259Sdim	{ 0x0009,	"topology request" },
71249259Sdim	{ 0,		NULL }
72249259Sdim};
73249259Sdim
74249259Sdimstatic void
75249259Sdimlane_hdr_print(netdissect_options *ndo, const u_char *bp)
76249259Sdim{
77249259Sdim	ND_PRINT("lecid:%x ", GET_BE_U_2(bp));
78249259Sdim}
79249259Sdim
80249259Sdim/*
81249259Sdim * This assumes 802.3, not 802.5, LAN emulation.
82249259Sdim */
83249259Sdimvoid
84249259Sdimlane_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
85249259Sdim{
86249259Sdim	const struct lane_controlhdr *lec;
87249259Sdim
88249259Sdim	ndo->ndo_protocol = "lane";
89249259Sdim
90249259Sdim	lec = (const struct lane_controlhdr *)p;
91249259Sdim	if (GET_BE_U_2(lec->lec_header) == 0xff00) {
92249259Sdim		/*
93249259Sdim		 * LE Control.
94249259Sdim		 */
95249259Sdim		ND_PRINT("lec: proto %x vers %x %s",
96249259Sdim			 GET_U_1(lec->lec_proto),
97249259Sdim			 GET_U_1(lec->lec_vers),
98249259Sdim			 tok2str(lecop2str, "opcode-#%u", GET_BE_U_2(lec->lec_opcode)));
99249259Sdim		return;
100249259Sdim	}
101249259Sdim
102249259Sdim	/*
103249259Sdim	 * Go past the LE header.
104249259Sdim	 */
105249259Sdim	ND_TCHECK_2(p); /* Needed */
106249259Sdim	length -= 2;
107249259Sdim	caplen -= 2;
108249259Sdim	p += 2;
109249259Sdim
110249259Sdim	/*
111249259Sdim	 * Now print the encapsulated frame, under the assumption
112249259Sdim	 * that it's an Ethernet frame.
113249259Sdim	 */
114249259Sdim	ether_print(ndo, p, length, caplen, lane_hdr_print, p - 2);
115249259Sdim}
116249259Sdim