1*05b00f60SXin Li /*
2*05b00f60SXin Li * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
3*05b00f60SXin Li * The Regents of the University of California. All rights reserved.
4*05b00f60SXin Li *
5*05b00f60SXin Li * Redistribution and use in source and binary forms, with or without
6*05b00f60SXin Li * modification, are permitted provided that: (1) source code distributions
7*05b00f60SXin Li * retain the above copyright notice and this paragraph in its entirety, (2)
8*05b00f60SXin Li * distributions including binary code include the above copyright notice and
9*05b00f60SXin Li * this paragraph in its entirety in the documentation or other materials
10*05b00f60SXin Li * provided with the distribution, and (3) all advertising materials mentioning
11*05b00f60SXin Li * features or use of this software display the following acknowledgement:
12*05b00f60SXin Li * ``This product includes software developed by the University of California,
13*05b00f60SXin Li * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*05b00f60SXin Li * the University nor the names of its contributors may be used to endorse
15*05b00f60SXin Li * or promote products derived from this software without specific prior
16*05b00f60SXin Li * written permission.
17*05b00f60SXin Li * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*05b00f60SXin Li * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*05b00f60SXin Li * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*05b00f60SXin Li */
21*05b00f60SXin Li
22*05b00f60SXin Li /* \summary: Apple IP-over-IEEE 1394 printer */
23*05b00f60SXin Li
24*05b00f60SXin Li #ifdef HAVE_CONFIG_H
25*05b00f60SXin Li #include <config.h>
26*05b00f60SXin Li #endif
27*05b00f60SXin Li
28*05b00f60SXin Li #include "netdissect-stdinc.h"
29*05b00f60SXin Li
30*05b00f60SXin Li #define ND_LONGJMP_FROM_TCHECK
31*05b00f60SXin Li #include "netdissect.h"
32*05b00f60SXin Li #include "extract.h"
33*05b00f60SXin Li #include "addrtoname.h"
34*05b00f60SXin Li #include "ethertype.h"
35*05b00f60SXin Li
36*05b00f60SXin Li /*
37*05b00f60SXin Li * Structure of a header for Apple's IP-over-IEEE 1384 BPF header.
38*05b00f60SXin Li */
39*05b00f60SXin Li #define FIREWIRE_EUI64_LEN 8
40*05b00f60SXin Li struct firewire_header {
41*05b00f60SXin Li nd_byte firewire_dhost[FIREWIRE_EUI64_LEN];
42*05b00f60SXin Li nd_byte firewire_shost[FIREWIRE_EUI64_LEN];
43*05b00f60SXin Li nd_uint16_t firewire_type;
44*05b00f60SXin Li };
45*05b00f60SXin Li
46*05b00f60SXin Li /*
47*05b00f60SXin Li * Length of that header; note that some compilers may pad
48*05b00f60SXin Li * "struct firewire_header" to a multiple of 4 bytes, for example, so
49*05b00f60SXin Li * "sizeof (struct firewire_header)" may not give the right answer.
50*05b00f60SXin Li */
51*05b00f60SXin Li #define FIREWIRE_HDRLEN 18
52*05b00f60SXin Li
53*05b00f60SXin Li static const char *
fwaddr_string(netdissect_options * ndo,const u_char * addr)54*05b00f60SXin Li fwaddr_string(netdissect_options *ndo, const u_char *addr)
55*05b00f60SXin Li {
56*05b00f60SXin Li return GET_LINKADDR_STRING(addr, LINKADDR_IEEE1394, FIREWIRE_EUI64_LEN);
57*05b00f60SXin Li }
58*05b00f60SXin Li
59*05b00f60SXin Li static void
ap1394_hdr_print(netdissect_options * ndo,const u_char * bp,u_int length)60*05b00f60SXin Li ap1394_hdr_print(netdissect_options *ndo, const u_char *bp, u_int length)
61*05b00f60SXin Li {
62*05b00f60SXin Li const struct firewire_header *fp;
63*05b00f60SXin Li uint16_t firewire_type;
64*05b00f60SXin Li
65*05b00f60SXin Li fp = (const struct firewire_header *)bp;
66*05b00f60SXin Li
67*05b00f60SXin Li ND_PRINT("%s > %s",
68*05b00f60SXin Li fwaddr_string(ndo, fp->firewire_shost),
69*05b00f60SXin Li fwaddr_string(ndo, fp->firewire_dhost));
70*05b00f60SXin Li
71*05b00f60SXin Li firewire_type = GET_BE_U_2(fp->firewire_type);
72*05b00f60SXin Li if (!ndo->ndo_qflag) {
73*05b00f60SXin Li ND_PRINT(", ethertype %s (0x%04x)",
74*05b00f60SXin Li tok2str(ethertype_values,"Unknown", firewire_type),
75*05b00f60SXin Li firewire_type);
76*05b00f60SXin Li } else {
77*05b00f60SXin Li ND_PRINT(", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", firewire_type));
78*05b00f60SXin Li }
79*05b00f60SXin Li
80*05b00f60SXin Li ND_PRINT(", length %u: ", length);
81*05b00f60SXin Li }
82*05b00f60SXin Li
83*05b00f60SXin Li /*
84*05b00f60SXin Li * This is the top level routine of the printer. 'p' points
85*05b00f60SXin Li * to the ether header of the packet, 'h->ts' is the timestamp,
86*05b00f60SXin Li * 'h->len' is the length of the packet off the wire, and 'h->caplen'
87*05b00f60SXin Li * is the number of bytes actually captured.
88*05b00f60SXin Li */
89*05b00f60SXin Li void
ap1394_if_print(netdissect_options * ndo,const struct pcap_pkthdr * h,const u_char * p)90*05b00f60SXin Li ap1394_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
91*05b00f60SXin Li {
92*05b00f60SXin Li u_int length = h->len;
93*05b00f60SXin Li u_int caplen = h->caplen;
94*05b00f60SXin Li const struct firewire_header *fp;
95*05b00f60SXin Li u_short ether_type;
96*05b00f60SXin Li struct lladdr_info src, dst;
97*05b00f60SXin Li
98*05b00f60SXin Li ndo->ndo_protocol = "ap1394";
99*05b00f60SXin Li ND_TCHECK_LEN(p, FIREWIRE_HDRLEN);
100*05b00f60SXin Li ndo->ndo_ll_hdr_len += FIREWIRE_HDRLEN;
101*05b00f60SXin Li
102*05b00f60SXin Li if (ndo->ndo_eflag)
103*05b00f60SXin Li ap1394_hdr_print(ndo, p, length);
104*05b00f60SXin Li
105*05b00f60SXin Li length -= FIREWIRE_HDRLEN;
106*05b00f60SXin Li caplen -= FIREWIRE_HDRLEN;
107*05b00f60SXin Li fp = (const struct firewire_header *)p;
108*05b00f60SXin Li p += FIREWIRE_HDRLEN;
109*05b00f60SXin Li
110*05b00f60SXin Li ether_type = GET_BE_U_2(fp->firewire_type);
111*05b00f60SXin Li src.addr = fp->firewire_shost;
112*05b00f60SXin Li src.addr_string = fwaddr_string;
113*05b00f60SXin Li dst.addr = fp->firewire_dhost;
114*05b00f60SXin Li dst.addr_string = fwaddr_string;
115*05b00f60SXin Li if (ethertype_print(ndo, ether_type, p, length, caplen, &src, &dst) == 0) {
116*05b00f60SXin Li /* ether_type not known, print raw packet */
117*05b00f60SXin Li if (!ndo->ndo_eflag)
118*05b00f60SXin Li ap1394_hdr_print(ndo, (const u_char *)fp, length + FIREWIRE_HDRLEN);
119*05b00f60SXin Li
120*05b00f60SXin Li if (!ndo->ndo_suppress_default_print)
121*05b00f60SXin Li ND_DEFAULTPRINT(p, caplen);
122*05b00f60SXin Li }
123*05b00f60SXin Li }
124