| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Marko Kiiskila carnil@cs.tut.fi | 
 | 3 |  * | 
 | 4 |  * Tampere University of Technology - Telecommunications Laboratory | 
 | 5 |  * | 
 | 6 |  * Permission to use, copy, modify and distribute this | 
 | 7 |  * software and its documentation is hereby granted, | 
 | 8 |  * provided that both the copyright notice and this | 
 | 9 |  * permission notice appear in all copies of the software, | 
 | 10 |  * derivative works or modified versions, and any portions | 
 | 11 |  * thereof, that both notices appear in supporting | 
 | 12 |  * documentation, and that the use of this software is | 
 | 13 |  * acknowledged in any publications resulting from using | 
 | 14 |  * the software. | 
 | 15 |  * | 
 | 16 |  * TUT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | 
 | 17 |  * CONDITION AND DISCLAIMS ANY LIABILITY OF ANY KIND FOR | 
 | 18 |  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS | 
 | 19 |  * SOFTWARE. | 
 | 20 |  * | 
 | 21 |  */ | 
 | 22 |  | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 23 | /* \summary: ATM LANE printer */ | 
 | 24 |  | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 25 | #ifdef HAVE_CONFIG_H | 
 | 26 | #include "config.h" | 
 | 27 | #endif | 
 | 28 |  | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 29 | #include <netdissect-stdinc.h> | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 30 |  | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 31 | #include "netdissect.h" | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 32 | #include "extract.h" | 
 | 33 | #include "ether.h" | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 34 |  | 
 | 35 | struct lecdatahdr_8023 { | 
 | 36 |   uint16_t le_header; | 
 | 37 |   uint8_t h_dest[ETHER_ADDR_LEN]; | 
 | 38 |   uint8_t h_source[ETHER_ADDR_LEN]; | 
 | 39 |   uint16_t h_type; | 
 | 40 | }; | 
 | 41 |  | 
 | 42 | struct lane_controlhdr { | 
 | 43 |   uint16_t lec_header; | 
 | 44 |   uint8_t lec_proto; | 
 | 45 |   uint8_t lec_vers; | 
 | 46 |   uint16_t lec_opcode; | 
 | 47 | }; | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 48 |  | 
 | 49 | static const struct tok lecop2str[] = { | 
 | 50 | 	{ 0x0001,	"configure request" }, | 
 | 51 | 	{ 0x0101,	"configure response" }, | 
 | 52 | 	{ 0x0002,	"join request" }, | 
 | 53 | 	{ 0x0102,	"join response" }, | 
 | 54 | 	{ 0x0003,	"ready query" }, | 
 | 55 | 	{ 0x0103,	"ready indication" }, | 
 | 56 | 	{ 0x0004,	"register request" }, | 
 | 57 | 	{ 0x0104,	"register response" }, | 
 | 58 | 	{ 0x0005,	"unregister request" }, | 
 | 59 | 	{ 0x0105,	"unregister response" }, | 
 | 60 | 	{ 0x0006,	"ARP request" }, | 
 | 61 | 	{ 0x0106,	"ARP response" }, | 
 | 62 | 	{ 0x0007,	"flush request" }, | 
 | 63 | 	{ 0x0107,	"flush response" }, | 
 | 64 | 	{ 0x0008,	"NARP request" }, | 
 | 65 | 	{ 0x0009,	"topology request" }, | 
 | 66 | 	{ 0,		NULL } | 
 | 67 | }; | 
 | 68 |  | 
| JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 69 | static void | 
 | 70 | lane_hdr_print(netdissect_options *ndo, const u_char *bp) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 71 | { | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 72 | 	ND_PRINT((ndo, "lecid:%x ", EXTRACT_16BITS(bp))); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 73 | } | 
 | 74 |  | 
 | 75 | /* | 
 | 76 |  * This is the top level routine of the printer.  'p' points | 
 | 77 |  * to the LANE header of the packet, 'h->ts' is the timestamp, | 
 | 78 |  * 'h->len' is the length of the packet off the wire, and 'h->caplen' | 
 | 79 |  * is the number of bytes actually captured. | 
 | 80 |  * | 
 | 81 |  * This assumes 802.3, not 802.5, LAN emulation. | 
 | 82 |  */ | 
 | 83 | void | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 84 | lane_print(netdissect_options *ndo, const u_char *p, u_int length, u_int caplen) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 85 | { | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 86 | 	const struct lane_controlhdr *lec; | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 87 |  | 
 | 88 | 	if (caplen < sizeof(struct lane_controlhdr)) { | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 89 | 		ND_PRINT((ndo, "[|lane]")); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 90 | 		return; | 
 | 91 | 	} | 
 | 92 |  | 
| Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 93 | 	lec = (const struct lane_controlhdr *)p; | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 94 | 	if (EXTRACT_16BITS(&lec->lec_header) == 0xff00) { | 
 | 95 | 		/* | 
 | 96 | 		 * LE Control. | 
 | 97 | 		 */ | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 98 | 		ND_PRINT((ndo, "lec: proto %x vers %x %s", | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 99 | 		    lec->lec_proto, lec->lec_vers, | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 100 | 		    tok2str(lecop2str, "opcode-#%u", EXTRACT_16BITS(&lec->lec_opcode)))); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 101 | 		return; | 
 | 102 | 	} | 
 | 103 |  | 
| JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 104 | 	/* | 
 | 105 | 	 * Go past the LE header. | 
 | 106 | 	 */ | 
 | 107 | 	length -= 2; | 
 | 108 | 	caplen -= 2; | 
 | 109 | 	p += 2; | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 110 |  | 
 | 111 | 	/* | 
| JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 112 | 	 * Now print the encapsulated frame, under the assumption | 
 | 113 | 	 * that it's an Ethernet frame. | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 114 | 	 */ | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 115 | 	ether_print(ndo, p, length, caplen, lane_hdr_print, p - 2); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 116 | } | 
 | 117 |  | 
 | 118 | u_int | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 119 | lane_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 120 | { | 
| Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 121 | 	lane_print(ndo, p, h->len, h->caplen); | 
| The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 122 |  | 
 | 123 | 	return (sizeof(struct lecdatahdr_8023)); | 
 | 124 | } |