1 /** @file 2 3 Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR> 4 This program and the accompanying materials 5 are licensed and made available under the terms and conditions of the BSD License 6 which accompanies this distribution. The full text of the license may be found at 7 http://opensource.org/licenses/bsd-license.php 8 9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 12 **/ 13 14 #ifndef __EFI_PXEBC_IMPL_H__ 15 #define __EFI_PXEBC_IMPL_H__ 16 17 18 typedef struct _PXEBC_PRIVATE_DATA PXEBC_PRIVATE_DATA; 19 20 #include <Uefi.h> 21 22 #include <Guid/SmBios.h> 23 #include <IndustryStandard/SmBios.h> 24 #include <Protocol/Dhcp4.h> 25 #include <Protocol/PxeBaseCode.h> 26 #include <Protocol/Mtftp4.h> 27 #include <Protocol/Udp4.h> 28 #include <Protocol/LoadFile.h> 29 #include <Protocol/NetworkInterfaceIdentifier.h> 30 #include <Protocol/PxeBaseCodeCallBack.h> 31 #include <Protocol/Arp.h> 32 #include <Protocol/Ip4.h> 33 #include <Protocol/Ip4Config2.h> 34 35 #include <Library/DebugLib.h> 36 #include <Library/DevicePathLib.h> 37 #include <Library/BaseMemoryLib.h> 38 #include <Library/MemoryAllocationLib.h> 39 #include <Library/UefiDriverEntryPoint.h> 40 #include <Library/UefiBootServicesTableLib.h> 41 #include <Library/UefiLib.h> 42 #include <Library/BaseLib.h> 43 #include <Library/NetLib.h> 44 #include <Library/DpcLib.h> 45 #include <Library/PcdLib.h> 46 47 #include "PxeBcDriver.h" 48 #include "PxeBcDhcp.h" 49 #include "PxeBcMtftp.h" 50 #include "PxeBcSupport.h" 51 52 #define PXEBC_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'X', 'E', 'P') 53 #define PXEBC_MTFTP_TIMEOUT 4 54 #define PXEBC_MTFTP_RETRIES 6 55 #define PXEBC_DEFAULT_UDP_OVERHEAD_SIZE 8 56 #define PXEBC_DEFAULT_TFTP_OVERHEAD_SIZE 4 57 #define PXEBC_DEFAULT_PACKET_SIZE 1480 58 #define PXEBC_DEFAULT_LIFETIME 50000 // 50ms, unit is microsecond 59 60 struct _PXEBC_PRIVATE_DATA { 61 UINT32 Signature; 62 EFI_HANDLE Controller; 63 EFI_HANDLE Image; 64 EFI_HANDLE ArpChild; 65 EFI_HANDLE Dhcp4Child; 66 EFI_HANDLE Ip4Child; 67 EFI_HANDLE Mtftp4Child; 68 EFI_HANDLE Udp4ReadChild; 69 EFI_HANDLE Udp4WriteChild; 70 71 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii; 72 73 EFI_PXE_BASE_CODE_PROTOCOL PxeBc; 74 EFI_LOAD_FILE_PROTOCOL LoadFile; 75 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL LoadFileCallback; 76 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *PxeBcCallback; 77 EFI_ARP_PROTOCOL *Arp; 78 EFI_DHCP4_PROTOCOL *Dhcp4; 79 EFI_IP4_PROTOCOL *Ip4; 80 EFI_IP4_CONFIG2_PROTOCOL *Ip4Config2; 81 EFI_IP4_CONFIG_DATA Ip4ConfigData; 82 EFI_MTFTP4_PROTOCOL *Mtftp4; 83 EFI_UDP4_PROTOCOL *Udp4Read; 84 EFI_UDP4_PROTOCOL *Udp4Write; 85 UINT16 CurrentUdpSrcPort; 86 EFI_UDP4_CONFIG_DATA Udp4CfgData; 87 88 89 EFI_PXE_BASE_CODE_MODE Mode; 90 EFI_PXE_BASE_CODE_FUNCTION Function; 91 92 CHAR8 *BootFileName; 93 94 EFI_IP_ADDRESS StationIp; 95 EFI_IP_ADDRESS SubnetMask; 96 EFI_IP_ADDRESS GatewayIp; 97 EFI_IP_ADDRESS ServerIp; 98 BOOLEAN AddressIsOk; 99 UINT32 Ip4MaxPacketSize; 100 UINTN BlockSize; 101 UINTN FileSize; 102 103 UINT8 OptionBuffer[PXEBC_DHCP4_MAX_OPTION_SIZE]; 104 EFI_DHCP4_PACKET SeedPacket; 105 EFI_MAC_ADDRESS Mac; 106 UINT8 MacLen; 107 108 BOOLEAN SortOffers; 109 BOOLEAN GotProxyOffer; 110 UINT32 NumOffers; 111 UINT32 SelectedOffer; 112 UINT32 ProxyOfferType; 113 114 // 115 // Cached packets as complements of pxe mode data 116 // 117 PXEBC_CACHED_DHCP4_PACKET ProxyOffer; 118 PXEBC_CACHED_DHCP4_PACKET Dhcp4Ack; 119 PXEBC_CACHED_DHCP4_PACKET PxeReply; 120 PXEBC_CACHED_DHCP4_PACKET Dhcp4Offers[PXEBC_MAX_OFFER_NUM]; 121 122 // 123 // Arrays for different types of offers: 124 // ServerCount records the count of the servers we got the offers, 125 // OfferIndex records the index of the offer sent by the server indexed by ServerCount. 126 // 127 UINT32 ServerCount[DHCP4_PACKET_TYPE_MAX]; 128 UINT32 OfferIndex[DHCP4_PACKET_TYPE_MAX][PXEBC_MAX_OFFER_NUM]; 129 UINT32 BootpIndex; 130 UINT32 ProxyIndex[DHCP4_PACKET_TYPE_MAX]; 131 UINT32 BinlIndex[PXEBC_MAX_OFFER_NUM]; 132 133 EFI_EVENT GetArpCacheEvent; 134 // 135 // token and event used to get ICMP error data from IP 136 // 137 EFI_IP4_COMPLETION_TOKEN IcmpErrorRcvToken; 138 }; 139 140 #define PXEBC_PRIVATE_DATA_FROM_PXEBC(a) CR (a, PXEBC_PRIVATE_DATA, PxeBc, PXEBC_PRIVATE_DATA_SIGNATURE) 141 142 #define PXEBC_PRIVATE_DATA_FROM_LOADFILE(a) CR (a, PXEBC_PRIVATE_DATA, LoadFile, PXEBC_PRIVATE_DATA_SIGNATURE) 143 144 #define PXEBC_PRIVATE_DATA_FROM_PXEBCCALLBACK(a) CR (a, PXEBC_PRIVATE_DATA, PxeBcCallback, PXEBC_PRIVATE_DATA_SIGNATURE) 145 146 extern EFI_PXE_BASE_CODE_PROTOCOL mPxeBcProtocolTemplate; 147 extern EFI_LOAD_FILE_PROTOCOL mLoadFileProtocolTemplate; 148 149 /** 150 Causes the driver to load a specified file. 151 152 @param This Protocol instance pointer. 153 @param FilePath The device specific path of the file to load. 154 @param BootPolicy If TRUE, indicates that the request originates from the 155 boot manager is attempting to load FilePath as a boot 156 selection. If FALSE, then FilePath must match as exact file 157 to be loaded. 158 @param BufferSize On input the size of Buffer in bytes. On output with a return 159 code of EFI_SUCCESS, the amount of data transferred to 160 Buffer. On output with a return code of EFI_BUFFER_TOO_SMALL, 161 the size of Buffer required to retrieve the requested file. 162 @param Buffer The memory buffer to transfer the file to. IF Buffer is NULL, 163 then no the size of the requested file is returned in 164 BufferSize. 165 166 @retval EFI_SUCCESS The file was loaded. 167 @retval EFI_UNSUPPORTED The device does not support the provided BootPolicy 168 @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or 169 BufferSize is NULL. 170 @retval EFI_NO_MEDIA No medium was present to load the file. 171 @retval EFI_DEVICE_ERROR The file was not loaded due to a device error. 172 @retval EFI_NO_RESPONSE The remote system did not respond. 173 @retval EFI_NOT_FOUND The file was not found. 174 @retval EFI_ABORTED The file load process was manually cancelled. 175 176 **/ 177 EFI_STATUS 178 EFIAPI 179 EfiPxeLoadFile ( 180 IN EFI_LOAD_FILE_PROTOCOL * This, 181 IN EFI_DEVICE_PATH_PROTOCOL * FilePath, 182 IN BOOLEAN BootPolicy, 183 IN OUT UINTN *BufferSize, 184 IN VOID *Buffer OPTIONAL 185 ); 186 187 #endif 188