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