Adding upstream version 4.00~pre53+dfsg.
[syslinux-debian/hramrach.git] / core / fs / pxe / pxe.h
blobcad6350775bab6e452d76b510bcc2c3f179eb295
1 /* -----------------------------------------------------------------------
3 * Copyright 1999-2008 H. Peter Anvin - All Rights Reserved
4 * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 * Boston MA 02111-1307, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * ----------------------------------------------------------------------- */
15 * pxe.h
17 * PXE opcodes
20 #ifndef PXE_H
21 #define PXE_H
23 #include <syslinux/pxe_api.h>
24 #include "fs.h" /* For MAX_OPEN, should go away */
27 * Some basic defines...
29 #define TFTP_PORT htons(69) /* Default TFTP port */
30 #define TFTP_BLOCKSIZE_LG2 9
31 #define TFTP_BLOCKSIZE (1 << TFTP_BLOCKSIZE_LG2)
32 #define PKTBUF_SIZE 2048 /* */
34 #define is_digit(c) (((c) >= '0') && ((c) <= '9'))
35 #define major_ver(v) (((v) >> 8) && 0xff)
37 static inline bool is_hex(char c)
39 return (c >= '0' && c <= '9') ||
40 (c >= 'A' && c <= 'F') ||
41 (c >= 'a' && c <= 'f');
44 static inline int hexval(char c)
46 return (c >= 'A') ? (c & ~0x20) - 'A' + 10 : (c - '0');
50 * TFTP operation codes
52 #define TFTP_RRQ htons(1) // Read rest
53 #define TFTP_WRQ htons(2) // Write rest
54 #define TFTP_DATA htons(3) // Data packet
55 #define TFTP_ACK htons(4) // ACK packet
56 #define TFTP_ERROR htons(5) // ERROR packet
57 #define TFTP_OACK htons(6) // OACK packet
60 * TFTP error codes
62 #define TFTP_EUNDEF htons(0) // Unspecified error
63 #define TFTP_ENOTFOUND htons(1) // File not found
64 #define TFTP_EACCESS htons(2) // Access violation
65 #define TFTP_ENOSPACE htons(3) // Disk full
66 #define TFTP_EBADOP htons(4) // Invalid TFTP operation
67 #define TFTP_EBADID htons(5) // Unknown transfer
68 #define TFTP_EEXISTS htons(6) // File exists
69 #define TFTP_ENOUSER htons(7) // No such user
70 #define TFTP_EOPTNEG htons(8) // Option negotiation failure
73 #define BOOTP_OPTION_MAGIC htonl(0x63825363)
74 #define MAC_MAX 32
76 /* Defines for DNS */
77 #define DNS_PORT htons(53) /* Default DNS port */
78 #define DNS_MAX_PACKET 512 /* Defined by protocol */
79 #define DNS_MAX_SERVERS 4 /* Max no of DNS servers */
83 * structures
86 struct pxenv_t {
87 uint8_t signature[6]; /* PXENV+ */
88 uint16_t version;
89 uint8_t length;
90 uint8_t checksum;
91 segoff16_t rmentry;
92 uint32_t pmoffset;
93 uint16_t pmselector;
94 uint16_t stackseg;
95 uint16_t stacksize;
96 uint16_t bc_codeseg;
97 uint16_t bc_codesize;
98 uint16_t bc_dataseg;
99 uint16_t bc_datasize;
100 uint16_t undidataseg;
101 uint16_t undidatasize;
102 uint16_t undicodeseg;
103 uint16_t undicodesize;
104 segoff16_t pxeptr;
105 } __packed;
107 struct pxe_t {
108 uint8_t signature[4]; /* !PXE */
109 uint8_t structlength;
110 uint8_t structcksum;
111 uint8_t structrev;
112 uint8_t _pad1;
113 segoff16_t undiromid;
114 segoff16_t baseromid;
115 segoff16_t entrypointsp;
116 segoff16_t entrypointesp;
117 segoff16_t statuscallout;
118 uint8_t _pad2;
119 uint8_t segdesccnt;
120 uint16_t firstselector;
121 pxe_segdesc_t seg[7];
122 } __packed;
124 enum pxe_segments {
125 PXE_Seg_Stack = 0,
126 PXE_Seg_UNDIData = 1,
127 PXE_Seg_UNDICode = 2,
128 PXE_Seg_UNDICodeWrite = 3,
129 PXE_Seg_BC_Data = 4,
130 PXE_Seg_BC_Code = 5,
131 PXE_Seg_BC_CodeWrite = 6
134 struct bootp_t {
135 uint8_t opcode; /* BOOTP/DHCP "opcode" */
136 uint8_t hardware; /* ARP hreadware type */
137 uint8_t hardlen; /* Hardware address length */
138 uint8_t gatehops; /* Used by forwarders */
139 uint32_t ident; /* Transaction ID */
140 uint16_t seconds; /* Seconds elapsed */
141 uint16_t flags; /* Broadcast flags */
142 uint32_t cip; /* Cient IP */
143 uint32_t yip; /* "Your" IP */
144 uint32_t sip; /* Next Server IP */
145 uint32_t gip; /* Relay agent IP */
146 uint8_t macaddr[16]; /* Client MAC address */
147 uint8_t sname[64]; /* Server name (optional) */
148 char bootfile[128]; /* Boot file name */
149 uint32_t option_magic; /* Vendor option magic cookie */
150 uint8_t options[1260]; /* Vendor options */
151 } __attribute__ ((packed));
154 * Our inode private information -- this includes the packet buffer!
156 struct pxe_pvt_inode {
157 uint16_t tftp_localport; /* Local port number (0=not in us)*/
158 uint16_t tftp_remoteport; /* Remote port number */
159 uint32_t tftp_remoteip; /* Remote IP address */
160 uint32_t tftp_filepos; /* bytes downloaded (includeing buffer) */
161 uint32_t tftp_blksize; /* Block size for this connection(*) */
162 uint16_t tftp_bytesleft; /* Unclaimed data bytes */
163 uint16_t tftp_lastpkt; /* Sequence number of last packet (NBO) */
164 char *tftp_dataptr; /* Pointer to available data */
165 uint8_t tftp_goteof; /* 1 if the EOF packet received */
166 uint8_t tftp_unused[3]; /* Currently unused */
167 char tftp_pktbuf[PKTBUF_SIZE];
168 } __attribute__ ((packed));
170 #define PVT(i) ((struct pxe_pvt_inode *)((i)->pvt))
173 * Network boot information
175 struct ip_info {
176 uint32_t ipv4;
177 uint32_t myip;
178 uint32_t serverip;
179 uint32_t gateway;
180 uint32_t netmask;
184 * Variable externs
186 extern struct ip_info IPInfo;
188 extern uint8_t MAC[];
189 extern char BOOTIFStr[];
190 extern uint8_t MAC_len;
191 extern uint8_t MAC_type;
193 extern uint8_t DHCPMagic;
194 extern uint32_t RebootTime;
196 extern char boot_file[];
197 extern char path_prefix[];
198 extern char LocalDomain[];
200 extern char IPOption[];
201 extern char dot_quad_buf[];
203 extern uint32_t dns_server[];
205 extern uint16_t APIVer;
206 extern far_ptr_t PXEEntry;
207 extern uint8_t KeepPXE;
209 extern far_ptr_t InitStack;
211 extern bool have_uuid;
212 extern uint8_t uuid_type;
213 extern char uuid[];
215 extern uint16_t BIOS_fbm;
216 extern const uint8_t TimeoutTable[];
219 * Compute the suitable gateway for a specific route -- too many
220 * vendor PXE stacks don't do this correctly...
222 static inline uint32_t gateway(uint32_t ip)
224 if ((ip ^ IPInfo.myip) & IPInfo.netmask)
225 return IPInfo.gateway;
226 else
227 return 0;
231 * functions
234 /* pxe.c */
235 int ip_ok(uint32_t);
236 int pxe_call(int, void *);
238 /* dhcp_options.c */
239 void parse_dhcp(int);
241 /* dnsresolv.c */
242 int dns_mangle(char **, const char *);
243 uint32_t dns_resolv(const char *);
245 /* idle.c */
246 void pxe_idle_init(void);
247 void pxe_idle_cleanup(void);
249 /* socknum.c */
250 uint16_t get_port(void);
251 void free_port(uint16_t port);
253 #endif /* pxe.h */