xref: /freebsd/contrib/tcpdump/print-ap1394.c (revision 0a7e5f1f02aad2ff5fff1c60f44c6975fd07e1d9)
15b0fe478SBruce M Simpson /*
25b0fe478SBruce M Simpson  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
35b0fe478SBruce M Simpson  *	The Regents of the University of California.  All rights reserved.
45b0fe478SBruce M Simpson  *
55b0fe478SBruce M Simpson  * Redistribution and use in source and binary forms, with or without
65b0fe478SBruce M Simpson  * modification, are permitted provided that: (1) source code distributions
75b0fe478SBruce M Simpson  * retain the above copyright notice and this paragraph in its entirety, (2)
85b0fe478SBruce M Simpson  * distributions including binary code include the above copyright notice and
95b0fe478SBruce M Simpson  * this paragraph in its entirety in the documentation or other materials
105b0fe478SBruce M Simpson  * provided with the distribution, and (3) all advertising materials mentioning
115b0fe478SBruce M Simpson  * features or use of this software display the following acknowledgement:
125b0fe478SBruce M Simpson  * ``This product includes software developed by the University of California,
135b0fe478SBruce M Simpson  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
145b0fe478SBruce M Simpson  * the University nor the names of its contributors may be used to endorse
155b0fe478SBruce M Simpson  * or promote products derived from this software without specific prior
165b0fe478SBruce M Simpson  * written permission.
175b0fe478SBruce M Simpson  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
185b0fe478SBruce M Simpson  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
195b0fe478SBruce M Simpson  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
205b0fe478SBruce M Simpson  */
215b0fe478SBruce M Simpson 
223340d773SGleb Smirnoff /* \summary: Apple IP-over-IEEE 1394 printer */
233340d773SGleb Smirnoff 
24*ee67461eSJoseph Mingrone #include <config.h>
255b0fe478SBruce M Simpson 
26*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
275b0fe478SBruce M Simpson 
28*ee67461eSJoseph Mingrone #define ND_LONGJMP_FROM_TCHECK
293340d773SGleb Smirnoff #include "netdissect.h"
3027df3f5dSRui Paulo #include "extract.h"
315b0fe478SBruce M Simpson #include "addrtoname.h"
325b0fe478SBruce M Simpson #include "ethertype.h"
335b0fe478SBruce M Simpson 
345b0fe478SBruce M Simpson /*
355b0fe478SBruce M Simpson  * Structure of a header for Apple's IP-over-IEEE 1384 BPF header.
365b0fe478SBruce M Simpson  */
375b0fe478SBruce M Simpson #define FIREWIRE_EUI64_LEN	8
385b0fe478SBruce M Simpson struct firewire_header {
39*ee67461eSJoseph Mingrone 	nd_byte     firewire_dhost[FIREWIRE_EUI64_LEN];
40*ee67461eSJoseph Mingrone 	nd_byte     firewire_shost[FIREWIRE_EUI64_LEN];
41*ee67461eSJoseph Mingrone 	nd_uint16_t firewire_type;
425b0fe478SBruce M Simpson };
435b0fe478SBruce M Simpson 
445b0fe478SBruce M Simpson /*
455b0fe478SBruce M Simpson  * Length of that header; note that some compilers may pad
465b0fe478SBruce M Simpson  * "struct firewire_header" to a multiple of 4 bytes, for example, so
475b0fe478SBruce M Simpson  * "sizeof (struct firewire_header)" may not give the right answer.
485b0fe478SBruce M Simpson  */
495b0fe478SBruce M Simpson #define FIREWIRE_HDRLEN		18
505b0fe478SBruce M Simpson 
513340d773SGleb Smirnoff static const char *
fwaddr_string(netdissect_options * ndo,const u_char * addr)523340d773SGleb Smirnoff fwaddr_string(netdissect_options *ndo, const u_char *addr)
533340d773SGleb Smirnoff {
54*ee67461eSJoseph Mingrone 	return GET_LINKADDR_STRING(addr, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN);
553340d773SGleb Smirnoff }
563340d773SGleb Smirnoff 
57*ee67461eSJoseph Mingrone static void
ap1394_hdr_print(netdissect_options * ndo,const u_char * bp,u_int length)58*ee67461eSJoseph Mingrone ap1394_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
595b0fe478SBruce M Simpson {
60*ee67461eSJoseph Mingrone 	const struct firewire_header *fp;
613c602fabSXin LI 	uint16_t firewire_type;
6227df3f5dSRui Paulo 
635b0fe478SBruce M Simpson 	fp = (const struct firewire_header *)bp;
645b0fe478SBruce M Simpson 
65*ee67461eSJoseph Mingrone 	ND_PRINT("%s > %s",
663340d773SGleb Smirnoff 		     fwaddr_string(ndo, fp->firewire_shost),
67*ee67461eSJoseph Mingrone 		     fwaddr_string(ndo, fp->firewire_dhost));
685b0fe478SBruce M Simpson 
69*ee67461eSJoseph Mingrone 	firewire_type = GET_BE_U_2(fp->firewire_type);
703c602fabSXin LI 	if (!ndo->ndo_qflag) {
71*ee67461eSJoseph Mingrone 		ND_PRINT(", ethertype %s (0x%04x)",
7227df3f5dSRui Paulo 			       tok2str(ethertype_values,"Unknown", firewire_type),
73*ee67461eSJoseph Mingrone                                firewire_type);
745b0fe478SBruce M Simpson         } else {
75*ee67461eSJoseph Mingrone                 ND_PRINT(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", firewire_type));
765b0fe478SBruce M Simpson         }
775b0fe478SBruce M Simpson 
78*ee67461eSJoseph Mingrone 	ND_PRINT(", length %u: ", length);
795b0fe478SBruce M Simpson }
805b0fe478SBruce M Simpson 
815b0fe478SBruce M Simpson /*
825b0fe478SBruce M Simpson  * This is the top level routine of the printer.  'p' points
835b0fe478SBruce M Simpson  * to the ether header of the packet, 'h->ts' is the timestamp,
841de50e9fSSam Leffler  * 'h->len' is the length of the packet off the wire, and 'h->caplen'
855b0fe478SBruce M Simpson  * is the number of bytes actually captured.
865b0fe478SBruce M Simpson  */
87*ee67461eSJoseph Mingrone void
ap1394_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)883c602fabSXin LI ap1394_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
895b0fe478SBruce M Simpson {
905b0fe478SBruce M Simpson 	u_int length = h->len;
915b0fe478SBruce M Simpson 	u_int caplen = h->caplen;
923340d773SGleb Smirnoff 	const struct firewire_header *fp;
935b0fe478SBruce M Simpson 	u_short ether_type;
943340d773SGleb Smirnoff 	struct lladdr_info src, dst;
955b0fe478SBruce M Simpson 
96*ee67461eSJoseph Mingrone 	ndo->ndo_protocol = "ap1394";
97*ee67461eSJoseph Mingrone 	ND_TCHECK_LEN(p, FIREWIRE_HDRLEN);
98*ee67461eSJoseph Mingrone 	ndo->ndo_ll_hdr_len += FIREWIRE_HDRLEN;
995b0fe478SBruce M Simpson 
1003c602fabSXin LI 	if (ndo->ndo_eflag)
1013c602fabSXin LI 		ap1394_hdr_print(ndo, p, length);
1025b0fe478SBruce M Simpson 
1035b0fe478SBruce M Simpson 	length -= FIREWIRE_HDRLEN;
1045b0fe478SBruce M Simpson 	caplen -= FIREWIRE_HDRLEN;
1053340d773SGleb Smirnoff 	fp = (const struct firewire_header *)p;
1065b0fe478SBruce M Simpson 	p += FIREWIRE_HDRLEN;
1075b0fe478SBruce M Simpson 
108*ee67461eSJoseph Mingrone 	ether_type = GET_BE_U_2(fp->firewire_type);
1093340d773SGleb Smirnoff 	src.addr = fp->firewire_shost;
1103340d773SGleb Smirnoff 	src.addr_string = fwaddr_string;
1113340d773SGleb Smirnoff 	dst.addr = fp->firewire_dhost;
1123340d773SGleb Smirnoff 	dst.addr_string = fwaddr_string;
1133340d773SGleb Smirnoff 	if (ethertype_print(ndo, ether_type, p, length, caplen, &src, &dst) == 0) {
1145b0fe478SBruce M Simpson 		/* ether_type not known, print raw packet */
1153c602fabSXin LI 		if (!ndo->ndo_eflag)
1163340d773SGleb Smirnoff 			ap1394_hdr_print(ndo, (const u_char *)fp, length + FIREWIRE_HDRLEN);
1175b0fe478SBruce M Simpson 
1183c602fabSXin LI 		if (!ndo->ndo_suppress_default_print)
1193c602fabSXin LI 			ND_DEFAULTPRINT(p, caplen);
1205b0fe478SBruce M Simpson 	}
1215b0fe478SBruce M Simpson }
122