FreeBSD/Linux Kernel Cross Reference
sys/ttd/ttd_comm.h
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993,1992 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * TTD Communications parsing code's header file.
28 *
29 * HISTORY:
30 * $Log: ttd_comm.h,v $
31 * Revision 2.2 93/05/10 23:24:37 rvb
32 * Checkin for MK80 branch.
33 * [93/05/10 15:07:45 grm]
34 *
35 * Revision 2.1.2.2 93/04/20 10:51:53 grm
36 * Added support for multiple endian archs. Changed some of the
37 * types for a more universal protocol. Moved some of the sln.h
38 * code into here.
39 * [93/04/20 grm]
40 *
41 * Revision 2.1.2.1 93/03/03 14:35:40 grm
42 * Changed the interface. Version works.
43 * [93/03/03 grm]
44 *
45 * Revision 2.1.1.2 93/01/28 15:21:56 grm
46 * Added prototypes.
47 *
48 * Revision 2.1.1.1 92/09/15 18:27:37 grm
49 * Initial checkin.
50 *
51 */
52 /***********************************************************
53 Copyright 1992 by Digital Equipment Corporation, Maynard, Massachusetts,
54
55 All Rights Reserved
56
57 Permission to use, copy, modify, and distribute this software and its
58 documentation for any purpose and without fee is hereby granted, provided
59 that the above copyright notice appear in all copies and that both that
60 copyright notice and this permission notice appear in supporting
61 documentation, and that the name of Digital not be used in advertising
62 or publicity pertaining to distribution of the software without specific,
63 written prior permission. Digital makes no representations about the
64 suitability of this software for any purpose. It is provided "as is"
65 without express or implied warranty.
66
67 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
68 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
69 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
70 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
71 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
72 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
73 SOFTWARE.
74
75 ******************************************************************/
76
77 #ifndef _TTD_COMM_H_
78 #define _TTD_COMM_H_
79
80 #include <mach/boolean.h>
81 #include <mach/mach_types.h>
82 #include <device/if_ether.h>
83 #include <ttd/ttd_msg.h>
84
85
86 /* Packet-type codes in Ethernet packets, in network order. */
87 #if BYTE_MSF
88 #define ETHERTYPE_IP 0x0800
89 #define ETHERTYPE_ARP 0x0806
90 #define ETHERTYPE_RARP 0x8035
91 #else
92 #define ETHERTYPE_IP 0x0008
93 #define ETHERTYPE_ARP 0x0608
94 #define ETHERTYPE_RARP 0x3580
95 #endif /* BYTE_MSF */
96
97 /* Type/operation codes in ARP/RARP packets, in network order. */
98 #if BYTE_MSF
99 #define ARPTYPE_ETHER 0x0001
100 #define ARPOP_REQUEST 0x0001
101 #define ARPOP_REPLY 0x0002
102 #define RARPOP_REQUEST 0x0003
103 #define RARPOP_REPLY 0x0004
104 #else
105 #define ARPTYPE_ETHER 0x0100
106 #define ARPOP_REQUEST 0x0100
107 #define ARPOP_REPLY 0x0200
108 #define RARPOP_REQUEST 0x0300
109 #define RARPOP_REPLY 0x0400
110 #endif /* BYTE_MSF */
111
112
113 #define ETHER_HTYPE 1
114
115 /* UDP Port for TTD protocol, in network order. */
116 #if BYTE_MSF
117 #define TTD_PORT 0x8765
118 #else
119 #define TTD_PORT 0x6587
120 #endif /* BYTE_MSF */
121
122 /* 1-byte packet-type code in IP packets. */
123 #define PROTOCOL_UDP 17
124
125 typedef unsigned char byte_t;
126 typedef unsigned short half_word_t;
127
128
129 /**************************************/
130 /* Ethernet-related declarations */
131 /**************************************/
132
133 struct ether_hardware_address { /* Ethernet address, in network order */
134 unsigned char array[6];
135 };
136
137 #define ETHER_ADDRESS_EQ(x,y) ( \
138 ((x)->array[0] == (y)->array[0]) && ((x)->array[1] == (y)->array[1]) \
139 && ((x)->array[2] == (y)->array[2]) && ((x)->array[3] == (y)->array[3]) \
140 && ((x)->array[4] == (y)->array[4]) && ((x)->array[5] == (y)->array[5]))
141
142 struct ethernet_header { /* header of an ethernet packet */
143 struct ether_hardware_address dest_uid;
144 struct ether_hardware_address srce_uid;
145 short type;
146 };
147
148 #define MAX_ETHER_DATA (1600 - sizeof (struct ethernet_header))
149
150 typedef half_word_t protocol_t;
151
152 struct ttd_ether_header {
153 struct ether_hardware_address dest;
154 struct ether_hardware_address source;
155 protocol_t protocol;
156 };
157
158 #define ETHER_ADDRESS_LENGTH sizeof(struct ether_hardware_address)
159 #define ETHER_HEADER_LENGTH sizeof(struct ttd_ether_header)
160 #define MIN_PACKET 60
161
162
163 /************************************/
164 /* IP-related declarations */
165 /************************************/
166
167 struct ip_address {
168 unsigned char array[4];
169 };
170
171 #define IP_ADDRESS_LENGTH sizeof(struct ip_address)
172
173 struct ip_header { /* Network order */
174 #if BYTE_MSF
175 byte_t version :4;
176 byte_t header_words :4;
177 #else
178 byte_t header_words :4;
179 byte_t version :4;
180 #endif /* BYTE_MSF */
181 byte_t type_of_service;
182 half_word_t length;
183 half_word_t id;
184 half_word_t fragment_stuff;
185 byte_t time_to_live;
186 byte_t protocol;
187 half_word_t header_checksum;
188 struct ip_address source;
189 struct ip_address dest;
190 };
191
192 #define MAX_IP_DATA (MAX_ETHER_DATA - sizeof(struct ip_header))
193
194 typedef union {
195 struct ip_header hdr;
196 unsigned short data[1];
197 /* Options opt; -- CAUTION: variable amount of stuff in here!! */
198 /* IPData data; */
199 } ip_packet_t;
200
201 #define OUT_IP_HEADER_BYTES sizeof(struct ip_header) /* No options sent */
202 #define OUT_IP_HEADER_WORDS (OUT_IP_HEADER_BYTES / 4)
203
204
205 /******************************************/
206 /* ARP/RARP-related declarations */
207 /******************************************/
208
209 typedef byte_t length_byte_t;
210
211 struct arp_packet { /* Network order, used for ARP */
212 protocol_t hardware_addr_type;
213 protocol_t protocol_addr_type;
214 length_byte_t hardware_addr_length;
215 length_byte_t protocol_addr_length;
216 half_word_t arp_opcode;
217 /* IPForward, IPReverse: */
218 struct {
219 struct ether_hardware_address source_hardware_addr;
220 struct ip_address source_protocol_addr;
221 struct ether_hardware_address dest_hardware_addr;
222 struct ip_address dest_protocol_addr;
223 } ip;
224 };
225
226 struct arpether_packet {
227 struct ttd_ether_header eh;
228 struct arp_packet arp;
229 };
230
231 typedef struct arpether_packet *arpether_packet_t;
232 typedef struct arp_packet *arp_packet_t;
233
234
235 /*************************************/
236 /* UDP-related declarations */
237 /*************************************/
238
239 struct udp_header { /* Network order, direct from DMA */
240 half_word_t source_port;
241 half_word_t dest_port;
242 half_word_t length;
243 half_word_t checksum;
244 };
245
246 #define MAX_UDP_DATA (MAX_IP_DATA - sizeof(struct udp_header))
247
248 typedef byte_t udp_data_t[MAX_UDP_DATA];
249
250 struct udp_packet {
251 struct udp_header hdr;
252 udp_data_t data;
253 };
254
255 typedef struct udp_packet *udp_packet_t;
256
257 struct udp_pseudo_header { /* All multi-byte fields in network order! */
258 struct ip_address source;
259 struct ip_address dest;
260 byte_t zero;
261 byte_t protocol;
262 half_word_t udp_length;
263 };
264
265
266 /*************************************/
267 /* BOOTP-related declarations */
268 /*************************************/
269
270 struct bootp {
271 u_char bp_op; /* packet opcode type */
272 #define BOOTREQUEST 1
273 #define BOOTREPLY 2
274 u_char bp_htype; /* hardware addr type */
275 u_char bp_hlen; /* hardware addr length */
276 u_char bp_hops; /* gateway hops */
277 u_char bp_xid[4]; /* transaction ID */
278 u_short bp_secs; /* seconds since boot began */
279 u_short bp_unused;
280 struct ip_address bp_ciaddr; /* client IP address */
281 struct ip_address bp_yiaddr; /* 'your' IP address */
282 struct ip_address bp_siaddr; /* server IP address */
283 struct ip_address bp_giaddr; /* gateway IP address */
284 u_char bp_chaddr[16]; /* client hardware address */
285 u_char bp_sname[64]; /* server host name */
286 u_char bp_file[128]; /* boot file name */
287 u_char bp_vend[64]; /* vendor-specific area */
288 };
289
290 typedef struct bootp * bootp_t;
291
292 struct udpip_packet {
293 struct ip_header ip_h;
294 struct udp_header udp_h;
295 };
296
297 struct recbootp {
298 struct udpip_packet ui;
299 char bpbuf[300]; /* hack for alignment */
300
301 };
302
303 struct sndbootp {
304 struct ttd_ether_header eh; /* ether header */
305 struct udpip_packet ui; /* ip/udp header */
306 char bpbuf[300]; /* hack for alignment */
307 };
308
309 typedef struct recbootp * recbootp_t;
310 typedef struct sndbootp * sndbootp_t;
311
312 #define BOOTPMSG_SIZE sizeof(struct sndbootp)
313 #define BOOTPMAX_TRIES 5
314
315 /*
316 * UDP port numbers, server and client.
317 */
318 #define UDP_BOOTPS 67
319 #define UDP_BOOTPC 68
320
321 /*
322 * Make available our own byteswapping routines. Got bit by
323 * this once, but not twice dammit!
324 */
325 #if BYTE_MSF
326 #define netswap_2_bytes(n) n
327 #define netswap_4_bytes(n) n
328 #else
329 extern u_short netswap_2_bytes(u_short n);
330 extern uint32 netswap_4_bytes(uint32 n);
331 #endif /* BYTE_MSF */
332
333 /*
334 * Prototype definitions:
335 */
336 extern boolean_t ttd_ip_bootp(void);
337 extern boolean_t kttd_valid_request(ipc_kmsg_t request,
338 boolean_t handle_arp,
339 vm_address_t *ttd_data,
340 natural_t *request_length);
341 extern boolean_t kttd_get_request(vm_address_t *ttd_request,
342 natural_t *request_length);
343 extern ttd_reply_t skip_net_headers(char * ptr);
344 extern void complete_and_send_ttd_reply(natural_t kttd_reply_length);
345
346 #endif /* _TTD_COMM_H_ */
Cache object: 6e3b82d467b66cef3d069cf9db82e7ee
|