]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/PxeBcDxe/Bc.h
edk2/MdeModulePkg/Universal/Network/PxeBcDxe/Pxe_bc_mtftp.c:
[mirror_edk2.git] / MdeModulePkg / Universal / Network / PxeBcDxe / Bc.h
1 /** @file
2
3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. 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 Module Name:
13 bc.h
14
15 Abstract:
16
17
18 **/
19
20 #ifndef _BC_H
21 #define _BC_H
22
23 #include <PiDxe.h>
24
25 #include <Guid/SmBios.h>
26 #include <IndustryStandard/SmBios.h>
27 #include <Protocol/Bis.h>
28 #include <Protocol/PxeBaseCode.h>
29 #include <Protocol/PxeBaseCodeCallBack.h>
30 #include <Protocol/NetworkInterfaceIdentifier.h>
31 #include <Protocol/SimpleNetwork.h>
32 #include <Protocol/LoadFile.h>
33 #include <Protocol/DevicePath.h>
34 #include <Protocol/Tcp.h>
35 #include <Protocol/LoadedImage.h>
36
37 #include <Library/DebugLib.h>
38 #include <Library/BaseMemoryLib.h>
39 #include <Library/MemoryAllocationLib.h>
40 #include <Library/UefiDriverEntryPoint.h>
41 #include <Library/UefiBootServicesTableLib.h>
42 #include <Library/BaseLib.h>
43 #include <Library/UefiLib.h>
44
45 #define CALLBACK_INTERVAL 100 // ten times a second
46 #define FILTER_BITS (EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP | \
47 EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST | \
48 EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS | \
49 EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST \
50 )
51
52 #define WAIT_TX_TIMEOUT 1000
53
54 #define SUPPORT_IPV6 0
55
56 #define PXE_BASECODE_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('p', 'x', 'e', 'd')
57
58 //
59 // Determine the classes of IPv4 address
60 //
61 #define IS_CLASSA_IPADDR(x) ((((EFI_IP_ADDRESS*)x)->v4.Addr[0] & 0x80) == 0x00)
62 #define IS_CLASSB_IPADDR(x) ((((EFI_IP_ADDRESS*)x)->v4.Addr[0] & 0xc0) == 0x80)
63 #define IS_CLASSC_IPADDR(x) ((((EFI_IP_ADDRESS*)x)->v4.Addr[0] & 0xe0) == 0xc0)
64 #define IS_INADDR_UNICAST(x) ((IS_CLASSA_IPADDR(x) || IS_CLASSB_IPADDR(x) || IS_CLASSC_IPADDR(x)) && (((EFI_IP_ADDRESS*)x)->Addr[0] != 0) )
65
66 //
67 // Definitions for internet group management protocol version 2 message
68 // structure
69 // Per RFC 2236, November 1997
70 //
71 #pragma pack(1)
72
73 typedef struct {
74 UINT8 Type;
75 UINT8 MaxRespTime; // in tenths of a second
76 UINT16 Checksum; // ones complement of ones complement sum of
77 // 16 bit words of message
78 UINT32 GroupAddress; // for general query, all systems group,
79 // for group specific, the group
80 } IGMPV2_MESSAGE;
81
82 #define IGMP_TYPE_QUERY 0x11
83 #define IGMP_TYPE_REPORT 0x16
84 #define IGMP_TYPE_V1REPORT 0x12
85 #define IGMP_TYPE_LEAVE_GROUP 0x17
86
87 #define IGMP_DEFAULT_MAX_RESPONSE_TIME 10 // 10 second default
88 #pragma pack()
89
90 #define MAX_MCAST_GROUPS 8 // most we allow ourselves to join at once
91 #define MAX_OFFERS 16
92
93 typedef struct {
94 UINTN Signature;
95 EFI_LOCK Lock;
96 BOOLEAN ShowErrorMessages;
97 EFI_TCP_PROTOCOL Tcp;
98 EFI_PXE_BASE_CODE_PROTOCOL EfiBc;
99 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *CallbackProtocolPtr;
100 EFI_HANDLE Handle;
101
102 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *NiiPtr;
103 EFI_SIMPLE_NETWORK_PROTOCOL *SimpleNetwork;
104 UINT8 *TransmitBufferPtr;
105 UINT8 *ReceiveBufferPtr;
106 EFI_PXE_BASE_CODE_FUNCTION Function;
107
108 UINTN OldestArpEntry;
109 UINTN MCastGroupCount;
110 EFI_EVENT Igmpv1TimeoutEvent;
111 BOOLEAN UseIgmpv1Reporting;
112 EFI_EVENT IgmpGroupEvent[MAX_MCAST_GROUPS];
113 UINT16 RandomPort;
114
115 #if SUPPORT_IPV6
116 //
117 // TBD
118 //
119 #else
120 UINT32 MCastGroup[MAX_MCAST_GROUPS];
121 #endif
122
123 BOOLEAN GoodStationIp;
124 BOOLEAN DidTransmit;
125 UINTN IpLength;
126 VOID *DhcpPacketBuffer;
127 UINTN FileSize;
128 VOID *BootServerReceiveBuffer;
129 EFI_IP_ADDRESS ServerIp;
130
131 //
132 // work area
133 // for dhcp
134 //
135 VOID *ReceiveBuffers;
136 VOID *TransmitBuffer;
137 UINTN NumOffersReceived;
138 UINT16 TotalSeconds;
139
140 //
141 // arrays for different types of offers
142 //
143 UINT8 ServerCount[4];
144 UINT8 OfferCount[4][MAX_OFFERS];
145 UINT8 GotBootp;
146 UINT8 GotProxy[4];
147 UINT8 BinlProxies[MAX_OFFERS];
148
149 UINT8 *ArpBuffer;
150 UINT8 *TftpAckBuffer;
151 UINT8 *TftpErrorBuffer;
152 IGMPV2_MESSAGE IgmpMessage;
153 BOOLEAN BigBlkNumFlag;
154 UINT8 Timeout;
155 UINT16 RandomSeed;
156 } PXE_BASECODE_DEVICE;
157
158 //
159 // type index
160 //
161 #define DHCP_ONLY_IX 0
162 #define PXE10_IX 1
163 #define WfM11a_IX 2
164 #define BINL_IX 3
165
166 #define PXE_RND_PORT_LOW 2070
167
168 //
169 //
170 //
171 #define LOADFILE_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('p', 'x', 'e', 'l')
172
173 typedef struct {
174 UINTN Signature;
175 EFI_LOCK Lock;
176 EFI_LOAD_FILE_PROTOCOL LoadFile;
177 PXE_BASECODE_DEVICE *Private;
178 } LOADFILE_DEVICE;
179
180 #define EFI_BASE_CODE_DEV_FROM_THIS(a) CR (a, PXE_BASECODE_DEVICE, efi_bc, PXE_BASECODE_DEVICE_SIGNATURE);
181
182 #define EFI_BASE_CODE_DEV_FROM_TCP(a) CR (a, PXE_BASECODE_DEVICE, Tcp, PXE_BASECODE_DEVICE_SIGNATURE);
183
184 #define EFI_LOAD_FILE_DEV_FROM_THIS(a) CR (a, LOADFILE_DEVICE, LoadFile, LOADFILE_DEVICE_SIGNATURE)
185
186 EFI_BIS_PROTOCOL *
187 PxebcBisStart (
188 PXE_BASECODE_DEVICE *Private,
189 BIS_APPLICATION_HANDLE *BisAppHandle,
190 EFI_BIS_DATA **BisDataSigInfo
191 )
192 ;
193
194 VOID
195 PxebcBisStop (
196 EFI_BIS_PROTOCOL *Bis,
197 BIS_APPLICATION_HANDLE BisAppHandle,
198 EFI_BIS_DATA *BisDataSigInfo
199 )
200 ;
201
202 BOOLEAN
203 PxebcBisVerify (
204 PXE_BASECODE_DEVICE *Private,
205 VOID *FileBuffer,
206 UINTN FileBufferLength,
207 VOID *CredentialBuffer,
208 UINTN CredentialBufferLength
209 )
210 ;
211
212 BOOLEAN
213 PxebcBisDetect (
214 PXE_BASECODE_DEVICE *Private
215 )
216 ;
217
218 //
219 // Global Variables
220 //
221 extern EFI_COMPONENT_NAME_PROTOCOL gPxeBcComponentName;
222 extern EFI_COMPONENT_NAME2_PROTOCOL gPxeBcComponentName2;
223
224 //
225 // //////////////////////////////////////////////////////////
226 //
227 // prototypes
228 //
229
230 /**
231 Initialize the base code drivers and install the driver binding
232
233 Standard EFI Image Entry
234
235 @retval EFI_SUCCESS This driver was successfully bound
236
237 **/
238 EFI_STATUS
239 EFIAPI
240 InitializeBCDriver (
241 IN EFI_HANDLE ImageHandle,
242 IN EFI_SYSTEM_TABLE *SystemTable
243 )
244 ;
245
246 EFI_STATUS
247 EFIAPI
248 BcStart (
249 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
250 IN BOOLEAN UseIpv6
251 )
252 ;
253
254 EFI_STATUS
255 EFIAPI
256 BcStop (
257 IN EFI_PXE_BASE_CODE_PROTOCOL *This
258 )
259 ;
260
261 EFI_STATUS
262 EFIAPI
263 BcDhcp (
264 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
265 IN BOOLEAN SortOffers
266 )
267 ;
268
269 EFI_STATUS
270 EFIAPI
271 BcDiscover (
272 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
273 IN UINT16 Type,
274 IN UINT16 *Layer,
275 IN BOOLEAN UseBis,
276 IN EFI_PXE_BASE_CODE_DISCOVER_INFO * Info OPTIONAL
277 )
278 ;
279
280 EFI_STATUS
281 EFIAPI
282 BcMtftp (
283 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
284 IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation,
285 IN OUT VOID *BufferPtr,
286 IN BOOLEAN Overwrite,
287 IN OUT UINT64 *BufferSize,
288 IN UINTN *BlockSize OPTIONAL,
289 IN EFI_IP_ADDRESS * ServerIp,
290 IN UINT8 *Filename,
291 IN EFI_PXE_BASE_CODE_MTFTP_INFO * Info OPTIONAL,
292 IN BOOLEAN DontUseBuffer
293 )
294 ;
295
296 EFI_STATUS
297 EFIAPI
298 BcUdpWrite (
299 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
300 IN UINT16 OpFlags,
301 IN EFI_IP_ADDRESS *DestIp,
302 IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,
303 IN EFI_IP_ADDRESS *GatewayIp, OPTIONAL
304 IN EFI_IP_ADDRESS *SrcIp, OPTIONAL
305 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort, OPTIONAL
306 IN UINTN *HeaderSize, OPTIONAL
307 IN VOID *HeaderPtr, OPTIONAL
308 IN UINTN *BufferSize,
309 IN VOID *BufferPtr
310 )
311 ;
312
313 EFI_STATUS
314 EFIAPI
315 BcUdpRead (
316 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
317 IN UINT16 OpFlags,
318 IN OUT EFI_IP_ADDRESS *DestIp, OPTIONAL
319 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort, OPTIONAL
320 IN OUT EFI_IP_ADDRESS *SrcIp, OPTIONAL
321 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort, OPTIONAL
322 IN UINTN *HeaderSize, OPTIONAL
323 IN VOID *HeaderPtr, OPTIONAL
324 IN OUT UINTN *BufferSize,
325 IN VOID *BufferPtr
326 )
327 ;
328
329 EFI_STATUS
330 EFIAPI
331 BcTcpWrite (
332 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
333 IN UINT16 OpFlags,
334 IN UINT16 *UrgentPointer,
335 IN UINT32 *SequenceNumber,
336 IN UINT32 *AckNumber,
337 IN UINT16 *HlenResCode,
338 IN UINT16 *Window,
339 IN EFI_IP_ADDRESS *DestIp,
340 IN EFI_PXE_BASE_CODE_TCP_PORT *DestPort,
341 IN EFI_IP_ADDRESS *GatewayIp, OPTIONAL
342 IN EFI_IP_ADDRESS *SrcIp, OPTIONAL
343 IN OUT EFI_PXE_BASE_CODE_TCP_PORT *SrcPort, OPTIONAL
344 IN UINTN *HeaderSize, OPTIONAL
345 IN VOID *HeaderPtr, OPTIONAL
346 IN UINTN *BufferSize,
347 IN VOID *BufferPtr
348 )
349 ;
350
351 EFI_STATUS
352 EFIAPI
353 BcTcpRead (
354 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
355 IN UINT16 OpFlags,
356 IN OUT EFI_IP_ADDRESS *DestIp, OPTIONAL
357 IN OUT EFI_PXE_BASE_CODE_TCP_PORT *DestPort, OPTIONAL
358 IN OUT EFI_IP_ADDRESS *SrcIp, OPTIONAL
359 IN OUT EFI_PXE_BASE_CODE_TCP_PORT *SrcPort, OPTIONAL
360 IN UINTN *HeaderSize, OPTIONAL
361 IN VOID *HeaderPtr, OPTIONAL
362 IN OUT UINTN *BufferSize,
363 IN VOID *BufferPtr
364 )
365 ;
366
367 EFI_STATUS
368 EFIAPI
369 BcArp (
370 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
371 IN EFI_IP_ADDRESS * IpAddr,
372 IN EFI_MAC_ADDRESS * MacAddr OPTIONAL
373 )
374 ;
375
376 EFI_STATUS
377 EFIAPI
378 BcIpFilter (
379 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
380 IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter
381 )
382 ;
383
384 EFI_STATUS
385 EFIAPI
386 BcSetParameters (
387 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
388 IN BOOLEAN *NewAutoArp, OPTIONAL
389 IN BOOLEAN *NewSendGUID, OPTIONAL
390 IN UINT8 *NewTTL, OPTIONAL
391 IN UINT8 *NewToS, OPTIONAL
392 IN BOOLEAN *NewMakeCallback OPTIONAL
393 )
394 ;
395
396 EFI_STATUS
397 EFIAPI
398 BcSetStationIP (
399 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
400 IN EFI_IP_ADDRESS * NewStationIp, OPTIONAL
401 IN EFI_IP_ADDRESS * NewSubnetMask OPTIONAL
402 )
403 ;
404
405 EFI_STATUS
406 EFIAPI
407 BcSetPackets (
408 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
409 BOOLEAN *NewDhcpDiscoverValid, OPTIONAL
410 BOOLEAN *NewDhcpAckReceived, OPTIONAL
411 BOOLEAN *NewProxyOfferReceived, OPTIONAL
412 BOOLEAN *NewPxeDiscoverValid, OPTIONAL
413 BOOLEAN *NewPxeReplyReceived, OPTIONAL
414 BOOLEAN *NewPxeBisReplyReceived, OPTIONAL
415 IN EFI_PXE_BASE_CODE_PACKET * NewDhcpDiscover, OPTIONAL
416 IN EFI_PXE_BASE_CODE_PACKET * NewDhcpAck, OPTIONAL
417 IN EFI_PXE_BASE_CODE_PACKET * NewProxyOffer, OPTIONAL
418 IN EFI_PXE_BASE_CODE_PACKET * NewPxeDiscover, OPTIONAL
419 IN EFI_PXE_BASE_CODE_PACKET * NewPxeReply, OPTIONAL
420 IN EFI_PXE_BASE_CODE_PACKET * NewPxeBisReply OPTIONAL
421 )
422 ;
423
424 EFI_STATUS
425 EFIAPI
426 LoadFile (
427 IN EFI_LOAD_FILE_PROTOCOL *This,
428 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
429 IN BOOLEAN BootPolicy,
430 IN OUT UINTN *BufferSize,
431 IN VOID *Buffer
432 )
433 ;
434
435 EFI_STATUS
436 PxeBcLibGetSmbiosSystemGuidAndSerialNumber (
437 IN EFI_GUID *SystemGuid,
438 OUT CHAR8 **SystemSerialNumber
439 )
440 ;
441
442 #include "Ip.h"
443 #include "Dhcp.h"
444 #include "Tftp.h"
445
446 #endif /* _BC_H */
447
448 /* EOF - bc.h */