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
;
1206 // Fail if IPv6 is requested and not supported.
1209 DEBUG ((DEBUG_WARN
, "\nBcStart() IPv6 is not supported.\n"));
1210 EfiReleaseLock (&Private
->Lock
);
1211 return EFI_UNSUPPORTED
;
1215 // Setup shortcuts to SNP protocol and data structure.
1217 SnpPtr
= Private
->SimpleNetwork
;
1218 SnpModePtr
= SnpPtr
->Mode
;
1221 // Start and initialize SNP.
1223 if (SnpModePtr
->State
== EfiSimpleNetworkStopped
) {
1224 StatCode
= (*SnpPtr
->Start
) (SnpPtr
);
1226 if (SnpModePtr
->State
!= EfiSimpleNetworkStarted
) {
1227 DEBUG ((DEBUG_WARN
, "\nBcStart() Could not start SNP.\n"));
1228 EfiReleaseLock (&Private
->Lock
);
1233 // acquire memory for mode and transmit/receive buffers
1235 if (SnpModePtr
->State
== EfiSimpleNetworkStarted
) {
1236 StatCode
= (*SnpPtr
->Initialize
) (SnpPtr
, 0, 0);
1238 if (SnpModePtr
->State
!= EfiSimpleNetworkInitialized
) {
1239 DEBUG ((DEBUG_WARN
, "\nBcStart() Could not initialize SNP."));
1240 EfiReleaseLock (&Private
->Lock
);
1247 DEBUG ((DEBUG_INFO
, "\nBC Start()"));
1250 "\nSnpModePtr->State %Xh",
1255 "\nSnpModePtr->HwAddressSize %Xh",
1256 SnpModePtr
->HwAddressSize
)
1260 "\nSnpModePtr->MediaHeaderSize %Xh",
1261 SnpModePtr
->MediaHeaderSize
)
1265 "\nSnpModePtr->MaxPacketSize %Xh",
1266 SnpModePtr
->MaxPacketSize
)
1270 "\nSnpModePtr->MacAddressChangeable %Xh",
1271 SnpModePtr
->MacAddressChangeable
)
1275 "\nSnpModePtr->MultipleTxSupported %Xh",
1276 SnpModePtr
->MultipleTxSupported
)
1280 "\nSnpModePtr->CurrentAddress %Xh",
1281 *((UINTN
*)&SnpModePtr
->CurrentAddress
))
1285 "\nSnpModePtr->BroadcastAddress %Xh",
1286 *((UINTN
*)&SnpModePtr
->BroadcastAddress
))
1290 "\nSnpModePtr->PermanentAddress %Xh",
1291 *((UINTN
*)&SnpModePtr
->PermanentAddress
))
1295 "\nSnpModePtr->NvRamSize %Xh",
1296 SnpModePtr
->NvRamSize
)
1300 "\nSnpModePtr->NvRamAccessSize %Xh",
1301 SnpModePtr
->NvRamAccessSize
)
1305 "\nSnpModePtr->ReceiveFilterMask %Xh",
1306 SnpModePtr
->ReceiveFilterMask
)
1310 "\nSnpModePtr->ReceiveFilterSetting %Xh",
1311 SnpModePtr
->ReceiveFilterSetting
)
1315 "\nSnpModePtr->MCastFilterCount %Xh",
1316 SnpModePtr
->MCastFilterCount
)
1320 "\nSnpModePtr->MCastFilter %Xh",
1321 SnpModePtr
->MCastFilter
)
1325 "\nSnpModePtr->IfType %Xh",
1330 "\nSnpModePtr->MediaPresentSupported %Xh",
1331 SnpModePtr
->MediaPresentSupported
)
1335 "\nSnpModePtr->MediaPresent %Xh",
1336 SnpModePtr
->MediaPresent
)
1340 // If media check is supported and there is no media,
1341 // return error to caller.
1343 if (SnpModePtr
->MediaPresentSupported
&& !SnpModePtr
->MediaPresent
) {
1344 DEBUG ((DEBUG_WARN
, "\nBcStart() Media not present.\n"));
1345 EfiReleaseLock (&Private
->Lock
);
1346 return EFI_NO_MEDIA
;
1349 // Allocate Tx/Rx buffers
1351 Status
= gBS
->AllocatePool (
1352 EfiBootServicesData
,
1353 BUFFER_ALLOCATE_SIZE
,
1354 (VOID
**) &Private
->TransmitBufferPtr
1357 if (!EFI_ERROR (Status
)) {
1358 ZeroMem (Private
->TransmitBufferPtr
, BUFFER_ALLOCATE_SIZE
);
1360 DEBUG ((DEBUG_NET
, "\nBcStart() Could not alloc TxBuf.\n"));
1361 EfiReleaseLock (&Private
->Lock
);
1362 return EFI_OUT_OF_RESOURCES
;
1365 Status
= gBS
->AllocatePool (
1366 EfiBootServicesData
,
1367 BUFFER_ALLOCATE_SIZE
,
1368 (VOID
**) &Private
->ReceiveBufferPtr
1371 if (!EFI_ERROR (Status
)) {
1372 ZeroMem (Private
->ReceiveBufferPtr
, BUFFER_ALLOCATE_SIZE
);
1374 DEBUG ((DEBUG_NET
, "\nBcStart() Could not alloc RxBuf.\n"));
1375 gBS
->FreePool (Private
->TransmitBufferPtr
);
1376 EfiReleaseLock (&Private
->Lock
);
1377 return EFI_OUT_OF_RESOURCES
;
1380 Status
= gBS
->AllocatePool (
1381 EfiBootServicesData
,
1383 (VOID
**) &Private
->TftpErrorBuffer
1386 if (EFI_ERROR (Status
)) {
1387 gBS
->FreePool (Private
->ReceiveBufferPtr
);
1388 gBS
->FreePool (Private
->TransmitBufferPtr
);
1389 EfiReleaseLock (&Private
->Lock
);
1390 return EFI_OUT_OF_RESOURCES
;
1393 Status
= gBS
->AllocatePool (EfiBootServicesData
, 256, (VOID
**) &Private
->TftpAckBuffer
);
1395 if (EFI_ERROR (Status
)) {
1396 gBS
->FreePool (Private
->TftpErrorBuffer
);
1397 gBS
->FreePool (Private
->ReceiveBufferPtr
);
1398 gBS
->FreePool (Private
->TransmitBufferPtr
);
1399 EfiReleaseLock (&Private
->Lock
);
1400 return EFI_OUT_OF_RESOURCES
;
1403 // Initialize private BaseCode instance data
1406 Private
->RandomPort
= (UINT16
) (Private
->RandomPort
+ PXE_RND_PORT_LOW
+ Random (Private
));
1407 } while (Private
->RandomPort
< PXE_RND_PORT_LOW
);
1409 Private
->Igmpv1TimeoutEvent
= NULL
;
1410 Private
->UseIgmpv1Reporting
= TRUE
;
1411 Private
->IpLength
= IP_ADDRESS_LENGTH (Private
->EfiBc
.Mode
);
1414 // Initialize Mode structure
1416 ZeroMem (Private
->EfiBc
.Mode
, sizeof (EFI_PXE_BASE_CODE_MODE
));
1418 // check for callback protocol and set boolean
1420 SetMakeCallback (Private
);
1421 Private
->EfiBc
.Mode
->Started
= TRUE
;
1422 Private
->EfiBc
.Mode
->TTL
= DEFAULT_TTL
;
1423 Private
->EfiBc
.Mode
->ToS
= DEFAULT_ToS
;
1424 Private
->EfiBc
.Mode
->UsingIpv6
= UseIPv6
;
1427 // Set to PXE_TRUE by the BC constructor if this BC implementation
1430 Private
->EfiBc
.Mode
->Ipv6Supported
= SUPPORT_IPV6
;
1432 Private
->EfiBc
.Mode
->Ipv6Available
= FALSE
;
1434 // Set to TRUE by the BC constructor if this BC implementation
1437 Private
->EfiBc
.Mode
->BisSupported
= TRUE
;
1438 Private
->EfiBc
.Mode
->BisDetected
= PxebcBisDetect (Private
);
1441 // This field is set to PXE_TRUE by the BC Start() function. When this
1442 // field is PXE_TRUE, ARP packets are sent as needed to get IP and MAC
1443 // addresses. This can cause unexpected delays in the DHCP(), Discover()
1444 // and MTFTP() functions. Setting this to PXE_FALSE will cause these
1445 // functions to fail if the required IP/MAC information is not in the
1446 // ARP cache. The value of this field can be changed by an application
1449 Private
->EfiBc
.Mode
->AutoArp
= TRUE
;
1452 // Unlock the instance data
1454 EfiReleaseLock (&Private
->Lock
);
1460 Stop the BaseCode protocol, Simple Network protocol and UNDI.
1462 @param Private Pointer to Pxe BaseCode Protocol
1464 @retval 0 Successfully stopped
1471 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
1475 // Lock the instance data
1477 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpPtr
;
1478 EFI_SIMPLE_NETWORK_MODE
*SnpModePtr
;
1479 EFI_STATUS StatCode
;
1480 PXE_BASECODE_DEVICE
*Private
;
1482 StatCode
= EFI_SUCCESS
;
1485 DEBUG ((DEBUG_ERROR
, "BC *This pointer == NULL"));
1486 return EFI_INVALID_PARAMETER
;
1489 Private
= CR (This
, PXE_BASECODE_DEVICE
, EfiBc
, PXE_BASECODE_DEVICE_SIGNATURE
);
1491 if (Private
== NULL
) {
1492 DEBUG ((DEBUG_ERROR
, "PXE_BASECODE_DEVICE poiner == NULL"));
1493 return EFI_INVALID_PARAMETER
;
1496 EfiAcquireLock (&Private
->Lock
);
1498 SnpPtr
= Private
->SimpleNetwork
;
1499 SnpModePtr
= SnpPtr
->Mode
;
1504 StatCode
= EFI_NOT_STARTED
;
1506 if (SnpModePtr
->State
== EfiSimpleNetworkInitialized
) {
1507 StatCode
= (*SnpPtr
->Shutdown
) (SnpPtr
);
1510 if (SnpModePtr
->State
== EfiSimpleNetworkStarted
) {
1511 StatCode
= (*SnpPtr
->Stop
) (SnpPtr
);
1514 if (Private
->TransmitBufferPtr
!= NULL
) {
1515 gBS
->FreePool (Private
->TransmitBufferPtr
);
1516 Private
->TransmitBufferPtr
= NULL
;
1519 if (Private
->ReceiveBufferPtr
!= NULL
) {
1520 gBS
->FreePool (Private
->ReceiveBufferPtr
);
1521 Private
->ReceiveBufferPtr
= NULL
;
1524 if (Private
->ArpBuffer
!= NULL
) {
1525 gBS
->FreePool (Private
->ArpBuffer
);
1526 Private
->ArpBuffer
= NULL
;
1529 if (Private
->TftpErrorBuffer
!= NULL
) {
1530 gBS
->FreePool (Private
->TftpErrorBuffer
);
1531 Private
->TftpErrorBuffer
= NULL
;
1534 if (Private
->TftpAckBuffer
!= NULL
) {
1535 gBS
->FreePool (Private
->TftpAckBuffer
);
1536 Private
->TftpAckBuffer
= NULL
;
1539 if (Private
->Igmpv1TimeoutEvent
!= NULL
) {
1540 gBS
->CloseEvent (Private
->Igmpv1TimeoutEvent
);
1541 Private
->Igmpv1TimeoutEvent
= NULL
;
1544 Private
->FileSize
= 0;
1546 if (!Private
->EfiBc
.Mode
->Started
) {
1547 StatCode
= EFI_NOT_STARTED
;
1549 Private
->EfiBc
.Mode
->Started
= FALSE
;
1553 // Unlock the instance data
1555 EfiReleaseLock (&Private
->Lock
);
1559 const IPV4_ADDR AllSystemsGroup
= {{224, 0, 0, 1}};
1563 Set up the IP filter
1565 @param Private Pointer to Pxe BaseCode Protocol
1566 @param Filter Pointer to the filter
1568 @retval 0 Successfully set the filter
1574 IN PXE_BASECODE_DEVICE
*Private
,
1575 IN EFI_PXE_BASE_CODE_IP_FILTER
*Filter
1578 EFI_STATUS StatCode
;
1579 EFI_MAC_ADDRESS MACadds
[PXE_IP_FILTER_SIZE
];
1580 EFI_PXE_BASE_CODE_MODE
*PxebcMode
;
1581 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpPtr
;
1582 EFI_SIMPLE_NETWORK_MODE
*SnpModePtr
;
1588 PxebcMode
= Private
->EfiBc
.Mode
;
1589 SnpPtr
= Private
->SimpleNetwork
;
1590 SnpModePtr
= SnpPtr
->Mode
;
1593 // validate input parameters
1594 // must have a filter
1595 // must not have any extra filter bits set
1597 if (Filter
== NULL
||
1598 (Filter
->Filters
&~FILTER_BITS
)
1600 // must not have a count which is too large or with no IP list
1603 (Filter
->IpCnt
&& (!Filter
->IpList
|| Filter
->IpCnt
> PXE_IP_FILTER_SIZE
))
1605 // must not have incompatible filters - promiscuous incompatible with anything else
1609 (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) &&
1610 ((Filter
->Filters
&~EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) || Filter
->IpCnt
)
1613 DEBUG ((DEBUG_INFO
, "\nIpFilter() Exit #1"));
1614 return EFI_INVALID_PARAMETER
;
1617 // promiscuous multicast incompatible with multicast in IP list
1619 if (Filter
->IpCnt
&& (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
)) {
1620 for (Index
= 0; Index
< Filter
->IpCnt
; ++Index
) {
1621 if (IS_MULTICAST (&Filter
->IpList
[Index
])) {
1622 DEBUG ((DEBUG_INFO
, "\nIpFilter() Exit #2"));
1623 return EFI_INVALID_PARAMETER
;
1628 // leave groups for all those multicast which are no longer enabled
1630 for (Index
= 0; Index
< PxebcMode
->IpFilter
.IpCnt
; ++Index
) {
1631 if (!IS_MULTICAST (&PxebcMode
->IpFilter
.IpList
[Index
])) {
1635 for (Index2
= 0; Index2
< Filter
->IpCnt
; ++Index2
) {
1636 if (!CompareMem (&PxebcMode
->IpFilter
.IpList
[Index
], &Filter
->IpList
[Index2
], IP_ADDRESS_LENGTH (PxebcMode
))) {
1644 // if we didn't find it, remove from group
1646 if (Index2
== Filter
->IpCnt
) {
1647 IgmpLeaveGroup (Private
, &PxebcMode
->IpFilter
.IpList
[Index
]);
1651 // set enable bits, convert multicast ip adds, join groups
1652 // allways leave receive broadcast enabled at hardware layer
1656 if (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS
) {
1657 Enable
= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS
;
1659 if (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST
) {
1660 Enable
= EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST
;
1662 Enable
= EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST
;
1664 for (Index
= 0; Index
< Filter
->IpCnt
; ++Index
) {
1665 CopyMem (&PxebcMode
->IpFilter
.IpList
[Index
], &Filter
->IpList
[Index
], sizeof (EFI_IP_ADDRESS
));
1667 if (IS_MULTICAST (&Filter
->IpList
[Index
])) {
1668 EFI_IP_ADDRESS
*TmpIp
;
1670 Enable
|= EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
;
1673 // if this is the first group, add the all systems group to mcast list
1677 TmpIp
= (EFI_IP_ADDRESS
*) &AllSystemsGroup
;
1680 TmpIp
= (EFI_IP_ADDRESS
*) &Filter
->IpList
[Index
];
1683 // get MAC address of IP
1685 StatCode
= (*SnpPtr
->MCastIpToMac
) (SnpPtr
, PxebcMode
->UsingIpv6
, TmpIp
, &MACadds
[Index2
++]);
1687 if (EFI_ERROR (StatCode
)) {
1690 "\nIpFilter() Exit #2 %Xh (%r)",
1697 Enable
|= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
;
1702 if (Filter
->Filters
& EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP
) {
1703 Enable
|= EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
;
1707 // if nothing changed, just return
1711 "\nsnp->ReceiveFilterSetting == %Xh Filter->IpCnt == %Xh",
1712 SnpModePtr
->ReceiveFilterSetting
,
1716 if (SnpModePtr
->ReceiveFilterSetting
== Enable
&& !Filter
->IpCnt
) {
1717 DEBUG ((DEBUG_INFO
, "\nIpFilter() Exit #4"));
1721 // disable those currently set but not set in new filter
1723 Disable
= SnpModePtr
->ReceiveFilterSetting
&~Enable
;
1725 StatCode
= SnpPtr
->ReceiveFilters (SnpPtr
, Enable
, Disable
, FALSE
, Index2
, MACadds
);
1727 PxebcMode
->IpFilter
.IpCnt
= Filter
->IpCnt
;
1730 // join groups for all multicast in list
1732 for (Index
= 0; Index
< Filter
->IpCnt
; ++Index
) {
1733 if (IS_MULTICAST (&Filter
->IpList
[Index
])) {
1734 IgmpJoinGroup (Private
, &Filter
->IpList
[Index
]);
1738 DEBUG ((DEBUG_INFO
, "\nIpFilter() Exit #5 %Xh (%r)", StatCode
, StatCode
));
1747 @param Private Pointer to Pxe BaseCode Protocol
1748 @param Filter Pointer to the filter
1750 @retval 0 Successfully set the filter
1757 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1758 IN EFI_PXE_BASE_CODE_IP_FILTER
*Filter
1761 EFI_STATUS StatCode
;
1762 PXE_BASECODE_DEVICE
*Private
;
1765 // Lock the instance data and make sure started
1767 StatCode
= EFI_SUCCESS
;
1770 DEBUG ((DEBUG_ERROR
, "BC *This pointer == NULL"));
1771 return EFI_INVALID_PARAMETER
;
1774 Private
= CR (This
, PXE_BASECODE_DEVICE
, EfiBc
, PXE_BASECODE_DEVICE_SIGNATURE
);
1776 if (Private
== NULL
) {
1777 DEBUG ((DEBUG_ERROR
, "PXE_BASECODE_DEVICE poiner == NULL"));
1778 return EFI_INVALID_PARAMETER
;
1781 for (Index
= 0; Index
< Filter
->IpCnt
; ++Index
) {
1782 if ((Filter
->IpList
[Index
].Addr
[0]) == BROADCAST_IPv4
) {
1784 // The IP is a broadcast address.
1786 return EFI_INVALID_PARAMETER
;
1790 EfiAcquireLock (&Private
->Lock
);
1792 if (This
->Mode
== NULL
|| !This
->Mode
->Started
) {
1793 DEBUG ((DEBUG_ERROR
, "BC was not started."));
1794 EfiReleaseLock (&Private
->Lock
);
1795 return EFI_NOT_STARTED
;
1798 if (Filter
== NULL
) {
1799 return EFI_INVALID_PARAMETER
;
1804 StatCode
= IpFilter (Private
, Filter
);
1807 // Unlock the instance data
1809 EfiReleaseLock (&Private
->Lock
);
1815 Set the Base Code behavior parameters
1817 @param This Pointer to Pxe BaseCode Protocol
1818 @param AutoArpPtr Boolean to do ARP stuff
1819 @param SendGuidPtr Boolean whether or not to send GUID info
1820 @param TimeToLivePtr Value for Total time to live
1821 @param TypeOfServicePtr Value for Type of Service
1822 @param MakeCallbackPtr Boolean to determine if we make callbacks
1824 @retval 0 Successfully set the parameters
1831 EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1832 BOOLEAN
*AutoArpPtr
,
1833 BOOLEAN
*SendGuidPtr
,
1834 UINT8
*TimeToLivePtr
,
1835 UINT8
*TypeOfServicePtr
,
1836 BOOLEAN
*MakeCallbackPtr
1839 EFI_PXE_BASE_CODE_MODE
*PxebcMode
;
1841 UINT8
*SerialNumberPtr
;
1842 EFI_STATUS StatCode
;
1843 PXE_BASECODE_DEVICE
*Private
;
1846 // Lock the instance data and make sure started
1848 StatCode
= EFI_SUCCESS
;
1851 DEBUG ((DEBUG_ERROR
, "BC *This pointer == NULL"));
1852 return EFI_INVALID_PARAMETER
;
1855 Private
= CR (This
, PXE_BASECODE_DEVICE
, EfiBc
, PXE_BASECODE_DEVICE_SIGNATURE
);
1857 if (Private
== NULL
) {
1858 DEBUG ((DEBUG_ERROR
, "PXE_BASECODE_DEVICE poiner == NULL"));
1859 return EFI_INVALID_PARAMETER
;
1862 EfiAcquireLock (&Private
->Lock
);
1864 if (This
->Mode
== NULL
|| !This
->Mode
->Started
) {
1865 DEBUG ((DEBUG_ERROR
, "BC was not started."));
1866 EfiReleaseLock (&Private
->Lock
);
1867 return EFI_NOT_STARTED
;
1870 DEBUG ((DEBUG_INFO
, "\nSetParameters() Entry. "));
1872 PxebcMode
= Private
->EfiBc
.Mode
;
1873 StatCode
= EFI_SUCCESS
;
1875 if (SendGuidPtr
!= NULL
) {
1877 if (PxeBcLibGetSmbiosSystemGuidAndSerialNumber (&TmpGuid
, (CHAR8
**) &SerialNumberPtr
) != EFI_SUCCESS
) {
1878 return EFI_INVALID_PARAMETER
;
1883 if (MakeCallbackPtr
!= NULL
) {
1884 if (*MakeCallbackPtr
) {
1885 if (!SetMakeCallback (Private
)) {
1886 return EFI_INVALID_PARAMETER
;
1890 PxebcMode
->MakeCallbacks
= *MakeCallbackPtr
;
1893 if (AutoArpPtr
!= NULL
) {
1894 PxebcMode
->AutoArp
= *AutoArpPtr
;
1897 if (SendGuidPtr
!= NULL
) {
1898 PxebcMode
->SendGUID
= *SendGuidPtr
;
1901 if (TimeToLivePtr
!= NULL
) {
1902 PxebcMode
->TTL
= *TimeToLivePtr
;
1905 if (TypeOfServicePtr
!= NULL
) {
1906 PxebcMode
->ToS
= *TypeOfServicePtr
;
1909 // Unlock the instance data
1911 DEBUG ((DEBUG_INFO
, "\nSetparameters() Exit = %xh ", StatCode
));
1913 EfiReleaseLock (&Private
->Lock
);
1917 // //////////////////////////////////////////////////////////
1919 // BC Set Station IP Routine
1923 Set the station IP address
1925 @param This Pointer to Pxe BaseCode Protocol
1926 @param StationIpPtr Pointer to the requested IP address to set in base
1928 @param SubnetMaskPtr Pointer to the requested subnet mask for the base
1931 @retval EFI_SUCCESS Successfully set the parameters
1932 @retval EFI_NOT_STARTED BC has not started
1938 IN EFI_PXE_BASE_CODE_PROTOCOL
*This
,
1939 IN EFI_IP_ADDRESS
*StationIpPtr
,
1940 IN EFI_IP_ADDRESS
*SubnetMaskPtr
1943 EFI_PXE_BASE_CODE_MODE
*PxebcMode
;
1944 EFI_STATUS StatCode
;
1945 PXE_BASECODE_DEVICE
*Private
;
1949 // Lock the instance data and make sure started
1951 StatCode
= EFI_SUCCESS
;
1954 DEBUG ((DEBUG_ERROR
, "BC *This pointer == NULL"));
1955 return EFI_INVALID_PARAMETER
;
1958 Private
= CR (This
, PXE_BASECODE_DEVICE
, EfiBc
, PXE_BASECODE_DEVICE_SIGNATURE
);
1960 if (Private
== NULL
) {
1961 DEBUG ((DEBUG_ERROR
, "PXE_BASECODE_DEVICE poiner == NULL"));
1962 return EFI_INVALID_PARAMETER
;
1965 EfiAcquireLock (&Private
->Lock
);
1967 if (This
->Mode
== NULL
|| !This
->Mode
->Started
) {
1968 DEBUG ((DEBUG_ERROR
, "BC was not started."));
1969 StatCode
= EFI_NOT_STARTED
;
1973 PxebcMode
= Private
->EfiBc
.Mode
;
1975 if (!Private
->GoodStationIp
&& ((StationIpPtr
== NULL
) || (SubnetMaskPtr
== NULL
))) {
1977 // It's not allowed to only set one of the two addresses while there isn't a previous
1978 // GOOD address configuration.
1980 StatCode
= EFI_INVALID_PARAMETER
;
1984 if (SubnetMaskPtr
!= NULL
) {
1985 SubnetMask
= SubnetMaskPtr
->Addr
[0];
1987 if (SubnetMask
& (SubnetMask
+ 1)) {
1989 // the subnet mask is valid if it's with leading continuous 1 bits.
1991 StatCode
= EFI_INVALID_PARAMETER
;
1995 SubnetMaskPtr
= &PxebcMode
->SubnetMask
;
1996 SubnetMask
= SubnetMaskPtr
->Addr
[0];
1999 if (StationIpPtr
== NULL
) {
2000 StationIpPtr
= &PxebcMode
->StationIp
;
2003 if (!IS_INADDR_UNICAST (StationIpPtr
) ||
2004 ((StationIpPtr
->Addr
[0] | SubnetMask
) == BROADCAST_IPv4
)) {
2006 // The station IP is not a unicast address.
2008 StatCode
= EFI_INVALID_PARAMETER
;
2012 CopyMem (&PxebcMode
->StationIp
, StationIpPtr
, sizeof (EFI_IP_ADDRESS
));
2013 CopyMem (&PxebcMode
->SubnetMask
, SubnetMaskPtr
, sizeof (EFI_IP_ADDRESS
));
2014 Private
->GoodStationIp
= TRUE
;
2018 // Unlock the instance data
2020 EfiReleaseLock (&Private
->Lock
);
2025 EFI_DRIVER_BINDING_PROTOCOL mPxeBcDriverBinding
= {
2026 PxeBcDriverSupported
,
2036 Test to see if this driver supports Controller. Any Controller
2037 than contains a Snp protocol can be supported.
2039 @param This Protocol instance pointer.
2040 @param Controller Handle of device to test.
2041 @param RemainingDevicePath Not used.
2043 @retval EFI_SUCCESS This driver supports this device.
2044 @retval EFI_ALREADY_STARTED This driver is already running on this device.
2045 @retval other This driver does not support this device.
2050 PxeBcDriverSupported (
2051 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
2052 IN EFI_HANDLE Controller
,
2053 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
2057 EFI_SIMPLE_NETWORK_PROTOCOL
*SnpPtr
;
2059 Status
= gBS
->OpenProtocol (
2061 &gEfiDevicePathProtocolGuid
,
2063 This
->DriverBindingHandle
,
2065 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
2068 if (EFI_ERROR (Status
)) {
2072 Status
= gBS
->OpenProtocol (
2074 &gEfiSimpleNetworkProtocolGuid
,
2076 This
->DriverBindingHandle
,
2078 EFI_OPEN_PROTOCOL_BY_DRIVER
2080 if (EFI_ERROR (Status
)) {
2084 gBS
->CloseProtocol (
2086 &gEfiSimpleNetworkProtocolGuid
,
2087 This
->DriverBindingHandle
,
2096 Start the Base code driver.
2098 @param This Protocol instance pointer.
2099 @param Controller Handle of device to test.
2100 @param RemainingDevicePath Not used.
2102 @retval EFI_SUCCESS This driver supports this device.
2103 @retval EFI_ALREADY_STARTED This driver is already running on this device.
2104 @retval other This driver does not support this device.
2110 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
2111 IN EFI_HANDLE Controller
,
2112 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
2116 PXE_BASECODE_DEVICE
*Private
;
2117 LOADFILE_DEVICE
*pLF
;
2120 // Allocate structures needed by BaseCode and LoadFile protocols.
2122 Private
= AllocateZeroPool (sizeof (PXE_BASECODE_DEVICE
));
2124 if (Private
== NULL
) {
2125 DEBUG ((EFI_D_NET
, "\nBcNotifySnp() Could not alloc PXE_BASECODE_DEVICE structure.\n"));
2126 return EFI_OUT_OF_RESOURCES
;
2129 pLF
= AllocateZeroPool (sizeof (LOADFILE_DEVICE
));
2131 DEBUG ((EFI_D_NET
, "\nBcNotifySnp() Could not alloc LOADFILE_DEVICE structure.\n"));
2133 return EFI_OUT_OF_RESOURCES
;
2136 Private
->EfiBc
.Mode
= AllocateZeroPool (sizeof (EFI_PXE_BASE_CODE_MODE
));
2137 if (Private
->EfiBc
.Mode
== NULL
) {
2138 DEBUG ((EFI_D_NET
, "\nBcNotifySnp() Could not alloc Mode structure.\n"));
2141 return EFI_OUT_OF_RESOURCES
;
2144 // Lock access, just in case
2146 EfiInitializeLock (&Private
->Lock
, TPL_CALLBACK
);
2147 EfiAcquireLock (&Private
->Lock
);
2149 EfiInitializeLock (&pLF
->Lock
, TPL_CALLBACK
);
2150 EfiAcquireLock (&pLF
->Lock
);
2153 // Initialize PXE structure
2156 // First initialize the internal 'private' data that the application
2159 Private
->Signature
= PXE_BASECODE_DEVICE_SIGNATURE
;
2160 Private
->Handle
= Controller
;
2163 // Get the NII interface
2165 Status
= gBS
->OpenProtocol (
2167 &gEfiNetworkInterfaceIdentifierProtocolGuid_31
,
2168 (VOID
**) &Private
->NiiPtr
,
2169 This
->DriverBindingHandle
,
2171 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2174 if (EFI_ERROR (Status
)) {
2179 // Get the Snp interface
2181 Status
= gBS
->OpenProtocol (
2183 &gEfiSimpleNetworkProtocolGuid
,
2184 (VOID
**) &Private
->SimpleNetwork
,
2185 This
->DriverBindingHandle
,
2187 EFI_OPEN_PROTOCOL_BY_DRIVER
2190 if (EFI_ERROR (Status
)) {
2195 // Next, initialize the external 'public' data that
2196 // the application does see.
2198 Private
->EfiBc
.Revision
= EFI_PXE_BASE_CODE_PROTOCOL_REVISION
;
2199 Private
->EfiBc
.Start
= BcStart
;
2200 Private
->EfiBc
.Stop
= BcStop
;
2201 Private
->EfiBc
.Dhcp
= BcDhcp
;
2202 Private
->EfiBc
.Discover
= BcDiscover
;
2203 Private
->EfiBc
.Mtftp
= BcMtftp
;
2204 Private
->EfiBc
.UdpWrite
= BcUdpWrite
;
2205 Private
->EfiBc
.UdpRead
= BcUdpRead
;
2206 Private
->EfiBc
.Arp
= BcArp
;
2207 Private
->EfiBc
.SetIpFilter
= BcIpFilter
;
2208 Private
->EfiBc
.SetParameters
= BcSetParameters
;
2209 Private
->EfiBc
.SetStationIp
= BcSetStationIP
;
2210 Private
->EfiBc
.SetPackets
= BcSetPackets
;
2213 // Initialize BaseCode Mode structure
2215 Private
->EfiBc
.Mode
->Started
= FALSE
;
2216 Private
->EfiBc
.Mode
->TTL
= DEFAULT_TTL
;
2217 Private
->EfiBc
.Mode
->ToS
= DEFAULT_ToS
;
2218 Private
->EfiBc
.Mode
->UsingIpv6
= FALSE
;
2219 Private
->EfiBc
.Mode
->AutoArp
= TRUE
;
2222 // Set to PXE_TRUE by the BC constructor if this BC
2223 // implementation supports IPv6.
2225 Private
->EfiBc
.Mode
->Ipv6Supported
= SUPPORT_IPV6
;
2228 Private
->EfiBc
.Mode
->Ipv6Available
= Private
->NiiPtr
->Ipv6Supported
;
2230 Private
->EfiBc
.Mode
->Ipv6Available
= FALSE
;
2233 // Set to TRUE by the BC constructor if this BC
2234 // implementation supports BIS.
2236 Private
->EfiBc
.Mode
->BisSupported
= TRUE
;
2237 Private
->EfiBc
.Mode
->BisDetected
= PxebcBisDetect (Private
);
2240 // Initialize LoadFile structure.
2242 pLF
->Signature
= LOADFILE_DEVICE_SIGNATURE
;
2243 pLF
->LoadFile
.LoadFile
= LoadFile
;
2244 pLF
->Private
= Private
;
2247 // Install protocol interfaces.
2249 Status
= gBS
->InstallMultipleProtocolInterfaces (
2251 &gEfiPxeBaseCodeProtocolGuid
,
2253 &gEfiLoadFileProtocolGuid
,
2258 if (EFI_ERROR (Status
)) {
2259 gBS
->CloseProtocol (
2261 &gEfiSimpleNetworkProtocolGuid
,
2262 This
->DriverBindingHandle
,
2271 EfiReleaseLock (&pLF
->Lock
);
2272 EfiReleaseLock (&Private
->Lock
);
2276 gBS
->FreePool (Private
->EfiBc
.Mode
);
2277 gBS
->FreePool (Private
);
2278 gBS
->FreePool (pLF
);
2284 Stop the Base code driver.
2286 @param This Protocol instance pointer.
2287 @param Controller Handle of device to test.
2288 @param NumberOfChildren Not used
2289 @param ChildHandleBuffer Not used
2291 @retval EFI_SUCCESS This driver supports this device.
2292 @retval EFI_ALREADY_STARTED This driver is already running on this device.
2293 @retval other This driver does not support this device.
2299 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
2300 IN EFI_HANDLE Controller
,
2301 IN UINTN NumberOfChildren
,
2302 IN EFI_HANDLE
*ChildHandleBuffer
2306 EFI_LOAD_FILE_PROTOCOL
*LfProtocol
;
2307 LOADFILE_DEVICE
*LoadDevice
;
2310 // Get our context back.
2312 Status
= gBS
->OpenProtocol (
2314 &gEfiLoadFileProtocolGuid
,
2315 (VOID
**) &LfProtocol
,
2316 This
->DriverBindingHandle
,
2318 EFI_OPEN_PROTOCOL_GET_PROTOCOL
2321 if (EFI_ERROR (Status
)) {
2322 return EFI_UNSUPPORTED
;
2325 LoadDevice
= EFI_LOAD_FILE_DEV_FROM_THIS (LfProtocol
);
2327 Status
= gBS
->UninstallMultipleProtocolInterfaces (
2329 &gEfiLoadFileProtocolGuid
,
2330 &LoadDevice
->LoadFile
,
2331 &gEfiPxeBaseCodeProtocolGuid
,
2332 &LoadDevice
->Private
->EfiBc
,
2336 if (!EFI_ERROR (Status
)) {
2338 Status
= gBS
->CloseProtocol (
2340 &gEfiSimpleNetworkProtocolGuid
,
2341 This
->DriverBindingHandle
,
2345 gBS
->FreePool (LoadDevice
->Private
->EfiBc
.Mode
);
2346 gBS
->FreePool (LoadDevice
->Private
);
2347 gBS
->FreePool (LoadDevice
);
2355 Initialize the base code drivers and install the driver binding
2357 Standard EFI Image Entry
2359 @retval EFI_SUCCESS This driver was successfully bound
2364 InitializeBCDriver (
2365 IN EFI_HANDLE ImageHandle
,
2366 IN EFI_SYSTEM_TABLE
*SystemTable
2372 // Initialize EFI library
2374 Status
= EfiLibInstallDriverBindingComponentName2 (
2377 &mPxeBcDriverBinding
,
2379 &gPxeBcComponentName
,
2380 &gPxeBcComponentName2
2384 OptionsStrucInit ();