1#ifndef GRUB_H
2#define GRUB_H
3
4#include "osdep.h"
5#include "byteswap.h"
6#include "in.h"
7#include "ip.h"
8#include "udp.h"
9#include "if_ether.h"
10#include "latch.h"
11#include "io.h"
12#include "nic.h"
13#include <shared.h>
14
15#define K_ESC		'\033'
16#define K_EOF		'\04'  /* Ctrl-D */
17#define K_INTR		'\03'  /* Ctrl-C */
18
19#ifndef	MAX_RPC_RETRIES
20#define MAX_RPC_RETRIES		20
21#endif
22
23
24/* Inter-packet retry in ticks */
25#ifndef TIMEOUT
26#define TIMEOUT			(10*TICKS_PER_SEC)
27#endif
28
29#ifndef	NULL
30#define NULL	((void *)0)
31#endif
32
33
34#define ARP_CLIENT	0
35#define ARP_SERVER	1
36#define ARP_GATEWAY	2
37#define MAX_ARP		ARP_GATEWAY+1
38
39#define IGMP_SERVER	0
40#define MAX_IGMP	IGMP_SERVER+1
41
42#define	RARP_REQUEST	3
43#define	RARP_REPLY	4
44
45
46#define MULTICAST_MASK    0xF0000000
47#define MULTICAST_NETWORK 0xE0000000
48
49struct arptable_t {
50	in_addr ipaddr;
51	uint8_t node[6];
52};
53
54struct igmptable_t {
55	in_addr group;
56	unsigned long time;
57};
58
59#define	KERNEL_BUF	(BOOTP_DATA_ADDR->bootp_reply.bp_file)
60
61#define	FLOPPY_BOOT_LOCATION	0x7c00
62/* Must match offsets in loader.S */
63#define ROM_SEGMENT		0x1fa
64#define ROM_LENGTH		0x1fc
65
66#define	ROM_INFO_LOCATION	(FLOPPY_BOOT_LOCATION+ROM_SEGMENT)
67/* at end of floppy boot block */
68
69
70
71/* Define a type for passing info to a loaded program */
72struct ebinfo {
73	uint8_t  major, minor;	/* Version */
74	uint16_t flags;		/* Bit flags */
75};
76
77/***************************************************************************
78External prototypes
79***************************************************************************/
80extern void rx_qdrain P((void));
81extern int tftp P((const char *name, int (*)(unsigned char *, unsigned int, unsigned int, int)));
82extern int ip_transmit P((int len, const void *buf));
83extern void build_ip_hdr P((unsigned long destip, int ttl, int protocol,
84	int option_len, int len, const void *buf));
85extern void build_udp_hdr P((unsigned long destip,
86	unsigned int srcsock, unsigned int destsock, int ttl,
87	int len, const void *buf));
88extern int udp_transmit P((unsigned long destip, unsigned int srcsock,
89	unsigned int destsock, int len, const void *buf));
90typedef int (*reply_t)(int ival, void *ptr, unsigned short ptype, struct iphdr *ip, struct udphdr *udp);
91extern int await_reply P((reply_t reply,	int ival, void *ptr, long timeout));
92extern int decode_rfc1533 P((unsigned char *, unsigned int, unsigned int, int));
93extern void join_group(int slot, unsigned long group);
94extern void leave_group(int slot);
95#define RAND_MAX 2147483647L
96extern uint16_t ipchksum P((const void *ip, unsigned long len));
97extern uint16_t add_ipchksums P((unsigned long offset, uint16_t sum, uint16_t new));
98extern int32_t random P((void));
99extern long rfc2131_sleep_interval P((long base, int exp));
100extern long rfc1112_sleep_interval P((long base, int exp));
101#ifndef DOWNLOAD_PROTO_TFTP
102#define	tftp(fname, load_block) 0
103#endif
104extern void cleanup P((void));
105
106/* misc.c */
107extern void twiddle P((void));
108extern void sleep P((int secs));
109extern void interruptible_sleep P((int secs));
110extern void poll_interruptions P((void));
111extern int strcasecmp P((const char *a, const char *b));
112extern char *substr P((const char *a, const char *b));
113extern unsigned long strtoul P((const char *p, const char **, int base));
114extern void printf P((const char *, ...));
115extern int sprintf P((char *, const char *, ...));
116extern int inet_aton P((char *p, in_addr *i));
117extern void putchar P((int));
118extern int getchar P((void));
119extern int iskey P((void));
120
121extern void grub_printf(const char *, ...);
122extern char config_file[128];
123extern void etherboot_printf(const char *,  ...);
124extern int etherboot_sprintf(char *, const char *, ...);
125extern int getdec(char **s);
126extern void cleanup_net(void);
127extern void print_network_configuration (void);
128extern int ifconfig (char *, char *, char *, char *);
129extern struct arptable_t arptable[MAX_ARP];
130
131#undef printf
132#undef sprintf
133#define printf etherboot_printf
134#define sprintf etherboot_sprintf
135
136#ifdef DEBUG
137#define EnterFunction(func) printf("Enter: " func "\n");
138#define LeaveFunction(func) printf("Leave: " func "\n");
139#else
140#define EnterFunction(func)
141#define LeaveFunction(func)
142#endif
143
144/*
145 * Some codes from etherboot use a level in DEBUG. Define it to be
146 * zero means no debug info output, that will make them silence in
147 * compiling. Up it as you want.
148 */
149#ifndef DEBUG
150#  define DEBUG 0
151#endif
152
153/*#define RPC_DEBUG*/
154
155extern char *hostname;
156
157extern int hostnamelen;
158/* Whether network is ready */
159extern int network_ready;
160
161/* User aborted in await_reply if not zero */
162extern int user_abort;
163
164extern int rarp(void);
165extern int grub_eth_probe(void);
166extern int bootp(void);
167
168extern int dhcp(void);
169
170extern struct nic nic;
171#endif /* GRUB_H */
172