]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/PxeBcDxe/Bc.h
1. Sync the latest network stack. Add NetLibCreateIPv4DPathNode () in netlib library.
[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 <Protocol/Bis.h>
27 #include <Protocol/PxeBaseCode.h>
28 #include <Protocol/PxeBaseCodeCallBack.h>
29 #include <Protocol/NetworkInterfaceIdentifier.h>
30 #include <Protocol/SimpleNetwork.h>
31 #include <Protocol/LoadFile.h>
32 #include <Protocol/DevicePath.h>
33 #include <Protocol/Tcp.h>
34
35 #include <Library/DebugLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/UefiDriverEntryPoint.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/BaseLib.h>
41 #include <Library/UefiLib.h>
42
43 #define CALLBACK_INTERVAL 100 // ten times a second
44 #define FILTER_BITS (EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP | \
45 EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST | \
46 EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS | \
47 EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST \
48 )
49
50 #define WAIT_TX_TIMEOUT 1000
51
52 #define SUPPORT_IPV6 0
53
54 #define PXE_BASECODE_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('p', 'x', 'e', 'd')
55
56 //
57 // Determine the classes of IPv4 address
58 //
59 #define IS_CLASSA_IPADDR(x) ((((EFI_IP_ADDRESS*)x)->v4.Addr[0] & 0x80) == 0x00)
60 #define IS_CLASSB_IPADDR(x) ((((EFI_IP_ADDRESS*)x)->v4.Addr[0] & 0xc0) == 0x80)
61 #define IS_CLASSC_IPADDR(x) ((((EFI_IP_ADDRESS*)x)->v4.Addr[0] & 0xe0) == 0xc0)
62 #define IS_INADDR_UNICAST(x) ((IS_CLASSA_IPADDR(x) || IS_CLASSB_IPADDR(x) || IS_CLASSC_IPADDR(x)) && (((EFI_IP_ADDRESS*)x)->Addr[0] != 0) )
63
64 //
65 // Definitions for internet group management protocol version 2 message
66 // structure
67 // Per RFC 2236, November 1997
68 //
69 #pragma pack(1)
70
71 typedef struct {
72 UINT8 Type;
73 UINT8 MaxRespTime; // in tenths of a second
74 UINT16 Checksum; // ones complement of ones complement sum of
75 // 16 bit words of message
76 UINT32 GroupAddress; // for general query, all systems group,
77 // for group specific, the group
78 } IGMPV2_MESSAGE;
79
80 #define IGMP_TYPE_QUERY 0x11
81 #define IGMP_TYPE_REPORT 0x16
82 #define IGMP_TYPE_V1REPORT 0x12
83 #define IGMP_TYPE_LEAVE_GROUP 0x17
84
85 #define IGMP_DEFAULT_MAX_RESPONSE_TIME 10 // 10 second default
86 #pragma pack()
87
88 #define MAX_MCAST_GROUPS 8 // most we allow ourselves to join at once
89 #define MAX_OFFERS 16
90
91 typedef struct {
92 UINTN Signature;
93 EFI_LOCK Lock;
94 BOOLEAN ShowErrorMessages;
95 EFI_TCP_PROTOCOL Tcp;
96 EFI_PXE_BASE_CODE_PROTOCOL EfiBc;
97 EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *CallbackProtocolPtr;
98 EFI_HANDLE Handle;
99
100 EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *NiiPtr;
101 EFI_SIMPLE_NETWORK_PROTOCOL *SimpleNetwork;
102 UINT8 *TransmitBufferPtr;
103 UINT8 *ReceiveBufferPtr;
104 EFI_PXE_BASE_CODE_FUNCTION Function;
105
106 UINTN OldestArpEntry;
107 UINTN MCastGroupCount;
108 EFI_EVENT Igmpv1TimeoutEvent;
109 BOOLEAN UseIgmpv1Reporting;
110 EFI_EVENT IgmpGroupEvent[MAX_MCAST_GROUPS];
111 UINT16 RandomPort;
112
113 #if SUPPORT_IPV6
114 //
115 // TBD
116 //
117 #else
118 UINT32 MCastGroup[MAX_MCAST_GROUPS];
119 #endif
120
121 BOOLEAN GoodStationIp;
122 BOOLEAN DidTransmit;
123 UINTN IpLength;
124 VOID *DhcpPacketBuffer;
125 UINTN FileSize;
126 VOID *BootServerReceiveBuffer;
127 EFI_IP_ADDRESS ServerIp;
128
129 //
130 // work area
131 // for dhcp
132 //
133 VOID *ReceiveBuffers;
134 VOID *TransmitBuffer;
135 UINTN NumOffersReceived;
136 UINT16 TotalSeconds;
137
138 //
139 // arrays for different types of offers
140 //
141 UINT8 ServerCount[4];
142 UINT8 OfferCount[4][MAX_OFFERS];
143 UINT8 GotBootp;
144 UINT8 GotProxy[4];
145 UINT8 BinlProxies[MAX_OFFERS];
146
147 UINT8 *ArpBuffer;
148 UINT8 *TftpAckBuffer;
149 UINT8 *TftpErrorBuffer;
150 IGMPV2_MESSAGE IgmpMessage;
151 BOOLEAN BigBlkNumFlag;
152 UINT8 Timeout;
153 UINT16 RandomSeed;
154 } PXE_BASECODE_DEVICE;
155
156 //
157 // type index
158 //
159 #define DHCP_ONLY_IX 0
160 #define PXE10_IX 1
161 #define WfM11a_IX 2
162 #define BINL_IX 3
163
164 #define PXE_RND_PORT_LOW 2070
165
166 //
167 //
168 //
169 #define LOADFILE_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('p', 'x', 'e', 'l')
170
171 typedef struct {
172 UINTN Signature;
173 EFI_LOCK Lock;
174 EFI_LOAD_FILE_PROTOCOL LoadFile;
175 PXE_BASECODE_DEVICE *Private;
176 } LOADFILE_DEVICE;
177
178 #define EFI_BASE_CODE_DEV_FROM_THIS(a) CR (a, PXE_BASECODE_DEVICE, efi_bc, PXE_BASECODE_DEVICE_SIGNATURE);
179
180 #define EFI_BASE_CODE_DEV_FROM_TCP(a) CR (a, PXE_BASECODE_DEVICE, Tcp, PXE_BASECODE_DEVICE_SIGNATURE);
181
182 #define EFI_LOAD_FILE_DEV_FROM_THIS(a) CR (a, LOADFILE_DEVICE, LoadFile, LOADFILE_DEVICE_SIGNATURE)
183
184 EFI_BIS_PROTOCOL *
185 PxebcBisStart (
186 PXE_BASECODE_DEVICE *Private,
187 BIS_APPLICATION_HANDLE *BisAppHandle,
188 EFI_BIS_DATA **BisDataSigInfo
189 )
190 ;
191
192 VOID
193 PxebcBisStop (
194 EFI_BIS_PROTOCOL *Bis,
195 BIS_APPLICATION_HANDLE BisAppHandle,
196 EFI_BIS_DATA *BisDataSigInfo
197 )
198 ;
199
200 BOOLEAN
201 PxebcBisVerify (
202 PXE_BASECODE_DEVICE *Private,
203 VOID *FileBuffer,
204 UINTN FileBufferLength,
205 VOID *CredentialBuffer,
206 UINTN CredentialBufferLength
207 )
208 ;
209
210 BOOLEAN
211 PxebcBisDetect (
212 PXE_BASECODE_DEVICE *Private
213 )
214 ;
215
216 //
217 // Global Variables
218 //
219 extern EFI_COMPONENT_NAME_PROTOCOL gPxeBcComponentName;
220
221 //
222 // //////////////////////////////////////////////////////////
223 //
224 // prototypes
225 //
226
227 /**
228 Initialize the base code drivers and install the driver binding
229
230 Standard EFI Image Entry
231
232 @retval EFI_SUCCESS This driver was successfully bound
233
234 **/
235 EFI_STATUS
236 EFIAPI
237 InitializeBCDriver (
238 IN EFI_HANDLE ImageHandle,
239 IN EFI_SYSTEM_TABLE *SystemTable
240 )
241 ;
242
243 EFI_STATUS
244 EFIAPI
245 BcStart (
246 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
247 IN BOOLEAN UseIpv6
248 )
249 ;
250
251 EFI_STATUS
252 EFIAPI
253 BcStop (
254 IN EFI_PXE_BASE_CODE_PROTOCOL *This
255 )
256 ;
257
258 EFI_STATUS
259 EFIAPI
260 BcDhcp (
261 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
262 IN BOOLEAN SortOffers
263 )
264 ;
265
266 EFI_STATUS
267 EFIAPI
268 BcDiscover (
269 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
270 IN UINT16 Type,
271 IN UINT16 *Layer,
272 IN BOOLEAN UseBis,
273 IN EFI_PXE_BASE_CODE_DISCOVER_INFO * Info OPTIONAL
274 )
275 ;
276
277 EFI_STATUS
278 EFIAPI
279 BcMtftp (
280 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
281 IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation,
282 IN OUT VOID *BufferPtr,
283 IN BOOLEAN Overwrite,
284 IN OUT UINT64 *BufferSize,
285 IN UINTN *BlockSize OPTIONAL,
286 IN EFI_IP_ADDRESS * ServerIp,
287 IN UINT8 *Filename,
288 IN EFI_PXE_BASE_CODE_MTFTP_INFO * Info OPTIONAL,
289 IN BOOLEAN DontUseBuffer
290 )
291 ;
292
293 EFI_STATUS
294 EFIAPI
295 BcUdpWrite (
296 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
297 IN UINT16 OpFlags,
298 IN EFI_IP_ADDRESS *DestIp,
299 IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,
300 IN EFI_IP_ADDRESS *GatewayIp, OPTIONAL
301 IN EFI_IP_ADDRESS *SrcIp, OPTIONAL
302 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort, OPTIONAL
303 IN UINTN *HeaderSize, OPTIONAL
304 IN VOID *HeaderPtr, OPTIONAL
305 IN UINTN *BufferSize,
306 IN VOID *BufferPtr
307 )
308 ;
309
310 EFI_STATUS
311 EFIAPI
312 BcUdpRead (
313 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
314 IN UINT16 OpFlags,
315 IN OUT EFI_IP_ADDRESS *DestIp, OPTIONAL
316 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort, OPTIONAL
317 IN OUT EFI_IP_ADDRESS *SrcIp, OPTIONAL
318 IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort, OPTIONAL
319 IN UINTN *HeaderSize, OPTIONAL
320 IN VOID *HeaderPtr, OPTIONAL
321 IN OUT UINTN *BufferSize,
322 IN VOID *BufferPtr
323 )
324 ;
325
326 EFI_STATUS
327 EFIAPI
328 BcTcpWrite (
329 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
330 IN UINT16 OpFlags,
331 IN UINT16 *UrgentPointer,
332 IN UINT32 *SequenceNumber,
333 IN UINT32 *AckNumber,
334 IN UINT16 *HlenResCode,
335 IN UINT16 *Window,
336 IN EFI_IP_ADDRESS *DestIp,
337 IN EFI_PXE_BASE_CODE_TCP_PORT *DestPort,
338 IN EFI_IP_ADDRESS *GatewayIp, OPTIONAL
339 IN EFI_IP_ADDRESS *SrcIp, OPTIONAL
340 IN OUT EFI_PXE_BASE_CODE_TCP_PORT *SrcPort, OPTIONAL
341 IN UINTN *HeaderSize, OPTIONAL
342 IN VOID *HeaderPtr, OPTIONAL
343 IN UINTN *BufferSize,
344 IN VOID *BufferPtr
345 )
346 ;
347
348 EFI_STATUS
349 EFIAPI
350 BcTcpRead (
351 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
352 IN UINT16 OpFlags,
353 IN OUT EFI_IP_ADDRESS *DestIp, OPTIONAL
354 IN OUT EFI_PXE_BASE_CODE_TCP_PORT *DestPort, OPTIONAL
355 IN OUT EFI_IP_ADDRESS *SrcIp, OPTIONAL
356 IN OUT EFI_PXE_BASE_CODE_TCP_PORT *SrcPort, OPTIONAL
357 IN UINTN *HeaderSize, OPTIONAL
358 IN VOID *HeaderPtr, OPTIONAL
359 IN OUT UINTN *BufferSize,
360 IN VOID *BufferPtr
361 )
362 ;
363
364 EFI_STATUS
365 EFIAPI
366 BcArp (
367 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
368 IN EFI_IP_ADDRESS * IpAddr,
369 IN EFI_MAC_ADDRESS * MacAddr OPTIONAL
370 )
371 ;
372
373 EFI_STATUS
374 EFIAPI
375 BcIpFilter (
376 IN EFI_PXE_BASE_CODE_PROTOCOL *This,
377 IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter
378 )
379 ;
380
381 EFI_STATUS
382 EFIAPI
383 BcSetParameters (
384 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
385 IN BOOLEAN *NewAutoArp, OPTIONAL
386 IN BOOLEAN *NewSendGUID, OPTIONAL
387 IN UINT8 *NewTTL, OPTIONAL
388 IN UINT8 *NewToS, OPTIONAL
389 IN BOOLEAN *NewMakeCallback OPTIONAL
390 )
391 ;
392
393 EFI_STATUS
394 EFIAPI
395 BcSetStationIP (
396 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
397 IN EFI_IP_ADDRESS * NewStationIp, OPTIONAL
398 IN EFI_IP_ADDRESS * NewSubnetMask OPTIONAL
399 )
400 ;
401
402 EFI_STATUS
403 EFIAPI
404 BcSetPackets (
405 IN EFI_PXE_BASE_CODE_PROTOCOL * This,
406 BOOLEAN *NewDhcpDiscoverValid, OPTIONAL
407 BOOLEAN *NewDhcpAckReceived, OPTIONAL
408 BOOLEAN *NewProxyOfferReceived, OPTIONAL
409 BOOLEAN *NewPxeDiscoverValid, OPTIONAL
410 BOOLEAN *NewPxeReplyReceived, OPTIONAL
411 BOOLEAN *NewPxeBisReplyReceived, OPTIONAL
412 IN EFI_PXE_BASE_CODE_PACKET * NewDhcpDiscover, OPTIONAL
413 IN EFI_PXE_BASE_CODE_PACKET * NewDhcpAck, OPTIONAL
414 IN EFI_PXE_BASE_CODE_PACKET * NewProxyOffer, OPTIONAL
415 IN EFI_PXE_BASE_CODE_PACKET * NewPxeDiscover, OPTIONAL
416 IN EFI_PXE_BASE_CODE_PACKET * NewPxeReply, OPTIONAL
417 IN EFI_PXE_BASE_CODE_PACKET * NewPxeBisReply OPTIONAL
418 )
419 ;
420
421 EFI_STATUS
422 EFIAPI
423 LoadFile (
424 IN EFI_LOAD_FILE_PROTOCOL *This,
425 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
426 IN BOOLEAN BootPolicy,
427 IN OUT UINTN *BufferSize,
428 IN VOID *Buffer
429 )
430 ;
431
432 EFI_STATUS
433 PxeBcLibGetSmbiosSystemGuidAndSerialNumber (
434 IN EFI_GUID *SystemGuid,
435 OUT CHAR8 **SystemSerialNumber
436 )
437 ;
438
439 #ifdef EFI_SIZE_REDUCTION_APPLIED
440 #define COMPONENT_NAME_CODE(code)
441 #define COMPONENT_NAME NULL
442 #else
443 #define COMPONENT_NAME_CODE(code) code
444 #define COMPONENT_NAME &gPxeBcComponentName
445 #endif
446
447
448 //
449 // Define SMBIOS tables.
450 //
451 #pragma pack(1)
452 typedef struct {
453 UINT8 AnchorString[4];
454 UINT8 EntryPointStructureChecksum;
455 UINT8 EntryPointLength;
456 UINT8 MajorVersion;
457 UINT8 MinorVersion;
458 UINT16 MaxStructureSize;
459 UINT8 EntryPointRevision;
460 UINT8 FormattedArea[5];
461 UINT8 IntermediateAnchorString[5];
462 UINT8 IntermediateChecksum;
463 UINT16 TableLength;
464 UINT32 TableAddress;
465 UINT16 NumberOfSmbiosStructures;
466 UINT8 SmbiosBcdRevision;
467 } SMBIOS_STRUCTURE_TABLE;
468
469 //
470 // Please note that SMBIOS structures can be odd byte aligned since the
471 // unformated section of each record is a set of arbitrary size strings.
472 //
473 typedef struct {
474 UINT8 Type;
475 UINT8 Length;
476 UINT8 Handle[2];
477 } SMBIOS_HEADER;
478
479 typedef UINT8 SMBIOS_STRING;
480
481 typedef struct {
482 SMBIOS_HEADER Hdr;
483 SMBIOS_STRING Vendor;
484 SMBIOS_STRING BiosVersion;
485 UINT8 BiosSegment[2];
486 SMBIOS_STRING BiosReleaseDate;
487 UINT8 BiosSize;
488 UINT8 BiosCharacteristics[8];
489 } SMBIOS_TYPE0;
490
491 typedef struct {
492 SMBIOS_HEADER Hdr;
493 SMBIOS_STRING Manufacturer;
494 SMBIOS_STRING ProductName;
495 SMBIOS_STRING Version;
496 SMBIOS_STRING SerialNumber;
497
498 //
499 // always byte copy this data to prevent alignment faults!
500 //
501 EFI_GUID Uuid;
502
503 UINT8 WakeUpType;
504 } SMBIOS_TYPE1;
505
506 typedef struct {
507 SMBIOS_HEADER Hdr;
508 SMBIOS_STRING Manufacturer;
509 SMBIOS_STRING ProductName;
510 SMBIOS_STRING Version;
511 SMBIOS_STRING SerialNumber;
512 } SMBIOS_TYPE2;
513
514 typedef struct {
515 SMBIOS_HEADER Hdr;
516 SMBIOS_STRING Manufacturer;
517 UINT8 Type;
518 SMBIOS_STRING Version;
519 SMBIOS_STRING SerialNumber;
520 SMBIOS_STRING AssetTag;
521 UINT8 BootupState;
522 UINT8 PowerSupplyState;
523 UINT8 ThermalState;
524 UINT8 SecurityStatus;
525 UINT8 OemDefined[4];
526 } SMBIOS_TYPE3;
527
528 typedef struct {
529 SMBIOS_HEADER Hdr;
530 UINT8 Socket;
531 UINT8 ProcessorType;
532 UINT8 ProcessorFamily;
533 SMBIOS_STRING ProcessorManufacture;
534 UINT8 ProcessorId[8];
535 SMBIOS_STRING ProcessorVersion;
536 UINT8 Voltage;
537 UINT8 ExternalClock[2];
538 UINT8 MaxSpeed[2];
539 UINT8 CurrentSpeed[2];
540 UINT8 Status;
541 UINT8 ProcessorUpgrade;
542 UINT8 L1CacheHandle[2];
543 UINT8 L2CacheHandle[2];
544 UINT8 L3CacheHandle[2];
545 } SMBIOS_TYPE4;
546
547 typedef union {
548 SMBIOS_HEADER *Hdr;
549 SMBIOS_TYPE0 *Type0;
550 SMBIOS_TYPE1 *Type1;
551 SMBIOS_TYPE2 *Type2;
552 SMBIOS_TYPE3 *Type3;
553 SMBIOS_TYPE4 *Type4;
554 UINT8 *Raw;
555 } SMBIOS_STRUCTURE_POINTER;
556 #pragma pack()
557
558 #include "ip.h"
559 #include "dhcp.h"
560 #include "tftp.h"
561
562 #endif /* _BC_H */
563
564 /* EOF - bc.h */