pxe.h revision 58993
1/* 2 * Copyright (c) 2000 Alfred Perlstein <alfred@freebsd.org> 3 * All rights reserved. 4 * Copyright (c) 2000 Paul Saab <ps@freebsd.org> 5 * All rights reserved. 6 * Copyright (c) 2000 John Baldwin <jhb@freebsd.org> 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 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. 17 * 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 28 * SUCH DAMAGE. 29 * 30 * $FreeBSD: head/sys/boot/i386/libi386/pxe.h 58993 2000-04-04 00:38:59Z ps $ 31 */ 32 33/* 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. 37 * 38 * It's for your own good. :) 39 */ 40 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) 46 * 47 * Solution: use gcc's '__attribute__ ((packed))' to correctly align 48 * structures passed into PXE 49 * Question: does this really work for PXE's expected ABI? 50 */ 51#define PACKED __attribute__ ((packed)) 52 53#define S_SIZE(s) s, sizeof(s) - 1 54 55#define IP_STR "%d.%d.%d.%d" 56#define IP_ARGS(ip) \ 57 (int)(ip >> 24) & 0xff, (int)(ip >> 16) & 0xff, \ 58 (int)(ip >> 8) & 0xff, (int)ip & 0xff 59 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] 63 64typedef struct { 65 uint16_t offset; 66 uint16_t segment; 67} SEGOFF16_t; 68 69typedef struct { 70 uint16_t Seg_Addr; 71 uint32_t Phy_Addr; 72 uint16_t Seg_Size; 73} SEGDESC_t; 74 75typedef uint16_t SEGSEL_t; 76typedef uint16_t PXENV_STATUS_t; 77typedef uint32_t IP4_t; 78typedef uint32_t ADDR32_t; 79typedef uint16_t UDP_PORT_t; 80 81#define MAC_ADDR_LEN 16 82typedef uint8_t MAC_ADDR[MAC_ADDR_LEN]; 83 84/* PXENV+ */ 85typedef struct { 86 uint8_t Signature[6]; /* 'PXENV+' */ 87 uint16_t Version; /* MSB = major, LSB = minor */ 88 uint8_t Length; /* structure length */ 89 uint8_t Checksum; /* checksum pad */ 90 SEGOFF16_t RMEntry; /* SEG:OFF to PXE entry point */ 91 /* don't use PMOffset and PMSelector (from the 2.1 PXE manual) */ 92 uint32_t PMOffset; /* Protected mode entry */ 93 SEGSEL_t PMSelector; /* Protected mode selector */ 94 SEGSEL_t StackSeg; /* Stack segment address */ 95 uint16_t StackSize; /* Stack segment size (bytes) */ 96 SEGSEL_t BC_CodeSeg; /* BC Code segment address */ 97 uint16_t BC_CodeSize; /* BC Code segment size (bytes) */ 98 SEGSEL_t BC_DataSeg; /* BC Data segment address */ 99 uint16_t BC_DataSize; /* BC Data segment size (bytes) */ 100 SEGSEL_t UNDIDataSeg; /* UNDI Data segment address */ 101 uint16_t UNDIDataSize; /* UNDI Data segment size (bytes) */ 102 SEGSEL_t UNDICodeSeg; /* UNDI Code segment address */ 103 uint16_t UNDICodeSize; /* UNDI Code segment size (bytes) */ 104 SEGOFF16_t PXEPtr; /* SEG:OFF to !PXE struct, 105 only present when Version > 2.1 */ 106} PACKED pxenv_t; 107 108/* !PXE */ 109typedef struct { 110 uint8_t Signature[4]; 111 uint8_t StructLength; 112 uint8_t StructCksum; 113 uint8_t StructRev; 114 uint8_t reserved_1; 115 SEGOFF16_t UNDIROMID; 116 SEGOFF16_t BaseROMID; 117 SEGOFF16_t EntryPointSP; 118 SEGOFF16_t EntryPointESP; 119 SEGOFF16_t StatusCallout; 120 uint8_t reserved_2; 121 uint8_t SegDescCn; 122 SEGSEL_t FirstSelector; 123 SEGDESC_t Stack; 124 SEGDESC_t UNDIData; 125 SEGDESC_t UNDICode; 126 SEGDESC_t UNDICodeWrite; 127 SEGDESC_t BC_Data; 128 SEGDESC_t BC_Code; 129 SEGDESC_t BC_CodeWrite; 130} PACKED pxe_t; 131 132#define PXENV_START_UNDI 0x0000 133typedef struct { 134 PXENV_STATUS_t Status; 135 uint16_t ax; 136 uint16_t bx; 137 uint16_t dx; 138 uint16_t di; 139 uint16_t es; 140} PACKED t_PXENV_START_UNDI; 141 142#define PXENV_UNDI_STARTUP 0x0001 143typedef struct { 144 PXENV_STATUS_t Status; 145} PACKED t_PXENV_UNDI_STARTUP; 146 147#define PXENV_UNDI_CLEANUP 0x0002 148typedef struct { 149 PXENV_STATUS_t Status; 150} PACKED t_PXENV_UNDI_CLEANUP; 151 152#define PXENV_UNDI_INITIALIZE 0x0003 153typedef struct { 154 PXENV_STATUS_t Status; 155 ADDR32_t ProtocolIni; /* Phys addr of a copy of the driver module */ 156 uint8_t reserved[8]; 157} PACKED t_PXENV_UNDI_INITALIZE; 158 159 160#define MAXNUM_MCADDR 8 161typedef struct { 162 PXENV_STATUS_t Status; 163 uint16_t MCastAddrCount; 164 MAC_ADDR McastAddr[MAXNUM_MCADDR]; 165} PACKED t_PXENV_UNDI_MCAST_ADDRESS; 166 167#define PXENV_UNDI_RESET_ADAPTER 0x0004 168typedef struct { 169 PXENV_STATUS_t Status; 170 t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf; 171} PACKED t_PXENV_UNDI_RESET; 172 173#define PXENV_UNDI_SHUTDOWN 0x0005 174typedef struct { 175 PXENV_STATUS_t Status; 176} PACKED t_PXENV_UNDI_SHUTDOWN; 177 178#define PXENV_UNDI_OPEN 0x0006 179typedef struct { 180 PXENV_STATUS_t Status; 181 uint16_t OpenFlag; 182 uint16_t PktFilter; 183# define FLTR_DIRECTED 0x0001 184# define FLTR_BRDCST 0x0002 185# define FLTR_PRMSCS 0x0003 186# define FLTR_SRC_RTG 0x0004 187 188 t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf; 189} PACKED t_PXENV_UNDI_OPEN; 190 191#define PXENV_UNDI_CLOSE 0x0007 192typedef struct { 193 PXENV_STATUS_t Status; 194} PACKED t_PXENV_UNDI_CLOSE; 195 196#define PXENV_UNDI_TRANSMIT 0x0008 197typedef struct { 198 PXENV_STATUS_t Status; 199 uint8_t Protocol; 200# define P_UNKNOWN 0 201# define P_IP 1 202# define P_ARP 2 203# define P_RARP 3 204 205 uint8_t XmitFlag; 206# define XMT_DESTADDR 0x0000 207# define XMT_BROADCAST 0x0001 208 209 SEGOFF16_t DestAddr; 210 SEGOFF16_t TBD; 211 uint32_t Reserved[2]; 212} PACKED t_PXENV_UNDI_TRANSMIT; 213 214#define MAX_DATA_BLKS 8 215typedef struct { 216 uint16_t ImmedLength; 217 SEGOFF16_t Xmit; 218 uint16_t DataBlkCount; 219 struct DataBlk { 220 uint8_t TDPtrType; 221 uint8_t TDRsvdByte; 222 uint16_t TDDataLen; 223 SEGOFF16_t TDDataPtr; 224 } DataBlock[MAX_DATA_BLKS]; 225} PACKED t_PXENV_UNDI_TBD; 226 227#define PXENV_UNDI_SET_MCAST_ADDRESS 0x0009 228typedef struct { 229 PXENV_STATUS_t Status; 230 t_PXENV_UNDI_MCAST_ADDRESS R_Mcast_Buf; 231} PACKED t_PXENV_UNDI_SET_MCAST_ADDR; 232 233#define PXENV_UNDI_SET_STATION_ADDRESS 0x000A 234typedef struct { 235 PXENV_STATUS_t Status; 236 MAC_ADDR StationAddress; /* Temp MAC addres to use */ 237} PACKED t_PXENV_UNDI_SET_STATION_ADDR; 238 239#define PXENV_UNDI_SET_PACKET_FILTER 0x000B 240typedef struct { 241 PXENV_STATUS_t Status; 242 uint8_t filter; /* see UNDI_OPEN (0x0006) */ 243} PACKED t_PXENV_UNDI_SET_PACKET_FILTER; 244 245#define PXENV_UNDI_GET_INFORMATION 0x000C 246typedef struct { 247 PXENV_STATUS_t Status; 248 uint16_t BaseIo; /* Adapter base I/O address */ 249 uint16_t IntNumber; /* Adapter IRQ number */ 250 uint16_t MaxTranUnit; /* Adapter maximum transmit unit */ 251 uint16_t HwType; /* Type of protocol at the hardware addr */ 252# define ETHER_TYPE 1 253# define EXP_ETHER_TYPE 2 254# define IEEE_TYPE 6 255# define ARCNET_TYPE 7 256 257 uint16_t HwAddrLen; /* Length of hardware address */ 258 MAC_ADDR CurrentNodeAddress; /* Current hardware address */ 259 MAC_ADDR PermNodeAddress; /* Permanent hardware address */ 260 SEGSEL_t ROMAddress; /* Real mode ROM segment address */ 261 uint16_t RxBufCt; /* Receive queue length */ 262 uint16_t TxBufCt; /* Transmit queue length */ 263} PACKED t_PXENV_UNDI_GET_INFORMATION; 264 265#define PXENV_UNDI_GET_STATISTICS 0x000D 266typedef struct { 267 PXENV_STATUS_t Status; 268 uint32_t XmitGoodFrames; /* Number of successful transmissions */ 269 uint32_t RcvGoodFrames; /* Number of good frames received */ 270 uint32_t RcvCRCErrors; /* Number of frames with CRC errors */ 271 uint32_t RcvResourceErrors; /* Number of frames dropped */ 272} PACKED t_PXENV_UNDI_GET_STATISTICS; 273 274#define PXENV_UNDI_CLEAR_STATISTICS 0x000E 275typedef struct { 276 PXENV_STATUS_t Status; 277} PACKED t_PXENV_UNDI_CLEAR_STATISTICS; 278 279#define PXENV_UNDI_INITIATE_DIAGS 0x000F 280typedef struct { 281 PXENV_STATUS_t Status; 282} PACKED t_PXENV_UNDI_INITIATE_DIAGS; 283 284#define PXENV_UNDI_FORCE_INTERRUPT 0x0010 285typedef struct { 286 PXENV_STATUS_t Status; 287} PACKED t_PXENV_UNDI_FORCE_INTERRUPT; 288 289#define PXENV_UNDI_GET_MCAST_ADDRESS 0x0011 290typedef struct { 291 PXENV_STATUS_t Status; 292 IP4_t InetAddr; /* IP mulicast address */ 293 MAC_ADDR MediaAddr; /* MAC multicast address */ 294} PACKED t_PXENV_UNDI_GET_MCAST_ADDR; 295 296#define PXENV_UNDI_GET_NIC_TYPE 0x0012 297typedef struct { 298 PXENV_STATUS_t Status; 299 uint8_t NicType; /* Type of NIC */ 300# define PCI_NIC 2 301# define PnP_NIC 3 302# define CardBus_NIC 4 303 304 union { 305 struct { 306 uint16_t Vendor_ID; 307 uint16_t Dev_ID; 308 uint8_t Base_Class; 309 uint8_t Sub_Class; 310 uint8_t Prog_Intf; 311 uint8_t Rev; 312 uint16_t BusDevFunc; 313 uint16_t SubVendor_ID; 314 uint16_t SubDevice_ID; 315 } pci, cardbus; 316 struct { 317 uint32_t EISA_Dev_ID; 318 uint8_t Base_Class; 319 uint8_t Sub_Class; 320 uint8_t Prog_Intf; 321 uint16_t CardSelNum; 322 } pnp; 323 } info; 324} PACKED t_PXENV_UNDI_GET_NIC_TYPE; 325 326#define PXENV_UNDI_GET_IFACE_INFO 0x0013 327typedef struct { 328 PXENV_STATUS_t Status; 329 uint8_t IfaceType[16]; /* Name of MAC type in ASCII. */ 330 uint32_t LinkSpeed; /* Defined in NDIS 2.0 spec */ 331 uint32_t ServiceFlags; /* Defined in NDIS 2.0 spec */ 332 uint32_t Reserved[4]; /* must be 0 */ 333} PACKED t_PXENV_UNDI_GET_NDIS_INFO; 334 335#define PXENV_UNDI_ISR 0x0014 336typedef struct { 337 PXENV_STATUS_t Status; 338 uint16_t FuncFlag; /* PXENV_UNDI_ISR_OUT_xxx */ 339 uint16_t BufferLength; /* Length of Frame */ 340 uint16_t FrameLength; /* Total length of reciever frame */ 341 uint16_t FrameHeaderLength; /* Length of the media header in Frame */ 342 SEGOFF16_t Frame; /* receive buffer */ 343 uint8_t ProtType; /* Protocol type */ 344 uint8_t PktType; /* Packet Type */ 345# define PXENV_UNDI_ISR_IN_START 1 346# define PXENV_UNDI_ISR_IN_PROCESS 2 347# define PXENV_UNDI_ISR_IN_GET_NEXT 3 348 349 /* one of these will be returned for PXENV_UNDI_ISR_IN_START */ 350# define PXENV_UNDI_ISR_OUT_OURS 0 351# define PXENV_UNDI_ISR_OUT_NOT_OUTS 1 352 353 /* 354 * one of these will bre returnd for PXEND_UNDI_ISR_IN_PROCESS 355 * and PXENV_UNDI_ISR_IN_GET_NEXT 356 */ 357# define PXENV_UNDI_ISR_OUT_DONE 0 358# define PXENV_UNDI_ISR_OUT_TRANSMIT 2 359# define PXENV_UNDI_ISR_OUT_RECIEVE 3 360# define PXENV_UNDI_ISR_OUT_BUSY 4 361} PACKED t_PXENV_UNDI_ISR; 362 363#define PXENV_STOP_UNDI 0x0015 364typedef struct { 365 PXENV_STATUS_t Status; 366} PACKED t_PXENV_STOP_UNDI; 367 368#define PXENV_TFTP_OPEN 0x0020 369typedef struct { 370 PXENV_STATUS_t Status; 371 IP4_t ServerIPAddress; 372 IP4_t GatewayIPAddress; 373 uint8_t FileName[128]; 374 UDP_PORT_t TFTPPort; 375 uint16_t PacketSize; 376} PACKED t_PXENV_TFTP_OPEN; 377 378#define PXENV_TFTP_CLOSE 0x0021 379typedef struct { 380 PXENV_STATUS_t Status; 381} PACKED t_PXENV_TFTP_CLOSE; 382 383#define PXENV_TFTP_READ 0x0022 384typedef struct { 385 PXENV_STATUS_t Status; 386 uint16_t PacketNumber; 387 uint16_t BufferSize; 388 SEGOFF16_t Buffer; 389} PACKED t_PXENV_TFTP_READ; 390 391#define PXENV_TFTP_READ_FILE 0x0023 392typedef struct { 393 PXENV_STATUS_t Status; 394 uint8_t FileName[128]; 395 uint32_t BufferSize; 396 ADDR32_t Buffer; 397 IP4_t ServerIPAddress; 398 IP4_t GatewayIPAdress; 399 IP4_t McastIPAdress; 400 UDP_PORT_t TFTPClntPort; 401 UDP_PORT_t TFTPSrvPort; 402 uint16_t TFTPOpenTimeOut; 403 uint16_t TFTPReopenDelay; 404} PACKED t_PXENV_TFTP_READ_FILE; 405 406#define PXENV_TFTP_GET_FSIZE 0x0025 407typedef struct { 408 PXENV_STATUS_t Status; 409 IP4_t ServerIPAddress; 410 IP4_t GatewayIPAdress; 411 uint8_t FileName[128]; 412 uint32_t FileSize; 413} PACKED t_PXENV_TFTP_GET_FSIZE; 414 415#define PXENV_UDP_OPEN 0x0030 416typedef struct { 417 PXENV_STATUS_t status; 418 IP4_t src_ip; /* IP address of this station */ 419} PACKED t_PXENV_UDP_OPEN; 420 421#define PXENV_UDP_CLOSE 0x0031 422typedef struct { 423 PXENV_STATUS_t status; 424} PACKED t_PXENV_UDP_CLOSE; 425 426#define PXENV_UDP_READ 0x0032 427typedef struct { 428 PXENV_STATUS_t status; 429 IP4_t src_ip; /* IP of sender */ 430 IP4_t dest_ip; /* Only accept packets sent to this IP */ 431 UDP_PORT_t s_port; /* UDP source port of sender */ 432 UDP_PORT_t d_port; /* Only accept packets sent to this port */ 433 uint16_t buffer_size; /* Size of the packet buffer */ 434 SEGOFF16_t buffer; /* SEG:OFF to the packet buffer */ 435} PACKED t_PXENV_UDP_READ; 436 437#define PXENV_UNLOAD_STACK 0x0070 438typedef struct { 439 PXENV_STATUS_t Status; 440 uint8_t reserved[10]; 441} PACKED t_PXENV_UNLOAD_STACK; 442 443 444#define PXENV_GET_CACHED_INFO 0x0071 445typedef struct { 446 PXENV_STATUS_t Status; 447 uint16_t PacketType; /* type (defined right here) */ 448# define PXENV_PACKET_TYPE_DHCP_DISCOVER 1 449# define PXENV_PACKET_TYPE_DHCP_ACK 2 450# define PXENV_PACKET_TYPE_BINL_REPLY 3 451 uint16_t BufferSize; /* max to copy, leave at 0 for pointer */ 452 SEGOFF16_t Buffer; /* copy to, leave at 0 for pointer */ 453 uint16_t BufferLimit; /* max size of buffer in BC dataseg ? */ 454} PACKED t_PXENV_GET_CACHED_INFO; 455 456 457/* structure filled in by PXENV_GET_CACHED_INFO 458 * (how we determine which IP we downloaded the initial bootstrap from) 459 * words can't describe... 460 */ 461typedef struct { 462 uint8_t opcode; 463# define BOOTP_REQ 1 464# define BOOTP_REP 2 465 uint8_t Hardware; /* hardware type */ 466 uint8_t Hardlen; /* hardware addr len */ 467 uint8_t Gatehops; /* zero it */ 468 uint32_t ident; /* random number chosen by client */ 469 uint16_t seconds; /* seconds since did initial bootstrap */ 470 uint16_t Flags; /* seconds since did initial bootstrap */ 471# define BOOTP_BCAST 0x8000 /* ? */ 472 IP4_t cip; /* Client IP */ 473 IP4_t yip; /* Your IP */ 474 IP4_t sip; /* IP to use for next boot stage */ 475 IP4_t gip; /* Relay IP ? */ 476 MAC_ADDR CAddr; /* Client hardware address */ 477 uint8_t Sname[64]; /* Server's hostname (Optional) */ 478 uint8_t bootfile[128]; /* boot filename */ 479 union { 480# if 1 481# define BOOTP_DHCPVEND 1024 /* DHCP extended vendor field size */ 482# else 483# define BOOTP_DHCPVEND 312 /* DHCP standard vendor field size */ 484# endif 485 uint8_t d[BOOTP_DHCPVEND]; /* raw array of vendor/dhcp options */ 486 struct { 487 uint8_t magic[4]; /* DHCP magic cookie */ 488# define VM_RFC1048 0x63825363L /* ? */ 489 uint32_t flags; /* bootp flags/opcodes */ 490 uint8_t pad[56]; /* I don't think intel knows what a 491 union does... */ 492 } v; 493 } vendor; 494} PACKED BOOTPLAYER; 495 496#define PXENV_RESTART_TFTP 0x0073 497#define t_PXENV_RESTART_TFTP t_PXENV_TFTP_READ_FILE 498 499#define PXENV_START_BASE 0x0075 500typedef struct { 501 PXENV_STATUS_t Status; 502} PACKED t_PXENV_START_BASE; 503 504#define PXENV_STOP_BASE 0x0076 505typedef struct { 506 PXENV_STATUS_t Status; 507} PACKED t_PXENV_STOP_BASE; 508