xref: /netbsd-src/sys/arch/mvme68k/stand/sboot/etherfun.h (revision bbde328be4e75ea9ad02e9715ea13ca54b797ada)
1 /*	$NetBSD: etherfun.h,v 1.4 2008/01/12 09:54:33 tsutsui Exp $	*/
2 
3 /*
4  *
5  * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Charles D. Cranor
19  *	and Seth Widoff.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 /* etherfun.h */
35 
36 /* constants */
37 /* ether header */
38 #define ETYPE_RARP 0x8035  /* ethertype is RARP */
39 #define ETYPE_IP   0x800   /* ethertype is IP   */
40 
41 /* rev arp */
42 #define PTYPE_IP 0x800     /* Protocol type is IP      */
43 #define OPCODE_RARP 3      /* Optype is REVARP request */
44 #define OPCODE_REPLY 4     /* Optype is REVARP reply   */
45 
46 /* ip header */
47 #define  IPP_UDP 17        /* IP Protocol is UDP       */
48 #define  IP_VERSION 4      /* IP version number        */
49 #define  IP_HLEN 5         /* IP header length is a fixed 50 bytes */
50 #define N 1536
51 
52 /* tftp header */
53 #define FTPOP_ACKN 4      /* Opcode is acknowledge     */
54 #define FTPOP_ERR 5       /* Opcode is Error	       */
55 #define FTP_PORT 69       /* Standard TFTP port number */
56 #define MSG "\0\1xxxxxxxx.147\0octet\0" /* implicit NULL */
57 
58 /* data structures */
59 
60 struct  ether_header {
61 	u_char  ether_dhost[6];
62 	u_char  ether_shost[6];
63 	u_short ether_type;
64 };
65 
66 struct  ether_arp {
67 	u_short ar_hrd;		/* format of hardware address */
68 	u_short ar_pro;		/* format of protocol address */
69 	u_char  ar_hln;		/* length of hardware address */
70 	u_char  ar_pln;		/* length of protocol address */
71 	u_short ar_op;
72 	u_char  arp_sha[6];	/* sender hardware address */
73 	u_char  arp_spa[4];	/* sender protocol address */
74 	u_char  arp_tha[6];	/* target hardware address */
75 	u_char  arp_tpa[4];	/* target protocol address */
76 };
77 
78 struct ip {
79 	u_char  ip_v:4,			/* version */
80 		ip_hl:4;		/* header length */
81 	u_char  ip_tos;			/* type of service */
82 	short   ip_len;			/* total length */
83 	u_short ip_id;			/* identification */
84 	short   ip_off;			/* fragment offset field */
85 #define IP_DF 0x4000			/* dont fragment flag */
86 #define IP_MF 0x2000			/* more fragments flag */
87 #define IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
88 	u_char  ip_ttl;			/* time to live */
89 	u_char  ip_p;			/* protocol */
90 	u_short ip_sum;			/* checksum */
91 	u_char  ip_src[4];
92 	u_char  ip_dst[4];		/* source and dest address */
93 };
94 
95 struct udp {
96 	u_short uh_sport;
97 	u_short uh_dport;
98 	short uh_ulen;
99 	u_short uh_sum;
100 };
101 
102 struct tftph {
103 	u_short op_code;
104 	u_short block;
105 };
106 
107 struct tftphr {
108 	struct tftph info;
109 	char data[1];
110 };
111 
112 /* globals */
113 int last_ack;
114 u_char buf[N];
115 struct ether_header *eh = (struct ether_header *)buf;
116 struct ether_arp *rarp =
117     (struct ether_arp *)(buf + sizeof(struct ether_header));
118 struct ip *iph = (struct ip *)(buf + sizeof(struct ether_header));
119 struct udp *udph = (struct udp *)(buf + sizeof(struct ether_header) +
120     sizeof(struct ip));
121 u_char *tftp_r = buf + sizeof(struct ether_header) + sizeof(struct ip) +
122     sizeof(struct udp);
123 struct tftph *tftp_a = (struct tftph *)(buf + sizeof(struct ether_header) +
124     sizeof(struct ip) + sizeof(struct udp));
125 struct tftphr *tftp = (struct tftphr *)(buf + sizeof(struct ether_header) +
126     sizeof(struct ip) + sizeof(struct udp));
127