xref: /freebsd/contrib/tcpdump/print-lane.c (revision 3340d77368116708ab5b5b95acf6c9c710528300)
1b0453382SBill Fenner /*
2b0453382SBill Fenner  * Marko Kiiskila carnil@cs.tut.fi
3b0453382SBill Fenner  *
4b0453382SBill Fenner  * Tampere University of Technology - Telecommunications Laboratory
5b0453382SBill Fenner  *
6b0453382SBill Fenner  * Permission to use, copy, modify and distribute this
7b0453382SBill Fenner  * software and its documentation is hereby granted,
8b0453382SBill Fenner  * provided that both the copyright notice and this
9b0453382SBill Fenner  * permission notice appear in all copies of the software,
10b0453382SBill Fenner  * derivative works or modified versions, and any portions
11b0453382SBill Fenner  * thereof, that both notices appear in supporting
12b0453382SBill Fenner  * documentation, and that the use of this software is
13b0453382SBill Fenner  * acknowledged in any publications resulting from using
14b0453382SBill Fenner  * the software.
15b0453382SBill Fenner  *
16b0453382SBill Fenner  * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17b0453382SBill Fenner  * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18b0453382SBill Fenner  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
19b0453382SBill Fenner  * SOFTWARE.
20b0453382SBill Fenner  *
21b0453382SBill Fenner  */
22b0453382SBill Fenner 
23*3340d773SGleb Smirnoff /* \summary: ATM LANE printer */
24*3340d773SGleb Smirnoff 
25b0453382SBill Fenner #ifdef HAVE_CONFIG_H
26b0453382SBill Fenner #include "config.h"
27b0453382SBill Fenner #endif
28b0453382SBill Fenner 
29*3340d773SGleb Smirnoff #include <netdissect-stdinc.h>
30b0453382SBill Fenner 
31*3340d773SGleb Smirnoff #include "netdissect.h"
325b0fe478SBruce M Simpson #include "extract.h"
33685295f4SBill Fenner #include "ether.h"
343c602fabSXin LI 
353c602fabSXin LI struct lecdatahdr_8023 {
363c602fabSXin LI   uint16_t le_header;
373c602fabSXin LI   uint8_t h_dest[ETHER_ADDR_LEN];
383c602fabSXin LI   uint8_t h_source[ETHER_ADDR_LEN];
393c602fabSXin LI   uint16_t h_type;
403c602fabSXin LI };
413c602fabSXin LI 
423c602fabSXin LI struct lane_controlhdr {
433c602fabSXin LI   uint16_t lec_header;
443c602fabSXin LI   uint8_t lec_proto;
453c602fabSXin LI   uint8_t lec_vers;
463c602fabSXin LI   uint16_t lec_opcode;
473c602fabSXin LI };
48b0453382SBill Fenner 
495b0fe478SBruce M Simpson static const struct tok lecop2str[] = {
505b0fe478SBruce M Simpson 	{ 0x0001,	"configure request" },
515b0fe478SBruce M Simpson 	{ 0x0101,	"configure response" },
525b0fe478SBruce M Simpson 	{ 0x0002,	"join request" },
535b0fe478SBruce M Simpson 	{ 0x0102,	"join response" },
545b0fe478SBruce M Simpson 	{ 0x0003,	"ready query" },
555b0fe478SBruce M Simpson 	{ 0x0103,	"ready indication" },
565b0fe478SBruce M Simpson 	{ 0x0004,	"register request" },
575b0fe478SBruce M Simpson 	{ 0x0104,	"register response" },
585b0fe478SBruce M Simpson 	{ 0x0005,	"unregister request" },
595b0fe478SBruce M Simpson 	{ 0x0105,	"unregister response" },
605b0fe478SBruce M Simpson 	{ 0x0006,	"ARP request" },
615b0fe478SBruce M Simpson 	{ 0x0106,	"ARP response" },
625b0fe478SBruce M Simpson 	{ 0x0007,	"flush request" },
635b0fe478SBruce M Simpson 	{ 0x0107,	"flush response" },
645b0fe478SBruce M Simpson 	{ 0x0008,	"NARP request" },
655b0fe478SBruce M Simpson 	{ 0x0009,	"topology request" },
665b0fe478SBruce M Simpson 	{ 0,		NULL }
675b0fe478SBruce M Simpson };
685b0fe478SBruce M Simpson 
6927df3f5dSRui Paulo static void
70cac3dcd5SXin LI lane_hdr_print(netdissect_options *ndo, const u_char *bp)
71b0453382SBill Fenner {
723c602fabSXin LI 	ND_PRINT((ndo, "lecid:%x ", EXTRACT_16BITS(bp)));
73b0453382SBill Fenner }
74b0453382SBill Fenner 
75b0453382SBill Fenner /*
765b0fe478SBruce M Simpson  * This is the top level routine of the printer.  'p' points
775b0fe478SBruce M Simpson  * to the LANE header of the packet, 'h->ts' is the timestamp,
781de50e9fSSam Leffler  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
79b0453382SBill Fenner  * is the number of bytes actually captured.
805b0fe478SBruce M Simpson  *
815b0fe478SBruce M Simpson  * This assumes 802.3, not 802.5, LAN emulation.
82b0453382SBill Fenner  */
83b0453382SBill Fenner void
843c602fabSXin LI lane_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
85b0453382SBill Fenner {
86*3340d773SGleb Smirnoff 	const struct lane_controlhdr *lec;
87b0453382SBill Fenner 
885b0fe478SBruce M Simpson 	if (caplen < sizeof(struct lane_controlhdr)) {
893c602fabSXin LI 		ND_PRINT((ndo, "[|lane]"));
905b0fe478SBruce M Simpson 		return;
915b0fe478SBruce M Simpson 	}
925b0fe478SBruce M Simpson 
93*3340d773SGleb Smirnoff 	lec = (const struct lane_controlhdr *)p;
945b0fe478SBruce M Simpson 	if (EXTRACT_16BITS(&lec->lec_header) == 0xff00) {
955b0fe478SBruce M Simpson 		/*
965b0fe478SBruce M Simpson 		 * LE Control.
975b0fe478SBruce M Simpson 		 */
983c602fabSXin LI 		ND_PRINT((ndo, "lec: proto %x vers %x %s",
995b0fe478SBruce M Simpson 		    lec->lec_proto, lec->lec_vers,
1003c602fabSXin LI 		    tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode))));
1015b0fe478SBruce M Simpson 		return;
1025b0fe478SBruce M Simpson 	}
103b0453382SBill Fenner 
10427df3f5dSRui Paulo 	/*
10527df3f5dSRui Paulo 	 * Go past the LE header.
10627df3f5dSRui Paulo 	 */
10727df3f5dSRui Paulo 	length -= 2;
10827df3f5dSRui Paulo 	caplen -= 2;
10927df3f5dSRui Paulo 	p += 2;
110b0453382SBill Fenner 
111b0453382SBill Fenner 	/*
11227df3f5dSRui Paulo 	 * Now print the encapsulated frame, under the assumption
11327df3f5dSRui Paulo 	 * that it's an Ethernet frame.
114b0453382SBill Fenner 	 */
1153c602fabSXin LI 	ether_print(ndo, p, length, caplen, lane_hdr_print, p - 2);
1165b0fe478SBruce M Simpson }
1175b0fe478SBruce M Simpson 
1185b0fe478SBruce M Simpson u_int
1193c602fabSXin LI lane_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
1205b0fe478SBruce M Simpson {
1213c602fabSXin LI 	lane_print(ndo, p, h->len, h->caplen);
1225b0fe478SBruce M Simpson 
1235b0fe478SBruce M Simpson 	return (sizeof(struct lecdatahdr_8023));
124b0453382SBill Fenner }
125