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