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