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
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.
28 PxeBcDriverSupported (
29 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
30 IN EFI_HANDLE Controller
,
31 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
37 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
38 IN EFI_HANDLE Controller
,
39 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
45 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
46 IN EFI_HANDLE Controller
,
47 IN UINTN NumberOfChildren
,
48 IN EFI_HANDLE
*ChildHandleBuffer
67 Convert number to ASCII value
69 @param Number Numeric value to convert to decimal ASCII value.
70 @param Buffer Buffer to place ASCII version of the Number
71 @param Length Length of Buffer.
86 Remainder
= Number
% 10;
88 Buffer
[Length
] = (UINT8
) ('0' + Remainder
);
94 Convert number to decimal ASCII value at Buffer location
96 @param Number Numeric value to convert to decimal ASCII value.
97 @param Buffer Buffer to place ASCII version of the Number
112 CvtNum (Number
, BuffArray
, 30);
114 for (Index
= 0; Index
< 30; ++Index
) {
115 if (BuffArray
[Index
] != '0') {
120 CopyMem (Buffer
, BuffArray
+ Index
, 31 - Index
);
125 Convert ASCII numeric string to a UINTN value
127 @param Number Numeric value to convert to decimal ASCII value.
128 @param Buffer Buffer to place ASCII version of the Number
130 @retval Value UINTN value of the ASCII string.
142 Character
= *Buffer
++;
144 Value
= Value
* 10 + Character
- '0';
145 Character
= *Buffer
++;
153 Convert ASCII numeric string to a UINTN value
155 @param Number Numeric value to convert to decimal ASCII value.
156 @param Buffer Buffer to place ASCII version of the Number
158 @retval Value UINTN value of the ASCII string.
170 while ((Character
= *Buffer
++) != '\0') {
171 Value
= MultU64x32 (Value
, 10) + (Character
- '0');
177 // random number generator
179 #define RANDOM_MULTIPLIER 2053
180 #define RANDOM_ADD_IN_VALUE 19
184 IN PXE_BASECODE_DEVICE
*Private
,
185 IN UINT16 InitialSeed
190 Initialize the Seed for the random number generator
199 if (Private
!= NULL
) {
200 Private
->RandomSeed
= InitialSeed
;
206 Generate and return a pseudo-random number
209 @retval Number UINT16 random number
214 IN PXE_BASECODE_DEVICE
*Private
219 if (Private
!= NULL
) {
220 Number
= -(INTN
) Private
->RandomSeed
* RANDOM_MULTIPLIER
+ RANDOM_ADD_IN_VALUE
;
222 return Private
->RandomSeed
= (UINT16
) Number
;
228 // calculate the internet checksum (RFC 1071)
229 // return 16 bit ones complement of ones complement sum of 16 bit words
233 Calculate the internet checksum (see RFC 1071)
235 @param Packet Buffer which contains the data to be checksummed
236 @param Length Length to be checksummed
238 @retval Checksum Returns the 16 bit ones complement of ones
239 complement sum of 16 bit words
252 Odd
= (UINT8
) (Length
& 1);
259 Sum
+= *(UINT8
*) Packet
;
262 Sum
= (Sum
& 0xffff) + (Sum
>> 16);
264 // in case above carried
268 return (UINT16
) (~ (UINT16
) Sum
);
273 Calculate the internet checksum (see RFC 1071)
274 on a non contiguous header and data
276 @param Header Buffer which contains the data to be checksummed
277 @param HeaderLen Length to be checksummed
278 @param Message Buffer which contains the data to be checksummed
279 @param MessageLen Length to be checksummed
281 @retval Checksum Returns the 16 bit ones complement of ones
282 complement sum of 16 bit words
294 UINT16 HeaderChecksum
;
295 UINT16 MessageChecksum
;
297 HeaderChecksum
= (UINT16
)~IpChecksum (Header
, HeaderLen
);
298 MessageChecksum
= (UINT16
)~IpChecksum (Message
, MessageLen
);
299 Sum
= HeaderChecksum
+ MessageChecksum
;
302 // in case above carried
306 return (UINT16
) (~ (UINT16
) Sum
);
311 Adjust the internet checksum (see RFC 1071) on a single word update.
313 @param OldChkSum Checksum previously calculated
315 @param NewWord New Value
317 @retval Checksum Returns the 16 bit ones complement of ones
318 complement sum of 16 bit words
330 sum
= ~OldChksum
+ NewWord
- OldWord
;
332 // in case above carried
335 return (UINT16
) (~ (UINT16
) sum
);
340 See if a callback is in play
342 @param Private Pointer to Pxe BaseCode Protocol
344 @retval 0 Callbacks are active on the handle
345 @retval 1 Callbacks are not active on the handle
351 IN PXE_BASECODE_DEVICE
*Private
354 Private
->EfiBc
.Mode
->MakeCallbacks
= (BOOLEAN
) (gBS
->HandleProtocol (
356 &gEfiPxeBaseCodeCallbackProtocolGuid
,
357 (VOID
*) &Private
->CallbackProtocolPtr
362 "\nMode->MakeCallbacks == %d ",
363 Private
->EfiBc
.Mode
->MakeCallbacks
)
368 "\nPrivate->CallbackProtocolPtr == %xh ",
369 Private
->CallbackProtocolPtr
)
372 if (Private
->CallbackProtocolPtr
!= NULL
) {
375 "\nCallbackProtocolPtr->Revision = %xh ",
376 Private
->CallbackProtocolPtr
->Revision
)
381 "\nCallbackProtocolPtr->Callback = %xh ",
382 Private
->CallbackProtocolPtr
->Callback
)
386 return Private
->EfiBc
.Mode
->MakeCallbacks
;
389 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
392 Routine which does an SNP->Receive over a timeout period and doing callbacks
394 @param Private Pointer to Pxe BaseCode Protocol
395 @param Function What PXE function to callback
396 @param TimeoutEvent Timer event that will trigger when we have waited
397 too long for an incoming packet
398 @param HeaderSizePtr Pointer to the size of the Header size
399 @param BufferSizePtr Pointer to the size of the Buffer size
400 @param ProtocolPtr The protocol to sniff for (namely, UDP/TCP/etc)
402 @retval 0 Something was returned
403 @retval !0 Like there was nothing to receive
404 (EFI_TIMEOUT/NOT_READY)
409 IN PXE_BASECODE_DEVICE
*Private
,
410 IN EFI_PXE_BASE_CODE_FUNCTION Function
,
411 IN EFI_EVENT TimeoutEvent
,
412 IN OUT UINTN
*HeaderSizePtr
,
413 IN OUT UINTN
*BufferSizePtr
,
414 IN OUT UINT16
*ProtocolPtr
417 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpPtr
;
418 EFI_PXE_CALLBACK CallbackPtr
;
420 EFI_EVENT CallbackEvent
;
423 // Initialize pointer to SNP interface
425 SnpPtr
= Private
->SimpleNetwork
;
428 // Initialize pointer to PxeBc callback routine - if any
430 CallbackPtr
= (Private
->EfiBc
.Mode
->MakeCallbacks
) ? Private
->CallbackProtocolPtr
->Callback
: NULL
;
433 // Create callback event and set timer
435 StatCode
= gBS
->CreateEvent (
443 if (EFI_ERROR (StatCode
)) {
444 return EFI_DEVICE_ERROR
;
448 // every 100 milliseconds
450 StatCode
= gBS
->SetTimer (
456 if (EFI_ERROR (StatCode
)) {
457 gBS
->CloseEvent (CallbackEvent
);
458 return EFI_DEVICE_ERROR
;
461 // Loop until a packet is received or a receive error is detected or
462 // a callback abort is detected or a timeout event occurs.
467 // Poll for received packet.
469 *BufferSizePtr
= BUFFER_ALLOCATE_SIZE
;
471 StatCode
= SnpPtr
->Receive (
475 Private
->ReceiveBufferPtr
,
481 if (!EFI_ERROR (StatCode
)) {
483 // Packet was received. Make received callback then return.
485 if (CallbackPtr
!= NULL
) {
486 StatCode
= CallbackPtr (
487 Private
->CallbackProtocolPtr
,
490 (UINT32
) *BufferSizePtr
,
491 (EFI_PXE_BASE_CODE_PACKET
*) Private
->ReceiveBufferPtr
494 if (StatCode
!= EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
) {
495 StatCode
= EFI_ABORTED
;
497 StatCode
= EFI_SUCCESS
;
504 if (StatCode
!= EFI_NOT_READY
) {
508 // Check for callback event.
510 if (!EFI_ERROR (gBS
->CheckEvent (CallbackEvent
))) {
512 // Make periodic callback if callback pointer is initialized.
514 if (CallbackPtr
!= NULL
) {
515 StatCode
= CallbackPtr (
516 Private
->CallbackProtocolPtr
,
524 // Abort if directed to by callback routine.
526 if (StatCode
!= EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
) {
527 StatCode
= EFI_ABORTED
;
533 // Check for timeout event.
535 if (TimeoutEvent
== 0) {
536 StatCode
= EFI_TIMEOUT
;
540 if (!EFI_ERROR (gBS
->CheckEvent (TimeoutEvent
))) {
541 StatCode
= EFI_TIMEOUT
;
545 // Check IGMP timer events.
547 IgmpCheckTimers (Private
);
550 gBS
->CloseEvent (CallbackEvent
);
557 Routine which does an SNP->Transmit of a buffer
559 @param Private Pointer to Pxe BaseCode Protocol
560 @param HeaderPtr Pointer to the buffer
561 @param PacketPtr Pointer to the packet to send
562 @param PacketLen The length of the entire packet to send
563 @param HardwareAddr Pointer to the MAC address of the destination
564 @param MediaProtocol What type of frame to create (RFC 1700) - IE.
566 @param Function What PXE function to callback
568 @retval 0 Something was sent
569 @retval !0 An error was encountered during sending of a packet
574 PXE_BASECODE_DEVICE
*Private
,
579 UINT16 MediaProtocol
,
580 IN EFI_PXE_BASE_CODE_FUNCTION Function
583 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpPtr
;
584 EFI_SIMPLE_NETWORK_MODE
*SnpModePtr
;
585 EFI_PXE_CALLBACK CallbackPtr
;
587 EFI_EVENT TimeoutEvent
;
594 CallbackPtr
= Private
->EfiBc
.Mode
->MakeCallbacks
? Private
->CallbackProtocolPtr
->Callback
: 0;
596 SnpPtr
= Private
->SimpleNetwork
;
597 SnpModePtr
= SnpPtr
->Mode
;
600 // clear prior interrupt status
602 StatCode
= SnpPtr
->GetStatus (SnpPtr
, &IntStatus
, 0);
604 if (EFI_ERROR (StatCode
)) {
607 "\nSendPacket() Exit #1 %xh (%r)",
614 Private
->DidTransmit
= FALSE
;
616 if (CallbackPtr
!= NULL
) {
618 Private
->CallbackProtocolPtr
,
623 ) != EFI_PXE_BASE_CODE_CALLBACK_STATUS_CONTINUE
) {
626 "\nSendPacket() Exit #2 %xh (%r)",
634 // put packet in transmit queue
635 // headersize should be zero if not filled in
637 StatCode
= gBS
->CreateEvent (
645 if (EFI_ERROR (StatCode
)) {
648 "Could not create transmit timeout event. %r\n",
651 return EFI_DEVICE_ERROR
;
657 StatCode
= gBS
->SetTimer (
663 if (EFI_ERROR (StatCode
)) {
666 "Could not set transmit timeout event timer. %r\n",
669 gBS
->CloseEvent (TimeoutEvent
);
670 return EFI_DEVICE_ERROR
;
674 StatCode
= SnpPtr
->Transmit (
676 (UINTN
) SnpPtr
->Mode
->MediaHeaderSize
,
677 (UINTN
) (PacketLen
+ SnpPtr
->Mode
->MediaHeaderSize
),
679 &SnpModePtr
->CurrentAddress
,
680 (EFI_MAC_ADDRESS
*) HardwareAddr
,
684 if (StatCode
!= EFI_NOT_READY
) {
688 if (!EFI_ERROR (gBS
->CheckEvent (TimeoutEvent
))) {
689 StatCode
= EFI_TIMEOUT
;
694 gBS
->CloseEvent (TimeoutEvent
);
696 if (EFI_ERROR (StatCode
)) {
699 "\nSendPacket() Exit #3 %xh (%r)",
706 // remove transmit buffer from snp's unused queue
707 // done this way in case someday things are buffered and we don't get it back
710 StatCode
= gBS
->CreateEvent (
718 if (EFI_ERROR (StatCode
)) {
721 "Could not create transmit status timeout event. %r\n",
724 return EFI_DEVICE_ERROR
;
730 StatCode
= gBS
->SetTimer (
736 if (EFI_ERROR (StatCode
)) {
739 "Could not set transmit status timeout event timer. %r\n",
742 gBS
->CloseEvent (TimeoutEvent
);
743 return EFI_DEVICE_ERROR
;
747 StatCode
= SnpPtr
->GetStatus (SnpPtr
, &IntStatus
, &TxBuf
);
749 if (EFI_ERROR (StatCode
)) {
752 "\nSendPacket() Exit #4 %xh (%r)",
759 if (IntStatus
& EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT
) {
760 Private
->DidTransmit
= TRUE
;
767 if (!EFI_ERROR (gBS
->CheckEvent (TimeoutEvent
))) {
768 StatCode
= EFI_TIMEOUT
;
773 gBS
->CloseEvent (TimeoutEvent
);
787 IN PXE_BASECODE_DEVICE
*Private
,
788 OUT BIS_APPLICATION_HANDLE
*BisAppHandle
,
789 OUT OPTIONAL EFI_BIS_DATA
**BisDataSigInfo
792 EFI_STATUS EfiStatus
;
793 EFI_HANDLE BisHandleBuffer
;
794 UINTN BisHandleCount
;
795 EFI_BIS_PROTOCOL
*BisPtr
;
796 EFI_BIS_VERSION BisInterfaceVersion
;
797 BOOLEAN BisCheckFlag
;
799 BisHandleCount
= sizeof (EFI_HANDLE
);
800 BisCheckFlag
= FALSE
;
803 // Locate BIS protocol handle (if present).
804 // If BIS protocol handle is not found, return NULL.
806 DEBUG ((DEBUG_INFO
, "\ngBS->LocateHandle() "));
808 EfiStatus
= gBS
->LocateHandle (
810 &gEfiBisProtocolGuid
,
816 if (EFI_ERROR (EfiStatus
)) {
818 // Any error means that there is no BIS.
819 // Note - It could mean that there are more than
820 // one BIS protocols installed, but that scenario
821 // is not yet supported.
825 "\nPxebcBisStart()""\n gBS->LocateHandle() %r (%xh)\n",
833 if (BisHandleCount
!= sizeof BisHandleBuffer
) {
835 // This really should never happen, but I am paranoid.
839 "\nPxebcBisStart() BisHandleCount != %d\n",
840 sizeof BisHandleBuffer
)
846 DEBUG ((DEBUG_INFO
, "BIS handle found."));
849 // Locate BIS protocol interface.
850 // If the BIS protocol interface cannot be found, return NULL.
852 DEBUG ((DEBUG_INFO
, "\ngBS->HandleProtocol() "));
854 EfiStatus
= gBS
->HandleProtocol (
856 &gEfiBisProtocolGuid
,
860 if (EFI_ERROR (EfiStatus
)) {
863 "\nPxebcBisStart()""\n gBS->HandleProtocol() %r (%xh)\n",
871 if (BisPtr
== NULL
) {
873 // This really should never happen.
877 "\nPxebcBisStart()""\n gBS->HandleProtocoL() ""BIS protocol interface pointer is NULL!\n")
883 DEBUG ((DEBUG_INFO
, "BIS protocol interface found."));
886 // Check that all of the BIS API function pointers are not NULL.
888 if (BisPtr
->Initialize
== NULL
||
889 BisPtr
->Shutdown
== NULL
||
890 BisPtr
->Free
== NULL
||
891 BisPtr
->GetBootObjectAuthorizationCertificate
== NULL
||
892 BisPtr
->GetBootObjectAuthorizationCheckFlag
== NULL
||
893 BisPtr
->GetBootObjectAuthorizationUpdateToken
== NULL
||
894 BisPtr
->GetSignatureInfo
== NULL
||
895 BisPtr
->UpdateBootObjectAuthorization
== NULL
||
896 BisPtr
->VerifyBootObject
== NULL
||
897 BisPtr
->VerifyObjectWithCredential
== NULL
902 "\nPxebcBisStart()""\n BIS protocol interface is invalid."
903 "\n At least one BIS protocol function pointer is NULL.\n"
911 // If BIS does not initialize, return NULL.
913 DEBUG ((DEBUG_INFO
, "\nBisPtr->Initialize() "));
915 BisInterfaceVersion
.Major
= BIS_VERSION_1
;
917 EfiStatus
= BisPtr
->Initialize (
920 &BisInterfaceVersion
,
924 if (EFI_ERROR (EfiStatus
)) {
927 "\nPxebcBisStart()""\n BisPtr->Initialize() %r (%xh)\n",
937 " BIS version: %d.%d",
938 BisInterfaceVersion
.Major
,
939 BisInterfaceVersion
.Minor
)
943 // If the requested BIS API version is not supported,
944 // shutdown BIS and return NULL.
946 if (BisInterfaceVersion
.Major
!= BIS_VERSION_1
) {
949 "\nPxebcBisStart()""\n BIS version %d.%d not supported by PXE BaseCode.\n",
950 BisInterfaceVersion
.Major
,
951 BisInterfaceVersion
.Minor
)
954 BisPtr
->Shutdown (*BisAppHandle
);
958 // Get BIS check flag.
959 // If the BIS check flag cannot be read, shutdown BIS and return NULL.
961 DEBUG ((DEBUG_INFO
, "\nBisPtr->GetBootObjectAuthorizationCheckFlag() "));
963 EfiStatus
= BisPtr
->GetBootObjectAuthorizationCheckFlag (*BisAppHandle
, &BisCheckFlag
);
965 if (EFI_ERROR (EfiStatus
)) {
968 "\nPxebcBisStart()""\n BisPtr->GetBootObjectAuthorizationCheckFlag() %r (%xh)\n",
973 BisPtr
->Shutdown (*BisAppHandle
);
977 // If the BIS check flag is FALSE, shutdown BIS and return NULL.
980 DEBUG ((DEBUG_INFO
, "\nBIS check flag is FALSE.\n"));
981 BisPtr
->Shutdown (*BisAppHandle
);
984 DEBUG ((DEBUG_INFO
, "\nBIS check flag is TRUE."));
987 // Early out if caller does not want signature information.
989 if (BisDataSigInfo
== NULL
) {
993 // Get BIS signature information.
994 // If the signature information cannot be read or is invalid,
995 // shutdown BIS and return NULL.
997 DEBUG ((DEBUG_INFO
, "\nBisPtr->GetSignatureInfo() "));
999 EfiStatus
= BisPtr
->GetSignatureInfo (*BisAppHandle
, BisDataSigInfo
);
1001 if (EFI_ERROR (EfiStatus
)) {
1004 "\nPxebcBisStart()""\n BisPtr_GetSignatureInfo() %r (%xh)\n",
1009 BisPtr
->Shutdown (*BisAppHandle
);
1013 if (*BisDataSigInfo
== NULL
) {
1015 // This should never happen.
1019 "\nPxebcBisStart()""\n BisPtr->GetSignatureInfo() Data pointer is NULL!\n")
1022 BisPtr
->Shutdown (*BisAppHandle
);
1026 if ((*BisDataSigInfo
)->Length
< sizeof (EFI_BIS_SIGNATURE_INFO
) ||
1027 (*BisDataSigInfo
)->Length
% sizeof (EFI_BIS_SIGNATURE_INFO
) ||
1028 (*BisDataSigInfo
)->Length
> sizeof (EFI_BIS_SIGNATURE_INFO
) * 63
1031 // This should never happen.
1035 "\nPxebcBisStart()""\n BisPtr->GetSignatureInfo() Invalid BIS siginfo length.\n")
1038 BisPtr
->Free (*BisAppHandle
, *BisDataSigInfo
);
1039 BisPtr
->Shutdown (*BisAppHandle
);
1053 EFI_BIS_PROTOCOL
*BisPtr
,
1054 BIS_APPLICATION_HANDLE BisAppHandle
,
1055 EFI_BIS_DATA
*BisDataSigInfo
1058 if (BisPtr
== NULL
) {
1062 // Free BIS allocated resources and shutdown BIS.
1063 // Return TRUE - BIS support is officially detected.
1065 if (BisDataSigInfo
!= NULL
) {
1066 BisPtr
->Free (BisAppHandle
, BisDataSigInfo
);
1069 BisPtr
->Shutdown (BisAppHandle
);
1075 @return TRUE := verified
1076 @return FALSE := not verified
1081 PXE_BASECODE_DEVICE
*Private
,
1084 VOID
*CredentialBuffer
,
1085 UINTN CredentialLength
1088 EFI_BIS_PROTOCOL
*BisPtr
;
1089 BIS_APPLICATION_HANDLE BisAppHandle
;
1090 EFI_BIS_DATA FileData
;
1091 EFI_BIS_DATA CredentialData
;
1092 EFI_STATUS EfiStatus
;
1095 if (Private
== NULL
|| FileBuffer
== NULL
|| FileLength
== 0 || CredentialBuffer
== NULL
|| CredentialLength
== 0) {
1099 BisPtr
= PxebcBisStart (Private
, &BisAppHandle
, NULL
);
1101 if (BisPtr
== NULL
) {
1105 FileData
.Length
= (UINT32
) FileLength
;
1106 FileData
.Data
= FileBuffer
;
1107 CredentialData
.Length
= (UINT32
) CredentialLength
;
1108 CredentialData
.Data
= CredentialBuffer
;
1110 EfiStatus
= BisPtr
->VerifyBootObject (
1117 PxebcBisStop (BisPtr
, BisAppHandle
, NULL
);
1119 return (BOOLEAN
) ((EFI_ERROR (EfiStatus
)) ? FALSE
: (IsVerified
? TRUE
: FALSE
));
1125 @return TRUE := BIS present
1126 @return FALSE := BIS not present
1131 PXE_BASECODE_DEVICE
*Private
1134 EFI_BIS_PROTOCOL
*BisPtr
;
1135 BIS_APPLICATION_HANDLE BisAppHandle
;
1136 EFI_BIS_DATA
*BisDataSigInfo
;
1138 BisPtr
= PxebcBisStart (Private
, &BisAppHandle
, &BisDataSigInfo
);
1140 if (BisPtr
== NULL
) {
1144 PxebcBisStop (BisPtr
, BisAppHandle
, BisDataSigInfo
);
1150 Start and initialize the BaseCode protocol, Simple Network protocol and UNDI.
1152 @param Private Pointer to Pxe BaseCode Protocol
1153 @param UseIPv6 Do we want to support IPv6?
1156 @return EFI_INVALID_PARAMETER
1157 @return EFI_UNSUPPORTED
1158 @return EFI_ALREADY_STARTED
1159 @return EFI_OUT_OF_RESOURCES
1160 @return Status is also returned from SNP.Start() and SNP.Initialize().
1166 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1170 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpPtr
;
1171 EFI_SIMPLE_NETWORK_MODE
*SnpModePtr
;
1173 EFI_STATUS StatCode
;
1174 PXE_BASECODE_DEVICE
*Private
;
1177 // Lock the instance data
1179 StatCode
= EFI_SUCCESS
;
1182 DEBUG ((DEBUG_ERROR
, "BC *This pointer == NULL"));
1183 return EFI_INVALID_PARAMETER
;
1186 Private
= CR (This
, PXE_BASECODE_DEVICE
, EfiBc
, PXE_BASECODE_DEVICE_SIGNATURE
);
1188 if (Private
== NULL
) {
1189 DEBUG ((DEBUG_ERROR
, "PXE_BASECODE_DEVICE pointer == NULL"));
1190 return EFI_INVALID_PARAMETER
;
1193 EfiAcquireLock (&Private
->Lock
);
1196 // Make sure BaseCode is not already started.
1198 if (This
->Mode
->Started
) {
1199 DEBUG ((DEBUG_WARN
, "\nBcStart() BC is already started.\n"));
1200 EfiReleaseLock (&Private
->Lock
);
1201 return EFI_ALREADY_STARTED
;
1205 // Fail if IPv6 is requested and not supported.
1208 DEBUG ((DEBUG_WARN
, "\nBcStart() IPv6 is not supported.\n"));
1209 EfiReleaseLock (&Private
->Lock
);
1210 return EFI_UNSUPPORTED
;
1213 // Setup shortcuts to SNP protocol and data structure.
1215 SnpPtr
= Private
->SimpleNetwork
;
1216 SnpModePtr
= SnpPtr
->Mode
;
1219 // Start and initialize SNP.
1221 if (SnpModePtr
->State
== EfiSimpleNetworkStopped
) {
1222 StatCode
= (*SnpPtr
->Start
) (SnpPtr
);
1224 if (SnpModePtr
->State
!= EfiSimpleNetworkStarted
) {
1225 DEBUG ((DEBUG_WARN
, "\nBcStart() Could not start SNP.\n"));
1226 EfiReleaseLock (&Private
->Lock
);
1231 // acquire memory for mode and transmit/receive buffers
1233 if (SnpModePtr
->State
== EfiSimpleNetworkStarted
) {
1234 StatCode
= (*SnpPtr
->Initialize
) (SnpPtr
, 0, 0);
1236 if (SnpModePtr
->State
!= EfiSimpleNetworkInitialized
) {
1237 DEBUG ((DEBUG_WARN
, "\nBcStart() Could not initialize SNP."));
1238 EfiReleaseLock (&Private
->Lock
);
1245 DEBUG ((DEBUG_INFO
, "\nBC Start()"));
1248 "\nSnpModePtr->State %Xh",
1253 "\nSnpModePtr->HwAddressSize %Xh",
1254 SnpModePtr
->HwAddressSize
)
1258 "\nSnpModePtr->MediaHeaderSize %Xh",
1259 SnpModePtr
->MediaHeaderSize
)
1263 "\nSnpModePtr->MaxPacketSize %Xh",
1264 SnpModePtr
->MaxPacketSize
)
1268 "\nSnpModePtr->MacAddressChangeable %Xh",
1269 SnpModePtr
->MacAddressChangeable
)
1273 "\nSnpModePtr->MultipleTxSupported %Xh",
1274 SnpModePtr
->MultipleTxSupported
)
1278 "\nSnpModePtr->CurrentAddress %Xh",
1279 *((UINTN
*)&SnpModePtr
->CurrentAddress
))
1283 "\nSnpModePtr->BroadcastAddress %Xh",
1284 *((UINTN
*)&SnpModePtr
->BroadcastAddress
))
1288 "\nSnpModePtr->PermanentAddress %Xh",
1289 *((UINTN
*)&SnpModePtr
->PermanentAddress
))
1293 "\nSnpModePtr->NvRamSize %Xh",
1294 SnpModePtr
->NvRamSize
)
1298 "\nSnpModePtr->NvRamAccessSize %Xh",
1299 SnpModePtr
->NvRamAccessSize
)
1303 "\nSnpModePtr->ReceiveFilterMask %Xh",
1304 SnpModePtr
->ReceiveFilterMask
)
1308 "\nSnpModePtr->ReceiveFilterSetting %Xh",
1309 SnpModePtr
->ReceiveFilterSetting
)
1313 "\nSnpModePtr->MCastFilterCount %Xh",
1314 SnpModePtr
->MCastFilterCount
)
1318 "\nSnpModePtr->MCastFilter %Xh",
1319 SnpModePtr
->MCastFilter
)
1323 "\nSnpModePtr->IfType %Xh",
1328 "\nSnpModePtr->MediaPresentSupported %Xh",
1329 SnpModePtr
->MediaPresentSupported
)
1333 "\nSnpModePtr->MediaPresent %Xh",
1334 SnpModePtr
->MediaPresent
)
1338 // If media check is supported and there is no media,
1339 // return error to caller.
1341 if (SnpModePtr
->MediaPresentSupported
&& !SnpModePtr
->MediaPresent
) {
1342 DEBUG ((DEBUG_WARN
, "\nBcStart() Media not present.\n"));
1343 EfiReleaseLock (&Private
->Lock
);
1344 return EFI_NO_MEDIA
;
1347 // Allocate Tx/Rx buffers
1349 Status
= gBS
->AllocatePool (
1350 EfiBootServicesData
,
1351 BUFFER_ALLOCATE_SIZE
,
1352 (VOID
**) &Private
->TransmitBufferPtr
1355 if (!EFI_ERROR (Status
)) {
1356 ZeroMem (Private
->TransmitBufferPtr
, BUFFER_ALLOCATE_SIZE
);
1358 DEBUG ((DEBUG_NET
, "\nBcStart() Could not alloc TxBuf.\n"));
1359 EfiReleaseLock (&Private
->Lock
);
1360 return EFI_OUT_OF_RESOURCES
;
1363 Status
= gBS
->AllocatePool (
1364 EfiBootServicesData
,
1365 BUFFER_ALLOCATE_SIZE
,
1366 (VOID
**) &Private
->ReceiveBufferPtr
1369 if (!EFI_ERROR (Status
)) {
1370 ZeroMem (Private
->ReceiveBufferPtr
, BUFFER_ALLOCATE_SIZE
);
1372 DEBUG ((DEBUG_NET
, "\nBcStart() Could not alloc RxBuf.\n"));
1373 gBS
->FreePool (Private
->TransmitBufferPtr
);
1374 EfiReleaseLock (&Private
->Lock
);
1375 return EFI_OUT_OF_RESOURCES
;
1378 Status
= gBS
->AllocatePool (
1379 EfiBootServicesData
,
1381 (VOID
**) &Private
->TftpErrorBuffer
1384 if (EFI_ERROR (Status
)) {
1385 gBS
->FreePool (Private
->ReceiveBufferPtr
);
1386 gBS
->FreePool (Private
->TransmitBufferPtr
);
1387 EfiReleaseLock (&Private
->Lock
);
1388 return EFI_OUT_OF_RESOURCES
;
1391 Status
= gBS
->AllocatePool (EfiBootServicesData
, 256, (VOID
**) &Private
->TftpAckBuffer
);
1393 if (EFI_ERROR (Status
)) {
1394 gBS
->FreePool (Private
->TftpErrorBuffer
);
1395 gBS
->FreePool (Private
->ReceiveBufferPtr
);
1396 gBS
->FreePool (Private
->TransmitBufferPtr
);
1397 EfiReleaseLock (&Private
->Lock
);
1398 return EFI_OUT_OF_RESOURCES
;
1401 // Initialize private BaseCode instance data
1404 Private
->RandomPort
= (UINT16
) (Private
->RandomPort
+ PXE_RND_PORT_LOW
+ Random (Private
));
1405 } while (Private
->RandomPort
< PXE_RND_PORT_LOW
);
1407 Private
->Igmpv1TimeoutEvent
= NULL
;
1408 Private
->UseIgmpv1Reporting
= TRUE
;
1409 Private
->IpLength
= IP_ADDRESS_LENGTH (Private
->EfiBc
.Mode
);
1412 // Initialize Mode structure
1414 ZeroMem (Private
->EfiBc
.Mode
, sizeof (EFI_PXE_BASE_CODE_MODE
));
1416 // check for callback protocol and set boolean
1418 SetMakeCallback (Private
);
1419 Private
->EfiBc
.Mode
->Started
= TRUE
;
1420 Private
->EfiBc
.Mode
->TTL
= DEFAULT_TTL
;
1421 Private
->EfiBc
.Mode
->ToS
= DEFAULT_ToS
;
1422 Private
->EfiBc
.Mode
->UsingIpv6
= UseIPv6
;
1425 // Set to PXE_TRUE by the BC constructor if this BC implementation
1428 Private
->EfiBc
.Mode
->Ipv6Supported
= SUPPORT_IPV6
;
1430 Private
->EfiBc
.Mode
->Ipv6Available
= FALSE
;
1432 // Set to TRUE by the BC constructor if this BC implementation
1435 Private
->EfiBc
.Mode
->BisSupported
= TRUE
;
1436 Private
->EfiBc
.Mode
->BisDetected
= PxebcBisDetect (Private
);
1439 // This field is set to PXE_TRUE by the BC Start() function. When this
1440 // field is PXE_TRUE, ARP packets are sent as needed to get IP and MAC
1441 // addresses. This can cause unexpected delays in the DHCP(), Discover()
1442 // and MTFTP() functions. Setting this to PXE_FALSE will cause these
1443 // functions to fail if the required IP/MAC information is not in the
1444 // ARP cache. The value of this field can be changed by an application
1447 Private
->EfiBc
.Mode
->AutoArp
= TRUE
;
1450 // Unlock the instance data
1452 EfiReleaseLock (&Private
->Lock
);
1458 Stop the BaseCode protocol, Simple Network protocol and UNDI.
1460 @param Private Pointer to Pxe BaseCode Protocol
1462 @retval 0 Successfully stopped
1469 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
1473 // Lock the instance data
1475 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpPtr
;
1476 EFI_SIMPLE_NETWORK_MODE
*SnpModePtr
;
1477 EFI_STATUS StatCode
;
1478 PXE_BASECODE_DEVICE
*Private
;
1480 StatCode
= EFI_SUCCESS
;
1483 DEBUG ((DEBUG_ERROR
, "BC *This pointer == NULL"));
1484 return EFI_INVALID_PARAMETER
;
1487 Private
= CR (This
, PXE_BASECODE_DEVICE
, EfiBc
, PXE_BASECODE_DEVICE_SIGNATURE
);
1489 if (Private
== NULL
) {
1490 DEBUG ((DEBUG_ERROR
, "PXE_BASECODE_DEVICE poiner == NULL"));
1491 return EFI_INVALID_PARAMETER
;
1494 EfiAcquireLock (&Private
->Lock
);
1496 SnpPtr
= Private
->SimpleNetwork
;
1497 SnpModePtr
= SnpPtr
->Mode
;
1502 StatCode
= EFI_NOT_STARTED
;
1504 if (SnpModePtr
->State
== EfiSimpleNetworkInitialized
) {
1505 StatCode
= (*SnpPtr
->Shutdown
) (SnpPtr
);
1508 if (SnpModePtr
->State
== EfiSimpleNetworkStarted
) {
1509 StatCode
= (*SnpPtr
->Stop
) (SnpPtr
);
1512 if (Private
->TransmitBufferPtr
!= NULL
) {
1513 gBS
->FreePool (Private
->TransmitBufferPtr
);
1514 Private
->TransmitBufferPtr
= NULL
;
1517 if (Private
->ReceiveBufferPtr
!= NULL
) {
1518 gBS
->FreePool (Private
->ReceiveBufferPtr
);
1519 Private
->ReceiveBufferPtr
= NULL
;
1522 if (Private
->ArpBuffer
!= NULL
) {
1523 gBS
->FreePool (Private
->ArpBuffer
);
1524 Private
->ArpBuffer
= NULL
;
1527 if (Private
->TftpErrorBuffer
!= NULL
) {
1528 gBS
->FreePool (Private
->TftpErrorBuffer
);
1529 Private
->TftpErrorBuffer
= NULL
;
1532 if (Private
->TftpAckBuffer
!= NULL
) {
1533 gBS
->FreePool (Private
->TftpAckBuffer
);
1534 Private
->TftpAckBuffer
= NULL
;
1537 if (Private
->Igmpv1TimeoutEvent
!= NULL
) {
1538 gBS
->CloseEvent (Private
->Igmpv1TimeoutEvent
);
1539 Private
->Igmpv1TimeoutEvent
= NULL
;
1542 Private
->FileSize
= 0;
1544 if (!Private
->EfiBc
.Mode
->Started
) {
1545 StatCode
= EFI_NOT_STARTED
;
1547 Private
->EfiBc
.Mode
->Started
= FALSE
;
1551 // Unlock the instance data
1553 EfiReleaseLock (&Private
->Lock
);
1557 const IPV4_ADDR AllSystemsGroup
= {{224, 0, 0, 1}};
1561 Set up the IP filter
1563 @param Private Pointer to Pxe BaseCode Protocol
1564 @param Filter Pointer to the filter
1566 @retval 0 Successfully set the filter
1572 IN PXE_BASECODE_DEVICE
*Private
,
1573 IN EFI_PXE_BASE_CODE_IP_FILTER
*Filter
1576 EFI_STATUS StatCode
;
1577 EFI_MAC_ADDRESS MACadds
[PXE_IP_FILTER_SIZE
];
1578 EFI_PXE_BASE_CODE_MODE
*PxebcMode
;
1579 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpPtr
;
1580 EFI_SIMPLE_NETWORK_MODE
*SnpModePtr
;
1586 PxebcMode
= Private
->EfiBc
.Mode
;
1587 SnpPtr
= Private
->SimpleNetwork
;
1588 SnpModePtr
= SnpPtr
->Mode
;
1591 // validate input parameters
1592 // must have a filter
1593 // must not have any extra filter bits set
1595 if (Filter
== NULL
||
1596 (Filter
->Filters
&~FILTER_BITS
)
1598 // must not have a count which is too large or with no IP list
1601 (Filter
->IpCnt
&& (!Filter
->IpList
|| Filter
->IpCnt
> PXE_IP_FILTER_SIZE
))
1603 // must not have incompatible filters - promiscuous incompatible with anything else
1607 (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) &&
1608 ((Filter
->Filters
&~EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) || Filter
->IpCnt
)
1611 DEBUG ((DEBUG_INFO
, "\nIpFilter() Exit #1"));
1612 return EFI_INVALID_PARAMETER
;
1615 // promiscuous multicast incompatible with multicast in IP list
1617 if (Filter
->IpCnt
&& (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
)) {
1618 for (Index
= 0; Index
< Filter
->IpCnt
; ++Index
) {
1619 if (IS_MULTICAST (&Filter
->IpList
[Index
])) {
1620 DEBUG ((DEBUG_INFO
, "\nIpFilter() Exit #2"));
1621 return EFI_INVALID_PARAMETER
;
1626 // leave groups for all those multicast which are no longer enabled
1628 for (Index
= 0; Index
< PxebcMode
->IpFilter
.IpCnt
; ++Index
) {
1629 if (!IS_MULTICAST (&PxebcMode
->IpFilter
.IpList
[Index
])) {
1633 for (Index2
= 0; Index2
< Filter
->IpCnt
; ++Index2
) {
1634 if (!CompareMem (&PxebcMode
->IpFilter
.IpList
[Index
], &Filter
->IpList
[Index2
], IP_ADDRESS_LENGTH (PxebcMode
))) {
1642 // if we didn't find it, remove from group
1644 if (Index2
== Filter
->IpCnt
) {
1645 IgmpLeaveGroup (Private
, &PxebcMode
->IpFilter
.IpList
[Index
]);
1649 // set enable bits, convert multicast ip adds, join groups
1650 // allways leave receive broadcast enabled at hardware layer
1654 if (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) {
1655 Enable
= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS
;
1657 if (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) {
1658 Enable
= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST
;
1660 Enable
= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
;
1662 for (Index
= 0; Index
< Filter
->IpCnt
; ++Index
) {
1663 CopyMem (&PxebcMode
->IpFilter
.IpList
[Index
], &Filter
->IpList
[Index
], sizeof (EFI_IP_ADDRESS
));
1665 if (IS_MULTICAST (&Filter
->IpList
[Index
])) {
1666 EFI_IP_ADDRESS
*TmpIp
;
1668 Enable
|= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
;
1671 // if this is the first group, add the all systems group to mcast list
1675 TmpIp
= (EFI_IP_ADDRESS
*) &AllSystemsGroup
;
1678 TmpIp
= (EFI_IP_ADDRESS
*) &Filter
->IpList
[Index
];
1681 // get MAC address of IP
1683 StatCode
= (*SnpPtr
->MCastIpToMac
) (SnpPtr
, PxebcMode
->UsingIpv6
, TmpIp
, &MACadds
[Index2
++]);
1685 if (EFI_ERROR (StatCode
)) {
1688 "\nIpFilter() Exit #2 %Xh (%r)",
1695 Enable
|= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
;
1700 if (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) {
1701 Enable
|= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
;
1705 // if nothing changed, just return
1709 "\nsnp->ReceiveFilterSetting == %Xh Filter->IpCnt == %Xh",
1710 SnpModePtr
->ReceiveFilterSetting
,
1714 if (SnpModePtr
->ReceiveFilterSetting
== Enable
&& !Filter
->IpCnt
) {
1715 DEBUG ((DEBUG_INFO
, "\nIpFilter() Exit #4"));
1719 // disable those currently set but not set in new filter
1721 Disable
= SnpModePtr
->ReceiveFilterSetting
&~Enable
;
1723 StatCode
= SnpPtr
->ReceiveFilters (SnpPtr
, Enable
, Disable
, FALSE
, Index2
, MACadds
);
1725 PxebcMode
->IpFilter
.IpCnt
= Filter
->IpCnt
;
1728 // join groups for all multicast in list
1730 for (Index
= 0; Index
< Filter
->IpCnt
; ++Index
) {
1731 if (IS_MULTICAST (&Filter
->IpList
[Index
])) {
1732 IgmpJoinGroup (Private
, &Filter
->IpList
[Index
]);
1736 DEBUG ((DEBUG_INFO
, "\nIpFilter() Exit #5 %Xh (%r)", StatCode
, StatCode
));
1745 @param Private Pointer to Pxe BaseCode Protocol
1746 @param Filter Pointer to the filter
1748 @retval 0 Successfully set the filter
1755 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1756 IN EFI_PXE_BASE_CODE_IP_FILTER
*Filter
1759 EFI_STATUS StatCode
;
1760 PXE_BASECODE_DEVICE
*Private
;
1763 // Lock the instance data and make sure started
1765 StatCode
= EFI_SUCCESS
;
1768 DEBUG ((DEBUG_ERROR
, "BC *This pointer == NULL"));
1769 return EFI_INVALID_PARAMETER
;
1772 Private
= CR (This
, PXE_BASECODE_DEVICE
, EfiBc
, PXE_BASECODE_DEVICE_SIGNATURE
);
1774 if (Private
== NULL
) {
1775 DEBUG ((DEBUG_ERROR
, "PXE_BASECODE_DEVICE poiner == NULL"));
1776 return EFI_INVALID_PARAMETER
;
1779 for (Index
= 0; Index
< Filter
->IpCnt
; ++Index
) {
1780 if ((Filter
->IpList
[Index
].Addr
[0]) == BROADCAST_IPv4
) {
1782 // The IP is a broadcast address.
1784 return EFI_INVALID_PARAMETER
;
1788 EfiAcquireLock (&Private
->Lock
);
1790 if (This
->Mode
== NULL
|| !This
->Mode
->Started
) {
1791 DEBUG ((DEBUG_ERROR
, "BC was not started."));
1792 EfiReleaseLock (&Private
->Lock
);
1793 return EFI_NOT_STARTED
;
1796 if (Filter
== NULL
) {
1797 return EFI_INVALID_PARAMETER
;
1802 StatCode
= IpFilter (Private
, Filter
);
1805 // Unlock the instance data
1807 EfiReleaseLock (&Private
->Lock
);
1813 Set the Base Code behavior parameters
1815 @param This Pointer to Pxe BaseCode Protocol
1816 @param AutoArpPtr Boolean to do ARP stuff
1817 @param SendGuidPtr Boolean whether or not to send GUID info
1818 @param TimeToLivePtr Value for Total time to live
1819 @param TypeOfServicePtr Value for Type of Service
1820 @param MakeCallbackPtr Boolean to determine if we make callbacks
1822 @retval 0 Successfully set the parameters
1829 EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1830 BOOLEAN
*AutoArpPtr
,
1831 BOOLEAN
*SendGuidPtr
,
1832 UINT8
*TimeToLivePtr
,
1833 UINT8
*TypeOfServicePtr
,
1834 BOOLEAN
*MakeCallbackPtr
1837 EFI_PXE_BASE_CODE_MODE
*PxebcMode
;
1839 UINT8
*SerialNumberPtr
;
1840 EFI_STATUS StatCode
;
1841 PXE_BASECODE_DEVICE
*Private
;
1844 // Lock the instance data and make sure started
1846 StatCode
= EFI_SUCCESS
;
1849 DEBUG ((DEBUG_ERROR
, "BC *This pointer == NULL"));
1850 return EFI_INVALID_PARAMETER
;
1853 Private
= CR (This
, PXE_BASECODE_DEVICE
, EfiBc
, PXE_BASECODE_DEVICE_SIGNATURE
);
1855 if (Private
== NULL
) {
1856 DEBUG ((DEBUG_ERROR
, "PXE_BASECODE_DEVICE poiner == NULL"));
1857 return EFI_INVALID_PARAMETER
;
1860 EfiAcquireLock (&Private
->Lock
);
1862 if (This
->Mode
== NULL
|| !This
->Mode
->Started
) {
1863 DEBUG ((DEBUG_ERROR
, "BC was not started."));
1864 EfiReleaseLock (&Private
->Lock
);
1865 return EFI_NOT_STARTED
;
1868 DEBUG ((DEBUG_INFO
, "\nSetParameters() Entry. "));
1870 PxebcMode
= Private
->EfiBc
.Mode
;
1871 StatCode
= EFI_SUCCESS
;
1873 if (SendGuidPtr
!= NULL
) {
1875 if (PxeBcLibGetSmbiosSystemGuidAndSerialNumber (&TmpGuid
, (CHAR8
**) &SerialNumberPtr
) != EFI_SUCCESS
) {
1876 return EFI_INVALID_PARAMETER
;
1881 if (MakeCallbackPtr
!= NULL
) {
1882 if (*MakeCallbackPtr
) {
1883 if (!SetMakeCallback (Private
)) {
1884 return EFI_INVALID_PARAMETER
;
1888 PxebcMode
->MakeCallbacks
= *MakeCallbackPtr
;
1891 if (AutoArpPtr
!= NULL
) {
1892 PxebcMode
->AutoArp
= *AutoArpPtr
;
1895 if (SendGuidPtr
!= NULL
) {
1896 PxebcMode
->SendGUID
= *SendGuidPtr
;
1899 if (TimeToLivePtr
!= NULL
) {
1900 PxebcMode
->TTL
= *TimeToLivePtr
;
1903 if (TypeOfServicePtr
!= NULL
) {
1904 PxebcMode
->ToS
= *TypeOfServicePtr
;
1907 // Unlock the instance data
1909 DEBUG ((DEBUG_INFO
, "\nSetparameters() Exit = %xh ", StatCode
));
1911 EfiReleaseLock (&Private
->Lock
);
1915 // //////////////////////////////////////////////////////////
1917 // BC Set Station IP Routine
1921 Set the station IP address
1923 @param This Pointer to Pxe BaseCode Protocol
1924 @param StationIpPtr Pointer to the requested IP address to set in base
1926 @param SubnetMaskPtr Pointer to the requested subnet mask for the base
1929 @retval EFI_SUCCESS Successfully set the parameters
1930 @retval EFI_NOT_STARTED BC has not started
1936 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1937 IN EFI_IP_ADDRESS
*StationIpPtr
,
1938 IN EFI_IP_ADDRESS
*SubnetMaskPtr
1941 EFI_PXE_BASE_CODE_MODE
*PxebcMode
;
1942 EFI_STATUS StatCode
;
1943 PXE_BASECODE_DEVICE
*Private
;
1947 // Lock the instance data and make sure started
1949 StatCode
= EFI_SUCCESS
;
1952 DEBUG ((DEBUG_ERROR
, "BC *This pointer == NULL"));
1953 return EFI_INVALID_PARAMETER
;
1956 Private
= CR (This
, PXE_BASECODE_DEVICE
, EfiBc
, PXE_BASECODE_DEVICE_SIGNATURE
);
1958 if (Private
== NULL
) {
1959 DEBUG ((DEBUG_ERROR
, "PXE_BASECODE_DEVICE poiner == NULL"));
1960 return EFI_INVALID_PARAMETER
;
1963 EfiAcquireLock (&Private
->Lock
);
1965 if (This
->Mode
== NULL
|| !This
->Mode
->Started
) {
1966 DEBUG ((DEBUG_ERROR
, "BC was not started."));
1967 StatCode
= EFI_NOT_STARTED
;
1971 PxebcMode
= Private
->EfiBc
.Mode
;
1973 if (!Private
->GoodStationIp
&& ((StationIpPtr
== NULL
) || (SubnetMaskPtr
== NULL
))) {
1975 // It's not allowed to only set one of the two addresses while there isn't a previous
1976 // GOOD address configuration.
1978 StatCode
= EFI_INVALID_PARAMETER
;
1982 if (SubnetMaskPtr
!= NULL
) {
1983 SubnetMask
= SubnetMaskPtr
->Addr
[0];
1985 if (SubnetMask
& (SubnetMask
+ 1)) {
1987 // the subnet mask is valid if it's with leading continuous 1 bits.
1989 StatCode
= EFI_INVALID_PARAMETER
;
1993 SubnetMaskPtr
= &PxebcMode
->SubnetMask
;
1994 SubnetMask
= SubnetMaskPtr
->Addr
[0];
1997 if (StationIpPtr
== NULL
) {
1998 StationIpPtr
= &PxebcMode
->StationIp
;
2001 if (!IS_INADDR_UNICAST (StationIpPtr
) ||
2002 ((StationIpPtr
->Addr
[0] | SubnetMask
) == BROADCAST_IPv4
)) {
2004 // The station IP is not a unicast address.
2006 StatCode
= EFI_INVALID_PARAMETER
;
2010 CopyMem (&PxebcMode
->StationIp
, StationIpPtr
, sizeof (EFI_IP_ADDRESS
));
2011 CopyMem (&PxebcMode
->SubnetMask
, SubnetMaskPtr
, sizeof (EFI_IP_ADDRESS
));
2012 Private
->GoodStationIp
= TRUE
;
2016 // Unlock the instance data
2018 EfiReleaseLock (&Private
->Lock
);
2023 EFI_DRIVER_BINDING_PROTOCOL mPxeBcDriverBinding
= {
2024 PxeBcDriverSupported
,
2034 Test to see if this driver supports Controller. Any Controller
2035 than contains a Snp protocol can be supported.
2037 @param This Protocol instance pointer.
2038 @param Controller Handle of device to test.
2039 @param RemainingDevicePath Not used.
2041 @retval EFI_SUCCESS This driver supports this device.
2042 @retval EFI_ALREADY_STARTED This driver is already running on this device.
2043 @retval other This driver does not support this device.
2048 PxeBcDriverSupported (
2049 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
2050 IN EFI_HANDLE Controller
,
2051 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
2055 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpPtr
;
2057 Status
= gBS
->OpenProtocol (
2059 &gEfiDevicePathProtocolGuid
,
2061 This
->DriverBindingHandle
,
2063 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
2066 if (EFI_ERROR (Status
)) {
2070 Status
= gBS
->OpenProtocol (
2072 &gEfiSimpleNetworkProtocolGuid
,
2074 This
->DriverBindingHandle
,
2076 EFI_OPEN_PROTOCOL_BY_DRIVER
2078 if (EFI_ERROR (Status
)) {
2082 gBS
->CloseProtocol (
2084 &gEfiSimpleNetworkProtocolGuid
,
2085 This
->DriverBindingHandle
,
2094 Start the Base code driver.
2096 @param This Protocol instance pointer.
2097 @param Controller Handle of device to test.
2098 @param RemainingDevicePath Not used.
2100 @retval EFI_SUCCESS This driver supports this device.
2101 @retval EFI_ALREADY_STARTED This driver is already running on this device.
2102 @retval other This driver does not support this device.
2108 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
2109 IN EFI_HANDLE Controller
,
2110 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
2114 PXE_BASECODE_DEVICE
*Private
;
2115 LOADFILE_DEVICE
*pLF
;
2118 // Allocate structures needed by BaseCode and LoadFile protocols.
2120 Private
= AllocateZeroPool (sizeof (PXE_BASECODE_DEVICE
));
2122 if (Private
== NULL
) {
2123 DEBUG ((EFI_D_NET
, "\nBcNotifySnp() Could not alloc PXE_BASECODE_DEVICE structure.\n"));
2124 return EFI_OUT_OF_RESOURCES
;
2127 pLF
= AllocateZeroPool (sizeof (LOADFILE_DEVICE
));
2129 DEBUG ((EFI_D_NET
, "\nBcNotifySnp() Could not alloc LOADFILE_DEVICE structure.\n"));
2131 return EFI_OUT_OF_RESOURCES
;
2134 Private
->EfiBc
.Mode
= AllocateZeroPool (sizeof (EFI_PXE_BASE_CODE_MODE
));
2135 if (Private
->EfiBc
.Mode
== NULL
) {
2136 DEBUG ((EFI_D_NET
, "\nBcNotifySnp() Could not alloc Mode structure.\n"));
2139 return EFI_OUT_OF_RESOURCES
;
2142 // Lock access, just in case
2144 EfiInitializeLock (&Private
->Lock
, TPL_CALLBACK
);
2145 EfiAcquireLock (&Private
->Lock
);
2147 EfiInitializeLock (&pLF
->Lock
, TPL_CALLBACK
);
2148 EfiAcquireLock (&pLF
->Lock
);
2151 // Initialize PXE structure
2154 // First initialize the internal 'private' data that the application
2157 Private
->Signature
= PXE_BASECODE_DEVICE_SIGNATURE
;
2158 Private
->Handle
= Controller
;
2161 // Get the NII interface
2163 Status
= gBS
->OpenProtocol (
2165 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
2166 (VOID
**) &Private
->NiiPtr
,
2167 This
->DriverBindingHandle
,
2169 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2172 if (EFI_ERROR (Status
)) {
2177 // Get the Snp interface
2179 Status
= gBS
->OpenProtocol (
2181 &gEfiSimpleNetworkProtocolGuid
,
2182 (VOID
**) &Private
->SimpleNetwork
,
2183 This
->DriverBindingHandle
,
2185 EFI_OPEN_PROTOCOL_BY_DRIVER
2188 if (EFI_ERROR (Status
)) {
2193 // Next, initialize the external 'public' data that
2194 // the application does see.
2196 Private
->EfiBc
.Revision
= EFI_PXE_BASE_CODE_PROTOCOL_REVISION
;
2197 Private
->EfiBc
.Start
= BcStart
;
2198 Private
->EfiBc
.Stop
= BcStop
;
2199 Private
->EfiBc
.Dhcp
= BcDhcp
;
2200 Private
->EfiBc
.Discover
= BcDiscover
;
2201 Private
->EfiBc
.Mtftp
= BcMtftp
;
2202 Private
->EfiBc
.UdpWrite
= BcUdpWrite
;
2203 Private
->EfiBc
.UdpRead
= BcUdpRead
;
2204 Private
->EfiBc
.Arp
= BcArp
;
2205 Private
->EfiBc
.SetIpFilter
= BcIpFilter
;
2206 Private
->EfiBc
.SetParameters
= BcSetParameters
;
2207 Private
->EfiBc
.SetStationIp
= BcSetStationIP
;
2208 Private
->EfiBc
.SetPackets
= BcSetPackets
;
2211 // Initialize BaseCode Mode structure
2213 Private
->EfiBc
.Mode
->Started
= FALSE
;
2214 Private
->EfiBc
.Mode
->TTL
= DEFAULT_TTL
;
2215 Private
->EfiBc
.Mode
->ToS
= DEFAULT_ToS
;
2216 Private
->EfiBc
.Mode
->UsingIpv6
= FALSE
;
2217 Private
->EfiBc
.Mode
->AutoArp
= TRUE
;
2220 // Set to PXE_TRUE by the BC constructor if this BC
2221 // implementation supports IPv6.
2223 Private
->EfiBc
.Mode
->Ipv6Supported
= SUPPORT_IPV6
;
2224 Private
->EfiBc
.Mode
->Ipv6Available
= FALSE
;
2227 // Set to TRUE by the BC constructor if this BC
2228 // implementation supports BIS.
2230 Private
->EfiBc
.Mode
->BisSupported
= TRUE
;
2231 Private
->EfiBc
.Mode
->BisDetected
= PxebcBisDetect (Private
);
2234 // Initialize LoadFile structure.
2236 pLF
->Signature
= LOADFILE_DEVICE_SIGNATURE
;
2237 pLF
->LoadFile
.LoadFile
= LoadFile
;
2238 pLF
->Private
= Private
;
2241 // Install protocol interfaces.
2243 Status
= gBS
->InstallMultipleProtocolInterfaces (
2245 &gEfiPxeBaseCodeProtocolGuid
,
2247 &gEfiLoadFileProtocolGuid
,
2252 if (EFI_ERROR (Status
)) {
2253 gBS
->CloseProtocol (
2255 &gEfiSimpleNetworkProtocolGuid
,
2256 This
->DriverBindingHandle
,
2265 EfiReleaseLock (&pLF
->Lock
);
2266 EfiReleaseLock (&Private
->Lock
);
2270 gBS
->FreePool (Private
->EfiBc
.Mode
);
2271 gBS
->FreePool (Private
);
2272 gBS
->FreePool (pLF
);
2278 Stop the Base code driver.
2280 @param This Protocol instance pointer.
2281 @param Controller Handle of device to test.
2282 @param NumberOfChildren Not used
2283 @param ChildHandleBuffer Not used
2285 @retval EFI_SUCCESS This driver supports this device.
2286 @retval EFI_ALREADY_STARTED This driver is already running on this device.
2287 @retval other This driver does not support this device.
2293 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
2294 IN EFI_HANDLE Controller
,
2295 IN UINTN NumberOfChildren
,
2296 IN EFI_HANDLE
*ChildHandleBuffer
2300 EFI_LOAD_FILE_PROTOCOL
*LfProtocol
;
2301 LOADFILE_DEVICE
*LoadDevice
;
2304 // Get our context back.
2306 Status
= gBS
->OpenProtocol (
2308 &gEfiLoadFileProtocolGuid
,
2309 (VOID
**) &LfProtocol
,
2310 This
->DriverBindingHandle
,
2312 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2315 if (EFI_ERROR (Status
)) {
2316 return EFI_UNSUPPORTED
;
2319 LoadDevice
= EFI_LOAD_FILE_DEV_FROM_THIS (LfProtocol
);
2321 Status
= gBS
->UninstallMultipleProtocolInterfaces (
2323 &gEfiLoadFileProtocolGuid
,
2324 &LoadDevice
->LoadFile
,
2325 &gEfiPxeBaseCodeProtocolGuid
,
2326 &LoadDevice
->Private
->EfiBc
,
2330 if (!EFI_ERROR (Status
)) {
2332 Status
= gBS
->CloseProtocol (
2334 &gEfiSimpleNetworkProtocolGuid
,
2335 This
->DriverBindingHandle
,
2339 gBS
->FreePool (LoadDevice
->Private
->EfiBc
.Mode
);
2340 gBS
->FreePool (LoadDevice
->Private
);
2341 gBS
->FreePool (LoadDevice
);
2349 Initialize the base code drivers and install the driver binding
2351 Standard EFI Image Entry
2353 @retval EFI_SUCCESS This driver was successfully bound
2358 InitializeBCDriver (
2359 IN EFI_HANDLE ImageHandle
,
2360 IN EFI_SYSTEM_TABLE
*SystemTable
2366 // Initialize EFI library
2368 Status
= EfiLibInstallDriverBindingComponentName2 (
2371 &mPxeBcDriverBinding
,
2373 &gPxeBcComponentName
,
2374 &gPxeBcComponentName2
2378 OptionsStrucInit ();