2 * Copyright (c) 2000 Alfred Perlstein <alfred@freebsd.org>
4 * Copyright (c) 2000 Paul Saab <ps@freebsd.org>
6 * Copyright (c) 2000 John Baldwin <jhb@freebsd.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * The typedefs and structures declared in this file
35 * clearly violate style(9), the reason for this is to conform to the
36 * typedefs/structure-names used in the Intel literature to avoid confusion.
38 * It's for your own good. :)
41 /* It seems that intel didn't think about ABI,
42 * either that or 16bit ABI != 32bit ABI (which seems reasonable)
43 * I have to thank Intel for the hair loss I incurred trying to figure
44 * out why PXE was mis-reading structures I was passing it (at least
45 * from my point of view)
47 * Solution: use gcc's '__packed' to correctly align
48 * structures passed into PXE
49 * Question: does this really work for PXE's expected ABI?
51 #define PACKED __packed
53 #define S_SIZE(s) s, sizeof(s) - 1
55 #define IP_STR "%d.%d.%d.%d"
57 (int)(ip >> 24) & 0xff, (int)(ip >> 16) & 0xff, \
58 (int)(ip >> 8) & 0xff, (int)ip & 0xff
60 #define MAC_STR "%02x:%02x:%02x:%02x:%02x:%02x"
61 #define MAC_ARGS(mac) \
62 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
64 #define PXENFSROOTPATH "/pxeroot"
77 typedef uint16_t SEGSEL_t;
78 typedef uint16_t PXENV_STATUS_t;
79 typedef uint32_t IP4_t;
80 typedef uint32_t ADDR32_t;
81 typedef uint16_t UDP_PORT_t;
83 #define MAC_ADDR_LEN 16
84 typedef uint8_t MAC_ADDR[MAC_ADDR_LEN];
88 uint8_t Signature[6]; /* 'PXENV+' */
89 uint16_t Version; /* MSB = major, LSB = minor */
90 uint8_t Length; /* structure length */
91 uint8_t Checksum; /* checksum pad */
92 SEGOFF16_t RMEntry; /* SEG:OFF to PXE entry point */
93 /* don't use PMOffset and PMSelector (from the 2.1 PXE manual) */
94 uint32_t PMOffset; /* Protected mode entry */
95 SEGSEL_t PMSelector; /* Protected mode selector */
96 SEGSEL_t StackSeg; /* Stack segment address */
97 uint16_t StackSize; /* Stack segment size (bytes) */
98 SEGSEL_t BC_CodeSeg; /* BC Code segment address */
99 uint16_t BC_CodeSize; /* BC Code segment size (bytes) */
100 SEGSEL_t BC_DataSeg; /* BC Data segment address */
101 uint16_t BC_DataSize; /* BC Data segment size (bytes) */
102 SEGSEL_t UNDIDataSeg; /* UNDI Data segment address */
103 uint16_t UNDIDataSize; /* UNDI Data segment size (bytes) */
104 SEGSEL_t UNDICodeSeg; /* UNDI Code segment address */
105 uint16_t UNDICodeSize; /* UNDI Code segment size (bytes) */
106 SEGOFF16_t PXEPtr; /* SEG:OFF to !PXE struct,
107 only present when Version > 2.1 */
112 uint8_t Signature[4];
113 uint8_t StructLength;
117 SEGOFF16_t UNDIROMID;
118 SEGOFF16_t BaseROMID;
119 SEGOFF16_t EntryPointSP;
120 SEGOFF16_t EntryPointESP;
121 SEGOFF16_t StatusCallout;
124 SEGSEL_t FirstSelector;
128 SEGDESC_t UNDICodeWrite;
131 SEGDESC_t BC_CodeWrite;
134 #define PXENV_START_UNDI 0x0000
136 PXENV_STATUS_t Status;
142 } PACKED t_PXENV_START_UNDI;
144 #define PXENV_UNDI_STARTUP 0x0001
146 PXENV_STATUS_t Status;
147 } PACKED t_PXENV_UNDI_STARTUP;
149 #define PXENV_UNDI_CLEANUP 0x0002
151 PXENV_STATUS_t Status;
152 } PACKED t_PXENV_UNDI_CLEANUP;
154 #define PXENV_UNDI_INITIALIZE 0x0003
156 PXENV_STATUS_t Status;
157 ADDR32_t ProtocolIni; /* Phys addr of a copy of the driver module */
159 } PACKED t_PXENV_UNDI_INITALIZE;
162 #define MAXNUM_MCADDR 8
164 PXENV_STATUS_t Status;
165 uint16_t MCastAddrCount;
166 MAC_ADDR McastAddr[MAXNUM_MCADDR];
167 } PACKED t_PXENV_UNDI_MCAST_ADDRESS;
169 #define PXENV_UNDI_RESET_ADAPTER 0x0004
171 PXENV_STATUS_t Status;
172 t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
173 } PACKED t_PXENV_UNDI_RESET;
175 #define PXENV_UNDI_SHUTDOWN 0x0005
177 PXENV_STATUS_t Status;
178 } PACKED t_PXENV_UNDI_SHUTDOWN;
180 #define PXENV_UNDI_OPEN 0x0006
182 PXENV_STATUS_t Status;
185 # define FLTR_DIRECTED 0x0001
186 # define FLTR_BRDCST 0x0002
187 # define FLTR_PRMSCS 0x0003
188 # define FLTR_SRC_RTG 0x0004
190 t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
191 } PACKED t_PXENV_UNDI_OPEN;
193 #define PXENV_UNDI_CLOSE 0x0007
195 PXENV_STATUS_t Status;
196 } PACKED t_PXENV_UNDI_CLOSE;
198 #define PXENV_UNDI_TRANSMIT 0x0008
200 PXENV_STATUS_t Status;
208 # define XMT_DESTADDR 0x0000
209 # define XMT_BROADCAST 0x0001
213 uint32_t Reserved[2];
214 } PACKED t_PXENV_UNDI_TRANSMIT;
216 #define MAX_DATA_BLKS 8
218 uint16_t ImmedLength;
220 uint16_t DataBlkCount;
225 SEGOFF16_t TDDataPtr;
226 } DataBlock[MAX_DATA_BLKS];
227 } PACKED t_PXENV_UNDI_TBD;
229 #define PXENV_UNDI_SET_MCAST_ADDRESS 0x0009
231 PXENV_STATUS_t Status;
232 t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf;
233 } PACKED t_PXENV_UNDI_SET_MCAST_ADDR;
235 #define PXENV_UNDI_SET_STATION_ADDRESS 0x000A
237 PXENV_STATUS_t Status;
238 MAC_ADDR StationAddress; /* Temp MAC addres to use */
239 } PACKED t_PXENV_UNDI_SET_STATION_ADDR;
241 #define PXENV_UNDI_SET_PACKET_FILTER 0x000B
243 PXENV_STATUS_t Status;
244 uint8_t filter; /* see UNDI_OPEN (0x0006) */
245 } PACKED t_PXENV_UNDI_SET_PACKET_FILTER;
247 #define PXENV_UNDI_GET_INFORMATION 0x000C
249 PXENV_STATUS_t Status;
250 uint16_t BaseIo; /* Adapter base I/O address */
251 uint16_t IntNumber; /* Adapter IRQ number */
252 uint16_t MaxTranUnit; /* Adapter maximum transmit unit */
253 uint16_t HwType; /* Type of protocol at the hardware addr */
254 # define ETHER_TYPE 1
255 # define EXP_ETHER_TYPE 2
257 # define ARCNET_TYPE 7
259 uint16_t HwAddrLen; /* Length of hardware address */
260 MAC_ADDR CurrentNodeAddress; /* Current hardware address */
261 MAC_ADDR PermNodeAddress; /* Permanent hardware address */
262 SEGSEL_t ROMAddress; /* Real mode ROM segment address */
263 uint16_t RxBufCt; /* Receive queue length */
264 uint16_t TxBufCt; /* Transmit queue length */
265 } PACKED t_PXENV_UNDI_GET_INFORMATION;
267 #define PXENV_UNDI_GET_STATISTICS 0x000D
269 PXENV_STATUS_t Status;
270 uint32_t XmitGoodFrames; /* Number of successful transmissions */
271 uint32_t RcvGoodFrames; /* Number of good frames received */
272 uint32_t RcvCRCErrors; /* Number of frames with CRC errors */
273 uint32_t RcvResourceErrors; /* Number of frames dropped */
274 } PACKED t_PXENV_UNDI_GET_STATISTICS;
276 #define PXENV_UNDI_CLEAR_STATISTICS 0x000E
278 PXENV_STATUS_t Status;
279 } PACKED t_PXENV_UNDI_CLEAR_STATISTICS;
281 #define PXENV_UNDI_INITIATE_DIAGS 0x000F
283 PXENV_STATUS_t Status;
284 } PACKED t_PXENV_UNDI_INITIATE_DIAGS;
286 #define PXENV_UNDI_FORCE_INTERRUPT 0x0010
288 PXENV_STATUS_t Status;
289 } PACKED t_PXENV_UNDI_FORCE_INTERRUPT;
291 #define PXENV_UNDI_GET_MCAST_ADDRESS 0x0011
293 PXENV_STATUS_t Status;
294 IP4_t InetAddr; /* IP mulicast address */
295 MAC_ADDR MediaAddr; /* MAC multicast address */
296 } PACKED t_PXENV_UNDI_GET_MCAST_ADDR;
298 #define PXENV_UNDI_GET_NIC_TYPE 0x0012
300 PXENV_STATUS_t Status;
301 uint8_t NicType; /* Type of NIC */
304 # define CardBus_NIC 4
315 uint16_t SubVendor_ID;
316 uint16_t SubDevice_ID;
319 uint32_t EISA_Dev_ID;
326 } PACKED t_PXENV_UNDI_GET_NIC_TYPE;
328 #define PXENV_UNDI_GET_IFACE_INFO 0x0013
330 PXENV_STATUS_t Status;
331 uint8_t IfaceType[16]; /* Name of MAC type in ASCII. */
332 uint32_t LinkSpeed; /* Defined in NDIS 2.0 spec */
333 uint32_t ServiceFlags; /* Defined in NDIS 2.0 spec */
334 uint32_t Reserved[4]; /* must be 0 */
335 } PACKED t_PXENV_UNDI_GET_NDIS_INFO;
337 #define PXENV_UNDI_ISR 0x0014
339 PXENV_STATUS_t Status;
340 uint16_t FuncFlag; /* PXENV_UNDI_ISR_OUT_xxx */
341 uint16_t BufferLength; /* Length of Frame */
342 uint16_t FrameLength; /* Total length of reciever frame */
343 uint16_t FrameHeaderLength; /* Length of the media header in Frame */
344 SEGOFF16_t Frame; /* receive buffer */
345 uint8_t ProtType; /* Protocol type */
346 uint8_t PktType; /* Packet Type */
347 # define PXENV_UNDI_ISR_IN_START 1
348 # define PXENV_UNDI_ISR_IN_PROCESS 2
349 # define PXENV_UNDI_ISR_IN_GET_NEXT 3
351 /* one of these will be returned for PXENV_UNDI_ISR_IN_START */
352 # define PXENV_UNDI_ISR_OUT_OURS 0
353 # define PXENV_UNDI_ISR_OUT_NOT_OUTS 1
356 * one of these will bre returnd for PXEND_UNDI_ISR_IN_PROCESS
357 * and PXENV_UNDI_ISR_IN_GET_NEXT
359 # define PXENV_UNDI_ISR_OUT_DONE 0
360 # define PXENV_UNDI_ISR_OUT_TRANSMIT 2
361 # define PXENV_UNDI_ISR_OUT_RECIEVE 3
362 # define PXENV_UNDI_ISR_OUT_BUSY 4
363 } PACKED t_PXENV_UNDI_ISR;
365 #define PXENV_STOP_UNDI 0x0015
367 PXENV_STATUS_t Status;
368 } PACKED t_PXENV_STOP_UNDI;
370 #define PXENV_TFTP_OPEN 0x0020
372 PXENV_STATUS_t Status;
373 IP4_t ServerIPAddress;
374 IP4_t GatewayIPAddress;
375 uint8_t FileName[128];
378 } PACKED t_PXENV_TFTP_OPEN;
380 #define PXENV_TFTP_CLOSE 0x0021
382 PXENV_STATUS_t Status;
383 } PACKED t_PXENV_TFTP_CLOSE;
385 #define PXENV_TFTP_READ 0x0022
387 PXENV_STATUS_t Status;
388 uint16_t PacketNumber;
391 } PACKED t_PXENV_TFTP_READ;
393 #define PXENV_TFTP_READ_FILE 0x0023
395 PXENV_STATUS_t Status;
396 uint8_t FileName[128];
399 IP4_t ServerIPAddress;
400 IP4_t GatewayIPAdress;
402 UDP_PORT_t TFTPClntPort;
403 UDP_PORT_t TFTPSrvPort;
404 uint16_t TFTPOpenTimeOut;
405 uint16_t TFTPReopenDelay;
406 } PACKED t_PXENV_TFTP_READ_FILE;
408 #define PXENV_TFTP_GET_FSIZE 0x0025
410 PXENV_STATUS_t Status;
411 IP4_t ServerIPAddress;
412 IP4_t GatewayIPAdress;
413 uint8_t FileName[128];
415 } PACKED t_PXENV_TFTP_GET_FSIZE;
417 #define PXENV_UDP_OPEN 0x0030
419 PXENV_STATUS_t status;
420 IP4_t src_ip; /* IP address of this station */
421 } PACKED t_PXENV_UDP_OPEN;
423 #define PXENV_UDP_CLOSE 0x0031
425 PXENV_STATUS_t status;
426 } PACKED t_PXENV_UDP_CLOSE;
428 #define PXENV_UDP_READ 0x0032
430 PXENV_STATUS_t status;
431 IP4_t src_ip; /* IP of sender */
432 IP4_t dest_ip; /* Only accept packets sent to this IP */
433 UDP_PORT_t s_port; /* UDP source port of sender */
434 UDP_PORT_t d_port; /* Only accept packets sent to this port */
435 uint16_t buffer_size; /* Size of the packet buffer */
436 SEGOFF16_t buffer; /* SEG:OFF to the packet buffer */
437 } PACKED t_PXENV_UDP_READ;
439 #define PXENV_UDP_WRITE 0x0033
441 PXENV_STATUS_t status;
442 IP4_t ip; /* dest ip addr */
443 IP4_t gw; /* ip gateway */
444 UDP_PORT_t src_port; /* source udp port */
445 UDP_PORT_t dst_port; /* destination udp port */
446 uint16_t buffer_size; /* Size of the packet buffer */
447 SEGOFF16_t buffer; /* SEG:OFF to the packet buffer */
448 } PACKED t_PXENV_UDP_WRITE;
450 #define PXENV_UNLOAD_STACK 0x0070
452 PXENV_STATUS_t Status;
453 uint8_t reserved[10];
454 } PACKED t_PXENV_UNLOAD_STACK;
457 #define PXENV_GET_CACHED_INFO 0x0071
459 PXENV_STATUS_t Status;
460 uint16_t PacketType; /* type (defined right here) */
461 # define PXENV_PACKET_TYPE_DHCP_DISCOVER 1
462 # define PXENV_PACKET_TYPE_DHCP_ACK 2
463 # define PXENV_PACKET_TYPE_BINL_REPLY 3
464 uint16_t BufferSize; /* max to copy, leave at 0 for pointer */
465 SEGOFF16_t Buffer; /* copy to, leave at 0 for pointer */
466 uint16_t BufferLimit; /* max size of buffer in BC dataseg ? */
467 } PACKED t_PXENV_GET_CACHED_INFO;
470 /* structure filled in by PXENV_GET_CACHED_INFO
471 * (how we determine which IP we downloaded the initial bootstrap from)
472 * words can't describe...
478 uint8_t Hardware; /* hardware type */
479 uint8_t Hardlen; /* hardware addr len */
480 uint8_t Gatehops; /* zero it */
481 uint32_t ident; /* random number chosen by client */
482 uint16_t seconds; /* seconds since did initial bootstrap */
483 uint16_t Flags; /* seconds since did initial bootstrap */
484 # define BOOTP_BCAST 0x8000 /* ? */
485 IP4_t cip; /* Client IP */
486 IP4_t yip; /* Your IP */
487 IP4_t sip; /* IP to use for next boot stage */
488 IP4_t gip; /* Relay IP ? */
489 MAC_ADDR CAddr; /* Client hardware address */
490 uint8_t Sname[64]; /* Server's hostname (Optional) */
491 uint8_t bootfile[128]; /* boot filename */
494 # define BOOTP_DHCPVEND 1024 /* DHCP extended vendor field size */
496 # define BOOTP_DHCPVEND 312 /* DHCP standard vendor field size */
498 uint8_t d[BOOTP_DHCPVEND]; /* raw array of vendor/dhcp options */
500 uint8_t magic[4]; /* DHCP magic cookie */
502 # define VM_RFC1048 0x63825363L /* ? */
504 uint32_t flags; /* bootp flags/opcodes */
505 uint8_t pad[56]; /* I don't think intel knows what a
511 #define PXENV_RESTART_TFTP 0x0073
512 #define t_PXENV_RESTART_TFTP t_PXENV_TFTP_READ_FILE
514 #define PXENV_START_BASE 0x0075
516 PXENV_STATUS_t Status;
517 } PACKED t_PXENV_START_BASE;
519 #define PXENV_STOP_BASE 0x0076
521 PXENV_STATUS_t Status;
522 } PACKED t_PXENV_STOP_BASE;