xref: /minix/external/bsd/dhcp/dist/common/fddi.c (revision fb9c64b2)
1 /*	$NetBSD: fddi.c,v 1.1.1.2 2014/07/12 11:57:44 spz Exp $	*/
2 /* fddi.c
3 
4    Packet assembly code, originally contributed by Archie Cobbs. */
5 
6 /*
7  * Copyright (c) 2004,2007,2009,2014 by Internet Systems Consortium, Inc. ("ISC")
8  * Copyright (c) 1996-2003 by Internet Software Consortium
9  *
10  * Permission to use, copy, modify, and distribute this software for any
11  * purpose with or without fee is hereby granted, provided that the above
12  * copyright notice and this permission notice appear in all copies.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
15  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
17  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
20  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  *
22  *   Internet Systems Consortium, Inc.
23  *   950 Charter Street
24  *   Redwood City, CA 94063
25  *   <info@isc.org>
26  *   https://www.isc.org/
27  *
28  */
29 
30 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: fddi.c,v 1.1.1.2 2014/07/12 11:57:44 spz Exp $");
32 
33 #include "dhcpd.h"
34 
35 #if defined (DEC_FDDI)
36 #include <netinet/if_fddi.h>
37 #include <net/if_llc.h>
38 
39 #if defined (PACKET_ASSEMBLY) || defined (PACKET_DECODING)
40 #include "includes/netinet/if_ether.h"
41 #endif /* PACKET_ASSEMBLY || PACKET_DECODING */
42 
43 #if defined (PACKET_ASSEMBLY)
44 /* Assemble an hardware header... */
45 
46 void assemble_fddi_header (interface, buf, bufix, to)
47 	struct interface_info *interface;
48 	unsigned char *buf;
49 	unsigned *bufix;
50 	struct hardware *to;
51 {
52 	struct fddi_header   fh;
53 	struct llc     lh;
54 
55 	if (to && to -> hlen == 7)
56 		memcpy (fh.fddi_dhost, &to -> hbuf [1],
57 			sizeof (fh.fddi_dhost));
58 	memcpy (fh.fddi_shost,
59 		&interface -> hw_address.hbuf [1], sizeof (fh.fddi_shost));
60 	fh.fddi_fc = FDDIFC_LLC_ASYNC;
61 	memcpy (&buf [*bufix], &fh, sizeof fh);
62 	*bufix += sizeof fh;
63 
64 	lh.llc_dsap = LLC_SNAP_LSAP;
65 	lh.llc_ssap = LLC_SNAP_LSAP;
66 	lh.llc_un.type_snap.control = LLC_UI;
67 	lh.llc_un.type_snap.ether_type = htons (ETHERTYPE_IP);
68 	memcpy (&buf [*bufix], &lh, LLC_SNAP_LEN);
69 	*bufix += LLC_SNAP_LEN;
70 }
71 #endif /* PACKET_ASSEMBLY */
72 
73 #ifdef PACKET_DECODING
74 /* Decode a hardware header... */
75 
76 ssize_t decode_fddi_header (interface, buf, bufix, from)
77      struct interface_info *interface;
78      unsigned char *buf;
79      unsigned bufix;
80      struct hardware *from;
81 {
82 	struct fddi_header   fh;
83 	struct llc     lh;
84 
85 	from -> hbuf [0] = HTYPE_FDDI;
86 	memcpy (&from -> hbuf [1], fh.fddi_shost, sizeof fh.fddi_shost);
87 	return FDDI_HEADER_SIZE + LLC_SNAP_LEN;
88 }
89 #endif /* PACKET_DECODING */
90 #endif /* DEC_FDDI */
91