xref: /dflybsd-src/contrib/tcpdump/print-lane.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Marko Kiiskila carnil@cs.tut.fi
341c99275SPeter Avalos  *
441c99275SPeter Avalos  * Tampere University of Technology - Telecommunications Laboratory
541c99275SPeter Avalos  *
641c99275SPeter Avalos  * Permission to use, copy, modify and distribute this
741c99275SPeter Avalos  * software and its documentation is hereby granted,
841c99275SPeter Avalos  * provided that both the copyright notice and this
941c99275SPeter Avalos  * permission notice appear in all copies of the software,
1041c99275SPeter Avalos  * derivative works or modified versions, and any portions
1141c99275SPeter Avalos  * thereof, that both notices appear in supporting
1241c99275SPeter Avalos  * documentation, and that the use of this software is
1341c99275SPeter Avalos  * acknowledged in any publications resulting from using
1441c99275SPeter Avalos  * the software.
1541c99275SPeter Avalos  *
1641c99275SPeter Avalos  * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
1741c99275SPeter Avalos  * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR
1841c99275SPeter Avalos  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS
1941c99275SPeter Avalos  * SOFTWARE.
2041c99275SPeter Avalos  *
2141c99275SPeter Avalos  */
2241c99275SPeter Avalos 
23411677aeSAaron LI /* \summary: ATM LANE printer */
2441c99275SPeter Avalos 
2541c99275SPeter Avalos #ifdef HAVE_CONFIG_H
26*ed775ee7SAntonio Huete Jimenez #include <config.h>
2741c99275SPeter Avalos #endif
2841c99275SPeter Avalos 
29*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
3041c99275SPeter Avalos 
31*ed775ee7SAntonio Huete Jimenez #define ND_LONGJMP_FROM_TCHECK
32411677aeSAaron LI #include "netdissect.h"
3341c99275SPeter Avalos #include "extract.h"
34411677aeSAaron LI 
35411677aeSAaron LI struct lecdatahdr_8023 {
36*ed775ee7SAntonio Huete Jimenez   nd_uint16_t le_header;
37*ed775ee7SAntonio Huete Jimenez   nd_mac_addr h_dest;
38*ed775ee7SAntonio Huete Jimenez   nd_mac_addr h_source;
39*ed775ee7SAntonio Huete Jimenez   nd_uint16_t h_type;
40411677aeSAaron LI };
41411677aeSAaron LI 
42411677aeSAaron LI struct lane_controlhdr {
43*ed775ee7SAntonio Huete Jimenez   nd_uint16_t lec_header;
44*ed775ee7SAntonio Huete Jimenez   nd_uint8_t  lec_proto;
45*ed775ee7SAntonio Huete Jimenez   nd_uint8_t  lec_vers;
46*ed775ee7SAntonio Huete Jimenez   nd_uint16_t lec_opcode;
47411677aeSAaron LI };
4841c99275SPeter Avalos 
4941c99275SPeter Avalos static const struct tok lecop2str[] = {
5041c99275SPeter Avalos 	{ 0x0001,	"configure request" },
5141c99275SPeter Avalos 	{ 0x0101,	"configure response" },
5241c99275SPeter Avalos 	{ 0x0002,	"join request" },
5341c99275SPeter Avalos 	{ 0x0102,	"join response" },
5441c99275SPeter Avalos 	{ 0x0003,	"ready query" },
5541c99275SPeter Avalos 	{ 0x0103,	"ready indication" },
5641c99275SPeter Avalos 	{ 0x0004,	"register request" },
5741c99275SPeter Avalos 	{ 0x0104,	"register response" },
5841c99275SPeter Avalos 	{ 0x0005,	"unregister request" },
5941c99275SPeter Avalos 	{ 0x0105,	"unregister response" },
6041c99275SPeter Avalos 	{ 0x0006,	"ARP request" },
6141c99275SPeter Avalos 	{ 0x0106,	"ARP response" },
6241c99275SPeter Avalos 	{ 0x0007,	"flush request" },
6341c99275SPeter Avalos 	{ 0x0107,	"flush response" },
6441c99275SPeter Avalos 	{ 0x0008,	"NARP request" },
6541c99275SPeter Avalos 	{ 0x0009,	"topology request" },
6641c99275SPeter Avalos 	{ 0,		NULL }
6741c99275SPeter Avalos };
6841c99275SPeter Avalos 
6927bfbee1SPeter Avalos static void
lane_hdr_print(netdissect_options * ndo,const u_char * bp)7027bfbee1SPeter Avalos lane_hdr_print(netdissect_options *ndo, const u_char *bp)
7141c99275SPeter Avalos {
72*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("lecid:%x ", GET_BE_U_2(bp));
7341c99275SPeter Avalos }
7441c99275SPeter Avalos 
7541c99275SPeter Avalos /*
7641c99275SPeter Avalos  * This assumes 802.3, not 802.5, LAN emulation.
7741c99275SPeter Avalos  */
7841c99275SPeter Avalos void
lane_print(netdissect_options * ndo,const u_char * p,u_int length,u_int caplen)79411677aeSAaron LI lane_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen)
8041c99275SPeter Avalos {
81411677aeSAaron LI 	const struct lane_controlhdr *lec;
8241c99275SPeter Avalos 
83*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "lane";
8441c99275SPeter Avalos 
85411677aeSAaron LI 	lec = (const struct lane_controlhdr *)p;
86*ed775ee7SAntonio Huete Jimenez 	if (GET_BE_U_2(lec->lec_header) == 0xff00) {
8741c99275SPeter Avalos 		/*
8841c99275SPeter Avalos 		 * LE Control.
8941c99275SPeter Avalos 		 */
90*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("lec: proto %x vers %x %s",
91*ed775ee7SAntonio Huete Jimenez 			 GET_U_1(lec->lec_proto),
92*ed775ee7SAntonio Huete Jimenez 			 GET_U_1(lec->lec_vers),
93*ed775ee7SAntonio Huete Jimenez 			 tok2str(lecop2str, "opcode-#%u", GET_BE_U_2(lec->lec_opcode)));
9441c99275SPeter Avalos 		return;
9541c99275SPeter Avalos 	}
9641c99275SPeter Avalos 
9727bfbee1SPeter Avalos 	/*
9827bfbee1SPeter Avalos 	 * Go past the LE header.
9927bfbee1SPeter Avalos 	 */
100*ed775ee7SAntonio Huete Jimenez 	ND_TCHECK_2(p); /* Needed */
10127bfbee1SPeter Avalos 	length -= 2;
10227bfbee1SPeter Avalos 	caplen -= 2;
10327bfbee1SPeter Avalos 	p += 2;
10441c99275SPeter Avalos 
10541c99275SPeter Avalos 	/*
10627bfbee1SPeter Avalos 	 * Now print the encapsulated frame, under the assumption
10727bfbee1SPeter Avalos 	 * that it's an Ethernet frame.
10841c99275SPeter Avalos 	 */
109411677aeSAaron LI 	ether_print(ndo, p, length, caplen, lane_hdr_print, p - 2);
11041c99275SPeter Avalos }
111