2 HDD password driver which is used to support HDD security feature.
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "HddPasswordDxe.h"
12 EFI_GUID mHddPasswordVendorGuid
= HDD_PASSWORD_CONFIG_GUID
;
13 CHAR16 mHddPasswordVendorStorageName
[] = L
"HDD_PASSWORD_CONFIG";
14 LIST_ENTRY mHddPasswordConfigFormList
;
15 UINT32 mNumberOfHddDevices
= 0;
17 EFI_GUID mHddPasswordDeviceInfoGuid
= HDD_PASSWORD_DEVICE_INFO_GUID
;
18 BOOLEAN mHddPasswordEndOfDxe
= FALSE
;
19 HDD_PASSWORD_REQUEST_VARIABLE
*mHddPasswordRequestVariable
= NULL
;
20 UINTN mHddPasswordRequestVariableSize
= 0;
22 HII_VENDOR_DEVICE_PATH mHddPasswordHiiVendorDevicePath
= {
28 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
29 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
32 HDD_PASSWORD_CONFIG_GUID
36 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
38 (UINT8
) (END_DEVICE_PATH_LENGTH
),
39 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
46 Check if the password is full zero.
48 @param[in] Password Points to the data buffer
50 @retval TRUE This password string is full zero.
51 @retval FALSE This password string is not full zero.
61 for (Index
= 0; Index
< HDD_PASSWORD_MAX_LENGTH
; Index
++) {
62 if (Password
[Index
] != 0) {
73 @param[in] ConfigFormEntry Points to HDD_PASSWORD_CONFIG_FORM_ENTRY buffer
74 @param[in,out] TempDevInfo Points to HDD_PASSWORD_DEVICE_INFO buffer
79 IN HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
,
80 IN OUT HDD_PASSWORD_DEVICE_INFO
*TempDevInfo
83 TempDevInfo
->Device
.Bus
= (UINT8
) ConfigFormEntry
->Bus
;
84 TempDevInfo
->Device
.Device
= (UINT8
) ConfigFormEntry
->Device
;
85 TempDevInfo
->Device
.Function
= (UINT8
) ConfigFormEntry
->Function
;
86 TempDevInfo
->Device
.Port
= ConfigFormEntry
->Port
;
87 TempDevInfo
->Device
.PortMultiplierPort
= ConfigFormEntry
->PortMultiplierPort
;
88 CopyMem (TempDevInfo
->Password
, ConfigFormEntry
->Password
, HDD_PASSWORD_MAX_LENGTH
);
89 TempDevInfo
->DevicePathLength
= (UINT32
) GetDevicePathSize (ConfigFormEntry
->DevicePath
);
90 CopyMem (TempDevInfo
->DevicePath
, ConfigFormEntry
->DevicePath
, TempDevInfo
->DevicePathLength
);
94 Build HDD password device info and save them to LockBox.
98 BuildHddPasswordDeviceInfo (
104 HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
105 HDD_PASSWORD_DEVICE_INFO
*DevInfo
;
106 HDD_PASSWORD_DEVICE_INFO
*TempDevInfo
;
109 BOOLEAN S3InitDevicesExist
;
110 UINTN S3InitDevicesLength
;
111 EFI_DEVICE_PATH_PROTOCOL
*S3InitDevices
;
112 EFI_DEVICE_PATH_PROTOCOL
*S3InitDevicesBak
;
115 // Build HDD password device info and save them to LockBox.
118 EFI_LIST_FOR_EACH (Entry
, &mHddPasswordConfigFormList
) {
119 ConfigFormEntry
= BASE_CR (Entry
, HDD_PASSWORD_CONFIG_FORM_ENTRY
, Link
);
122 // 1. Handle device which already set password.
123 // 2. When request to send freeze comamnd, driver also needs to handle device
124 // which support security feature.
126 if ((!PasswordIsFullZero (ConfigFormEntry
->Password
)) ||
127 ((ConfigFormEntry
->IfrData
.SecurityStatus
.Supported
!= 0) &&
128 (ConfigFormEntry
->IfrData
.SecurityStatus
.Enabled
== 0))) {
129 DevInfoLength
+= sizeof (HDD_PASSWORD_DEVICE_INFO
) +
130 GetDevicePathSize (ConfigFormEntry
->DevicePath
);
134 if (DevInfoLength
== 0) {
138 S3InitDevicesLength
= sizeof (DummyData
);
139 Status
= RestoreLockBox (
140 &gS3StorageDeviceInitListGuid
,
144 ASSERT ((Status
== EFI_NOT_FOUND
) || (Status
== EFI_BUFFER_TOO_SMALL
));
145 if (Status
== EFI_NOT_FOUND
) {
146 S3InitDevices
= NULL
;
147 S3InitDevicesExist
= FALSE
;
148 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
149 S3InitDevices
= AllocatePool (S3InitDevicesLength
);
150 ASSERT (S3InitDevices
!= NULL
);
152 Status
= RestoreLockBox (
153 &gS3StorageDeviceInitListGuid
,
157 ASSERT_EFI_ERROR (Status
);
158 S3InitDevicesExist
= TRUE
;
163 DevInfo
= AllocateZeroPool (DevInfoLength
);
164 ASSERT (DevInfo
!= NULL
);
166 TempDevInfo
= DevInfo
;
167 EFI_LIST_FOR_EACH (Entry
, &mHddPasswordConfigFormList
) {
168 ConfigFormEntry
= BASE_CR (Entry
, HDD_PASSWORD_CONFIG_FORM_ENTRY
, Link
);
170 if ((!PasswordIsFullZero (ConfigFormEntry
->Password
)) ||
171 ((ConfigFormEntry
->IfrData
.SecurityStatus
.Supported
!= 0) &&
172 (ConfigFormEntry
->IfrData
.SecurityStatus
.Enabled
== 0))) {
173 SaveDeviceInfo (ConfigFormEntry
, TempDevInfo
);
175 S3InitDevicesBak
= S3InitDevices
;
176 S3InitDevices
= AppendDevicePathInstance (
178 ConfigFormEntry
->DevicePath
180 if (S3InitDevicesBak
!= NULL
) {
181 FreePool (S3InitDevicesBak
);
183 ASSERT (S3InitDevices
!= NULL
);
185 TempDevInfo
= (HDD_PASSWORD_DEVICE_INFO
*) ((UINTN
)TempDevInfo
+
186 sizeof (HDD_PASSWORD_DEVICE_INFO
) +
187 TempDevInfo
->DevicePathLength
);
191 Status
= SaveLockBox (
192 &mHddPasswordDeviceInfoGuid
,
196 ASSERT_EFI_ERROR (Status
);
198 Status
= SetLockBoxAttributes (
199 &mHddPasswordDeviceInfoGuid
,
200 LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY
202 ASSERT_EFI_ERROR (Status
);
204 S3InitDevicesLength
= GetDevicePathSize (S3InitDevices
);
205 if (S3InitDevicesExist
) {
206 Status
= UpdateLockBox (
207 &gS3StorageDeviceInitListGuid
,
212 ASSERT_EFI_ERROR (Status
);
214 Status
= SaveLockBox (
215 &gS3StorageDeviceInitListGuid
,
219 ASSERT_EFI_ERROR (Status
);
221 Status
= SetLockBoxAttributes (
222 &gS3StorageDeviceInitListGuid
,
223 LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY
225 ASSERT_EFI_ERROR (Status
);
228 ZeroMem (DevInfo
, DevInfoLength
);
230 FreePool (S3InitDevices
);
234 Send freeze lock cmd through Ata Pass Thru Protocol.
236 @param[in] AtaPassThru The pointer to the ATA_PASS_THRU protocol.
237 @param[in] Port The port number of the ATA device to send the command.
238 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
239 If there is no port multiplier, then specify 0xFFFF.
241 @retval EFI_SUCCESS Successful to send freeze lock cmd.
242 @retval EFI_INVALID_PARAMETER The parameter passed-in is invalid.
243 @retval EFI_OUT_OF_RESOURCES Not enough memory to send freeze lock cmd.
244 @retval EFI_DEVICE_ERROR Can not send freeze lock cmd.
249 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
251 IN UINT16 PortMultiplierPort
255 EFI_ATA_COMMAND_BLOCK Acb
;
256 EFI_ATA_STATUS_BLOCK
*Asb
;
257 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet
;
259 if (AtaPassThru
== NULL
) {
260 return EFI_INVALID_PARAMETER
;
264 // The 'Asb' field (a pointer to the EFI_ATA_STATUS_BLOCK structure) in
265 // EFI_ATA_PASS_THRU_COMMAND_PACKET is required to be aligned specified by
266 // the 'IoAlign' field in the EFI_ATA_PASS_THRU_MODE structure. Meanwhile,
267 // the structure EFI_ATA_STATUS_BLOCK is composed of only UINT8 fields, so it
268 // may not be aligned when allocated on stack for some compilers. Hence, we
269 // use the API AllocateAlignedPages to ensure this structure is properly
272 Asb
= AllocateAlignedPages (
273 EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)),
274 AtaPassThru
->Mode
->IoAlign
277 return EFI_OUT_OF_RESOURCES
;
281 // Prepare for ATA command block.
283 ZeroMem (&Acb
, sizeof (Acb
));
284 ZeroMem (Asb
, sizeof (EFI_ATA_STATUS_BLOCK
));
285 Acb
.AtaCommand
= ATA_SECURITY_FREEZE_LOCK_CMD
;
286 Acb
.AtaDeviceHead
= (UINT8
) (PortMultiplierPort
== 0xFFFF ? 0 : (PortMultiplierPort
<< 4));
289 // Prepare for ATA pass through packet.
291 ZeroMem (&Packet
, sizeof (Packet
));
292 Packet
.Protocol
= EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA
;
293 Packet
.Length
= EFI_ATA_PASS_THRU_LENGTH_NO_DATA_TRANSFER
;
296 Packet
.Timeout
= ATA_TIMEOUT
;
298 Status
= AtaPassThru
->PassThru (
305 if (!EFI_ERROR (Status
) &&
306 ((Asb
->AtaStatus
& ATA_STSREG_ERR
) != 0) &&
307 ((Asb
->AtaError
& ATA_ERRREG_ABRT
) != 0)) {
308 Status
= EFI_DEVICE_ERROR
;
311 FreeAlignedPages (Asb
, EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)));
313 DEBUG ((DEBUG_INFO
, "%a() - %r\n", __FUNCTION__
, Status
));
318 Get attached harddisk identify data through Ata Pass Thru Protocol.
320 @param[in] AtaPassThru The pointer to the ATA_PASS_THRU protocol.
321 @param[in] Port The port number of the ATA device to send the command.
322 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
323 If there is no port multiplier, then specify 0xFFFF.
324 @param[in] IdentifyData The buffer to store identify data.
326 @retval EFI_SUCCESS Successful to get identify data.
327 @retval EFI_INVALID_PARAMETER The parameter passed-in is invalid.
328 @retval EFI_OUT_OF_RESOURCES Not enough memory to get identify data.
329 @retval EFI_DEVICE_ERROR Can not get identify data.
333 GetHddDeviceIdentifyData (
334 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
336 IN UINT16 PortMultiplierPort
,
337 IN ATA_IDENTIFY_DATA
*IdentifyData
341 EFI_ATA_COMMAND_BLOCK Acb
;
342 EFI_ATA_STATUS_BLOCK
*Asb
;
343 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet
;
345 if ((AtaPassThru
== NULL
) || (IdentifyData
== NULL
)) {
346 return EFI_INVALID_PARAMETER
;
350 // The 'Asb' field (a pointer to the EFI_ATA_STATUS_BLOCK structure) in
351 // EFI_ATA_PASS_THRU_COMMAND_PACKET is required to be aligned specified by
352 // the 'IoAlign' field in the EFI_ATA_PASS_THRU_MODE structure. Meanwhile,
353 // the structure EFI_ATA_STATUS_BLOCK is composed of only UINT8 fields, so it
354 // may not be aligned when allocated on stack for some compilers. Hence, we
355 // use the API AllocateAlignedPages to ensure this structure is properly
358 Asb
= AllocateAlignedPages (
359 EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)),
360 AtaPassThru
->Mode
->IoAlign
363 return EFI_OUT_OF_RESOURCES
;
367 // Prepare for ATA command block.
369 ZeroMem (&Acb
, sizeof (Acb
));
370 ZeroMem (Asb
, sizeof (EFI_ATA_STATUS_BLOCK
));
371 Acb
.AtaCommand
= ATA_CMD_IDENTIFY_DRIVE
;
372 Acb
.AtaDeviceHead
= (UINT8
) (BIT7
| BIT6
| BIT5
| (PortMultiplierPort
== 0xFFFF ? 0 : (PortMultiplierPort
<< 4)));
375 // Prepare for ATA pass through packet.
377 ZeroMem (&Packet
, sizeof (Packet
));
378 Packet
.Protocol
= EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN
;
379 Packet
.Length
= EFI_ATA_PASS_THRU_LENGTH_BYTES
| EFI_ATA_PASS_THRU_LENGTH_SECTOR_COUNT
;
382 Packet
.InDataBuffer
= IdentifyData
;
383 Packet
.InTransferLength
= sizeof (ATA_IDENTIFY_DATA
);
384 Packet
.Timeout
= ATA_TIMEOUT
;
386 Status
= AtaPassThru
->PassThru (
394 FreeAlignedPages (Asb
, EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)));
400 Parse security status according to identify data.
402 @param[in] IdentifyData The buffer to store identify data.
403 @param[in, out] IfrData IFR data to hold security status.
407 GetHddPasswordSecurityStatus (
408 IN ATA_IDENTIFY_DATA
*IdentifyData
,
409 IN OUT HDD_PASSWORD_CONFIG
*IfrData
412 IfrData
->SecurityStatus
.Supported
= (IdentifyData
->command_set_supported_82
& BIT1
) ? 1 : 0;
413 IfrData
->SecurityStatus
.Enabled
= (IdentifyData
->security_status
& BIT1
) ? 1 : 0;
414 IfrData
->SecurityStatus
.Locked
= (IdentifyData
->security_status
& BIT2
) ? 1 : 0;
415 IfrData
->SecurityStatus
.Frozen
= (IdentifyData
->security_status
& BIT3
) ? 1 : 0;
416 IfrData
->SecurityStatus
.UserPasswordStatus
= IfrData
->SecurityStatus
.Enabled
;
417 IfrData
->SecurityStatus
.MasterPasswordStatus
= IfrData
->SecurityStatus
.Supported
;
419 DEBUG ((DEBUG_INFO
, "IfrData->SecurityStatus.Supported = %x\n", IfrData
->SecurityStatus
.Supported
));
420 DEBUG ((DEBUG_INFO
, "IfrData->SecurityStatus.Enabled = %x\n", IfrData
->SecurityStatus
.Enabled
));
421 DEBUG ((DEBUG_INFO
, "IfrData->SecurityStatus.Locked = %x\n", IfrData
->SecurityStatus
.Locked
));
422 DEBUG ((DEBUG_INFO
, "IfrData->SecurityStatus.Frozen = %x\n", IfrData
->SecurityStatus
.Frozen
));
423 DEBUG ((DEBUG_INFO
, "IfrData->SecurityStatus.UserPasswordStatus = %x\n", IfrData
->SecurityStatus
.UserPasswordStatus
));
424 DEBUG ((DEBUG_INFO
, "IfrData->SecurityStatus.MasterPasswordStatus = %x\n", IfrData
->SecurityStatus
.MasterPasswordStatus
));
428 Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
430 This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.
432 @param Event Event whose notification function is being invoked.
433 @param Context Pointer to the notification function's context.
438 HddPasswordEndOfDxeEventNotify (
444 HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
446 ATA_IDENTIFY_DATA IdentifyData
;
448 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
450 mHddPasswordEndOfDxe
= TRUE
;
452 if (mHddPasswordRequestVariable
!= NULL
) {
454 // Free the HDD password request variable buffer here
455 // as the HDD password requests should have been processed.
457 FreePool (mHddPasswordRequestVariable
);
458 mHddPasswordRequestVariable
= NULL
;
459 mHddPasswordRequestVariableSize
= 0;
463 // If no any device, return directly.
465 if (IsListEmpty (&mHddPasswordConfigFormList
)) {
466 gBS
->CloseEvent (Event
);
470 BuildHddPasswordDeviceInfo ();
473 // Zero passsword and freeze lock device.
475 EFI_LIST_FOR_EACH (Entry
, &mHddPasswordConfigFormList
) {
476 ConfigFormEntry
= BASE_CR (Entry
, HDD_PASSWORD_CONFIG_FORM_ENTRY
, Link
);
478 ZeroMem (ConfigFormEntry
->Password
, HDD_PASSWORD_MAX_LENGTH
);
481 // Check whether need send freeze lock command.
482 // Below device will be froze:
483 // 1. Device not enable password.
484 // 2. Device enable password and unlocked.
486 if ((ConfigFormEntry
->IfrData
.SecurityStatus
.Supported
!= 0) &&
487 (ConfigFormEntry
->IfrData
.SecurityStatus
.Locked
== 0) &&
488 (ConfigFormEntry
->IfrData
.SecurityStatus
.Frozen
== 0)) {
489 Status
= FreezeLockDevice (ConfigFormEntry
->AtaPassThru
, ConfigFormEntry
->Port
, ConfigFormEntry
->PortMultiplierPort
);
490 DEBUG ((DEBUG_INFO
, "FreezeLockDevice return %r!\n", Status
));
491 Status
= GetHddDeviceIdentifyData (
492 ConfigFormEntry
->AtaPassThru
,
493 ConfigFormEntry
->Port
,
494 ConfigFormEntry
->PortMultiplierPort
,
497 GetHddPasswordSecurityStatus (&IdentifyData
, &ConfigFormEntry
->IfrData
);
501 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
503 gBS
->CloseEvent (Event
);
509 @param[in, out] SaltValue Points to the salt buffer, 32 bytes
514 IN OUT UINT8
*SaltValue
517 RandomSeed (NULL
, 0);
518 RandomBytes (SaltValue
, PASSWORD_SALT_SIZE
);
522 Hash the data to get credential.
524 @param[in] Buffer Points to the data buffer
525 @param[in] BufferSize Buffer size
526 @param[in] SaltValue Points to the salt buffer, 32 bytes
527 @param[out] Credential Points to the hashed result
529 @retval TRUE Hash the data successfully.
530 @retval FALSE Failed to hash the data.
538 OUT UINT8
*Credential
550 HashSize
= Sha256GetContextSize ();
551 Hash
= AllocateZeroPool (HashSize
);
552 ASSERT (Hash
!= NULL
);
557 Status
= Sha256Init (Hash
);
562 HashData
= AllocateZeroPool (PASSWORD_SALT_SIZE
+ BufferSize
);
563 ASSERT (HashData
!= NULL
);
564 if (HashData
== NULL
) {
568 CopyMem (HashData
, SaltValue
, PASSWORD_SALT_SIZE
);
569 CopyMem ((UINT8
*) HashData
+ PASSWORD_SALT_SIZE
, Buffer
, BufferSize
);
571 Status
= Sha256Update (Hash
, HashData
, PASSWORD_SALT_SIZE
+ BufferSize
);
576 Status
= Sha256Final (Hash
, Credential
);
582 if (HashData
!= NULL
) {
583 ZeroMem (HashData
, PASSWORD_SALT_SIZE
+ BufferSize
);
590 Save HDD password variable that will be used to validate HDD password
591 when the device is at frozen state.
593 @param[in] ConfigFormEntry The HDD Password configuration form entry.
594 @param[in] Password The hdd password of attached ATA device.
598 SaveHddPasswordVariable (
599 IN HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
,
604 HDD_PASSWORD_VARIABLE
*TempVariable
;
605 UINTN TempVariableSize
;
606 HDD_PASSWORD_VARIABLE
*NextNode
;
607 HDD_PASSWORD_VARIABLE
*Variable
;
609 HDD_PASSWORD_VARIABLE
*NewVariable
;
610 UINTN NewVariableSize
;
613 UINT8 HashData
[SHA256_DIGEST_SIZE
];
614 UINT8 SaltData
[PASSWORD_SALT_SIZE
];
616 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
619 if (!PasswordIsFullZero (Password
)) {
621 // It is Set/Update HDD Password.
623 ZeroMem (HashData
, sizeof (HashData
));
624 ZeroMem (SaltData
, sizeof (SaltData
));
626 HashOk
= GenerateCredential ((UINT8
*) Password
, HDD_PASSWORD_MAX_LENGTH
, SaltData
, HashData
);
628 DEBUG ((DEBUG_INFO
, "GenerateCredential failed\n"));
633 // It is Disable HDD Password.
634 // Go to delete the variable node for the HDD password device.
644 Status
= GetVariable2 (
645 HDD_PASSWORD_VARIABLE_NAME
,
646 &mHddPasswordVendorGuid
,
651 if (!EFI_ERROR (Status
) && (Variable
!= NULL
)) {
652 TempVariable
= Variable
;
653 TempVariableSize
= VariableSize
;
654 while (TempVariableSize
>= sizeof (HDD_PASSWORD_VARIABLE
)) {
655 if ((TempVariable
->Device
.Bus
== ConfigFormEntry
->Bus
) &&
656 (TempVariable
->Device
.Device
== ConfigFormEntry
->Device
) &&
657 (TempVariable
->Device
.Function
== ConfigFormEntry
->Function
) &&
658 (TempVariable
->Device
.Port
== ConfigFormEntry
->Port
) &&
659 (TempVariable
->Device
.PortMultiplierPort
== ConfigFormEntry
->PortMultiplierPort
)) {
661 // Found the node for the HDD password device.
664 NextNode
= TempVariable
+ 1;
665 CopyMem (TempVariable
, NextNode
, (UINTN
) Variable
+ VariableSize
- (UINTN
) NextNode
);
666 NewVariable
= Variable
;
667 NewVariableSize
= VariableSize
- sizeof (HDD_PASSWORD_VARIABLE
);
670 TempVariableSize
-= sizeof (HDD_PASSWORD_VARIABLE
);
673 if (NewVariable
== NULL
) {
674 DEBUG ((DEBUG_INFO
, "The variable node for the HDD password device is not found\n"));
677 DEBUG ((DEBUG_INFO
, "HddPassword variable get failed (%r)\n", Status
));
680 if (!EFI_ERROR (Status
) && (Variable
!= NULL
)) {
681 TempVariable
= Variable
;
682 TempVariableSize
= VariableSize
;
683 while (TempVariableSize
>= sizeof (HDD_PASSWORD_VARIABLE
)) {
684 if ((TempVariable
->Device
.Bus
== ConfigFormEntry
->Bus
) &&
685 (TempVariable
->Device
.Device
== ConfigFormEntry
->Device
) &&
686 (TempVariable
->Device
.Function
== ConfigFormEntry
->Function
) &&
687 (TempVariable
->Device
.Port
== ConfigFormEntry
->Port
) &&
688 (TempVariable
->Device
.PortMultiplierPort
== ConfigFormEntry
->PortMultiplierPort
)) {
690 // Found the node for the HDD password device.
693 CopyMem (TempVariable
->PasswordHash
, HashData
, sizeof (HashData
));
694 CopyMem (TempVariable
->PasswordSalt
, SaltData
, sizeof (SaltData
));
695 NewVariable
= Variable
;
696 NewVariableSize
= VariableSize
;
699 TempVariableSize
-= sizeof (HDD_PASSWORD_VARIABLE
);
702 if (NewVariable
== NULL
) {
704 // The node for the HDD password device is not found.
705 // Create node for the HDD password device.
707 NewVariableSize
= VariableSize
+ sizeof (HDD_PASSWORD_VARIABLE
);
708 NewVariable
= AllocateZeroPool (NewVariableSize
);
709 ASSERT (NewVariable
!= NULL
);
710 CopyMem (NewVariable
, Variable
, VariableSize
);
711 TempVariable
= (HDD_PASSWORD_VARIABLE
*) ((UINTN
) NewVariable
+ VariableSize
);
712 TempVariable
->Device
.Bus
= (UINT8
) ConfigFormEntry
->Bus
;
713 TempVariable
->Device
.Device
= (UINT8
) ConfigFormEntry
->Device
;
714 TempVariable
->Device
.Function
= (UINT8
) ConfigFormEntry
->Function
;
715 TempVariable
->Device
.Port
= ConfigFormEntry
->Port
;
716 TempVariable
->Device
.PortMultiplierPort
= ConfigFormEntry
->PortMultiplierPort
;
717 CopyMem (TempVariable
->PasswordHash
, HashData
, sizeof (HashData
));
718 CopyMem (TempVariable
->PasswordSalt
, SaltData
, sizeof (SaltData
));
721 NewVariableSize
= sizeof (HDD_PASSWORD_VARIABLE
);
722 NewVariable
= AllocateZeroPool (NewVariableSize
);
723 ASSERT (NewVariable
!= NULL
);
724 NewVariable
->Device
.Bus
= (UINT8
) ConfigFormEntry
->Bus
;
725 NewVariable
->Device
.Device
= (UINT8
) ConfigFormEntry
->Device
;
726 NewVariable
->Device
.Function
= (UINT8
) ConfigFormEntry
->Function
;
727 NewVariable
->Device
.Port
= ConfigFormEntry
->Port
;
728 NewVariable
->Device
.PortMultiplierPort
= ConfigFormEntry
->PortMultiplierPort
;
729 CopyMem (NewVariable
->PasswordHash
, HashData
, sizeof (HashData
));
730 CopyMem (NewVariable
->PasswordSalt
, SaltData
, sizeof (SaltData
));
734 if (NewVariable
!= NULL
) {
735 Status
= gRT
->SetVariable (
736 HDD_PASSWORD_VARIABLE_NAME
,
737 &mHddPasswordVendorGuid
,
738 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
742 if (EFI_ERROR (Status
)) {
743 DEBUG ((DEBUG_INFO
, "HddPassword variable set failed (%r)\n", Status
));
747 if (NewVariable
!= Variable
) {
748 FreePool (NewVariable
);
750 if (Variable
!= NULL
) {
754 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
758 Get saved HDD password variable that will be used to validate HDD password
759 when the device is at frozen state.
761 @param[in] ConfigFormEntry The HDD Password configuration form entry.
762 @param[out] HddPasswordVariable The variable node for the HDD password device.
764 @retval TRUE The variable node for the HDD password device is found and returned.
765 @retval FALSE The variable node for the HDD password device is not found.
769 GetSavedHddPasswordVariable (
770 IN HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
,
771 OUT HDD_PASSWORD_VARIABLE
*HddPasswordVariable
775 HDD_PASSWORD_VARIABLE
*TempVariable
;
776 HDD_PASSWORD_VARIABLE
*Variable
;
780 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
785 Status
= GetVariable2 (
786 HDD_PASSWORD_VARIABLE_NAME
,
787 &mHddPasswordVendorGuid
,
791 if (EFI_ERROR (Status
) || (Variable
== NULL
)) {
792 DEBUG ((DEBUG_INFO
, "HddPassword variable get failed (%r)\n", Status
));
797 TempVariable
= Variable
;
798 while (VariableSize
>= sizeof (HDD_PASSWORD_VARIABLE
)) {
799 if ((TempVariable
->Device
.Bus
== ConfigFormEntry
->Bus
) &&
800 (TempVariable
->Device
.Device
== ConfigFormEntry
->Device
) &&
801 (TempVariable
->Device
.Function
== ConfigFormEntry
->Function
) &&
802 (TempVariable
->Device
.Port
== ConfigFormEntry
->Port
) &&
803 (TempVariable
->Device
.PortMultiplierPort
== ConfigFormEntry
->PortMultiplierPort
)) {
805 // Found the node for the HDD password device.
808 CopyMem (HddPasswordVariable
, TempVariable
, sizeof (HDD_PASSWORD_VARIABLE
));
812 VariableSize
-= sizeof (HDD_PASSWORD_VARIABLE
);
819 DEBUG ((DEBUG_INFO
, "The variable node for the HDD password device is not found\n"));
822 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
828 Use saved HDD password variable to validate HDD password
829 when the device is at frozen state.
831 @param[in] ConfigFormEntry The HDD Password configuration form entry.
832 @param[in] Password The hdd password of attached ATA device.
834 @retval EFI_SUCCESS Pass to validate the HDD password.
835 @retval EFI_NOT_FOUND The variable node for the HDD password device is not found.
836 @retval EFI_DEVICE_ERROR Failed to generate credential for the HDD password.
837 @retval EFI_INVALID_PARAMETER Failed to validate the HDD password.
841 ValidateHddPassword (
842 IN HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
,
847 HDD_PASSWORD_VARIABLE HddPasswordVariable
;
849 UINT8 HashData
[SHA256_DIGEST_SIZE
];
851 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
853 if (!GetSavedHddPasswordVariable (ConfigFormEntry
, &HddPasswordVariable
)) {
854 DEBUG ((DEBUG_INFO
, "GetSavedHddPasswordVariable failed\n"));
855 return EFI_NOT_FOUND
;
858 ZeroMem (HashData
, sizeof (HashData
));
859 HashOk
= GenerateCredential ((UINT8
*) Password
, HDD_PASSWORD_MAX_LENGTH
, HddPasswordVariable
.PasswordSalt
, HashData
);
861 DEBUG ((DEBUG_INFO
, "GenerateCredential failed\n"));
862 return EFI_DEVICE_ERROR
;
865 if (CompareMem (HddPasswordVariable
.PasswordHash
, HashData
, sizeof (HashData
)) != 0) {
866 Status
= EFI_INVALID_PARAMETER
;
868 Status
= EFI_SUCCESS
;
871 DEBUG ((DEBUG_INFO
, "%a() - exit (%r)\n", __FUNCTION__
, Status
));
876 Send unlock hdd password cmd through Ata Pass Thru Protocol.
878 @param[in] AtaPassThru The pointer to the ATA_PASS_THRU protocol.
879 @param[in] Port The port number of the ATA device to send the command.
880 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
881 If there is no port multiplier, then specify 0xFFFF.
882 @param[in] Identifier The identifier to set user or master password.
883 @param[in] Password The hdd password of attached ATA device.
885 @retval EFI_SUCCESS Successful to send unlock hdd password cmd.
886 @retval EFI_INVALID_PARAMETER The parameter passed-in is invalid.
887 @retval EFI_OUT_OF_RESOURCES Not enough memory to send unlock hdd password cmd.
888 @retval EFI_DEVICE_ERROR Can not send unlock hdd password cmd.
893 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
895 IN UINT16 PortMultiplierPort
,
901 EFI_ATA_COMMAND_BLOCK Acb
;
902 EFI_ATA_STATUS_BLOCK
*Asb
;
903 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet
;
904 UINT8 Buffer
[HDD_PAYLOAD
];
906 if ((AtaPassThru
== NULL
) || (Password
== NULL
)) {
907 return EFI_INVALID_PARAMETER
;
911 // The 'Asb' field (a pointer to the EFI_ATA_STATUS_BLOCK structure) in
912 // EFI_ATA_PASS_THRU_COMMAND_PACKET is required to be aligned specified by
913 // the 'IoAlign' field in the EFI_ATA_PASS_THRU_MODE structure. Meanwhile,
914 // the structure EFI_ATA_STATUS_BLOCK is composed of only UINT8 fields, so it
915 // may not be aligned when allocated on stack for some compilers. Hence, we
916 // use the API AllocateAlignedPages to ensure this structure is properly
919 Asb
= AllocateAlignedPages (
920 EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)),
921 AtaPassThru
->Mode
->IoAlign
924 return EFI_OUT_OF_RESOURCES
;
928 // Prepare for ATA command block.
930 ZeroMem (&Acb
, sizeof (Acb
));
931 ZeroMem (Asb
, sizeof (EFI_ATA_STATUS_BLOCK
));
932 Acb
.AtaCommand
= ATA_SECURITY_UNLOCK_CMD
;
933 Acb
.AtaDeviceHead
= (UINT8
) (PortMultiplierPort
== 0xFFFF ? 0 : (PortMultiplierPort
<< 4));
936 // Prepare for ATA pass through packet.
938 ZeroMem (&Packet
, sizeof (Packet
));
939 Packet
.Protocol
= EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT
;
940 Packet
.Length
= EFI_ATA_PASS_THRU_LENGTH_BYTES
;
944 ((CHAR16
*) Buffer
)[0] = Identifier
& BIT0
;
945 CopyMem (&((CHAR16
*) Buffer
)[1], Password
, HDD_PASSWORD_MAX_LENGTH
);
947 Packet
.OutDataBuffer
= Buffer
;
948 Packet
.OutTransferLength
= sizeof (Buffer
);
949 Packet
.Timeout
= ATA_TIMEOUT
;
951 Status
= AtaPassThru
->PassThru (
958 if (!EFI_ERROR (Status
) &&
959 ((Asb
->AtaStatus
& ATA_STSREG_ERR
) != 0) &&
960 ((Asb
->AtaError
& ATA_ERRREG_ABRT
) != 0)) {
961 Status
= EFI_DEVICE_ERROR
;
964 FreeAlignedPages (Asb
, EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)));
966 ZeroMem (Buffer
, sizeof (Buffer
));
968 DEBUG ((DEBUG_INFO
, "%a() - %r\n", __FUNCTION__
, Status
));
973 Send disable hdd password cmd through Ata Pass Thru Protocol.
975 @param[in] AtaPassThru The pointer to the ATA_PASS_THRU protocol.
976 @param[in] Port The port number of the ATA device to send the command.
977 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
978 If there is no port multiplier, then specify 0xFFFF.
979 @param[in] Identifier The identifier to set user or master password.
980 @param[in] Password The hdd password of attached ATA device.
982 @retval EFI_SUCCESS Successful to disable hdd password cmd.
983 @retval EFI_INVALID_PARAMETER The parameter passed-in is invalid.
984 @retval EFI_OUT_OF_RESOURCES Not enough memory to disable hdd password cmd.
985 @retval EFI_DEVICE_ERROR Can not disable hdd password cmd.
990 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
992 IN UINT16 PortMultiplierPort
,
998 EFI_ATA_COMMAND_BLOCK Acb
;
999 EFI_ATA_STATUS_BLOCK
*Asb
;
1000 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet
;
1001 UINT8 Buffer
[HDD_PAYLOAD
];
1003 if ((AtaPassThru
== NULL
) || (Password
== NULL
)) {
1004 return EFI_INVALID_PARAMETER
;
1008 // The 'Asb' field (a pointer to the EFI_ATA_STATUS_BLOCK structure) in
1009 // EFI_ATA_PASS_THRU_COMMAND_PACKET is required to be aligned specified by
1010 // the 'IoAlign' field in the EFI_ATA_PASS_THRU_MODE structure. Meanwhile,
1011 // the structure EFI_ATA_STATUS_BLOCK is composed of only UINT8 fields, so it
1012 // may not be aligned when allocated on stack for some compilers. Hence, we
1013 // use the API AllocateAlignedPages to ensure this structure is properly
1016 Asb
= AllocateAlignedPages (
1017 EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)),
1018 AtaPassThru
->Mode
->IoAlign
1021 return EFI_OUT_OF_RESOURCES
;
1025 // Prepare for ATA command block.
1027 ZeroMem (&Acb
, sizeof (Acb
));
1028 ZeroMem (Asb
, sizeof (EFI_ATA_STATUS_BLOCK
));
1029 Acb
.AtaCommand
= ATA_SECURITY_DIS_PASSWORD_CMD
;
1030 Acb
.AtaDeviceHead
= (UINT8
) (PortMultiplierPort
== 0xFFFF ? 0 : (PortMultiplierPort
<< 4));
1033 // Prepare for ATA pass through packet.
1035 ZeroMem (&Packet
, sizeof (Packet
));
1036 Packet
.Protocol
= EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT
;
1037 Packet
.Length
= EFI_ATA_PASS_THRU_LENGTH_BYTES
;
1041 ((CHAR16
*) Buffer
)[0] = Identifier
& BIT0
;
1042 CopyMem (&((CHAR16
*) Buffer
)[1], Password
, HDD_PASSWORD_MAX_LENGTH
);
1044 Packet
.OutDataBuffer
= Buffer
;
1045 Packet
.OutTransferLength
= sizeof (Buffer
);
1046 Packet
.Timeout
= ATA_TIMEOUT
;
1048 Status
= AtaPassThru
->PassThru (
1055 if (!EFI_ERROR (Status
) &&
1056 ((Asb
->AtaStatus
& ATA_STSREG_ERR
) != 0) &&
1057 ((Asb
->AtaError
& ATA_ERRREG_ABRT
) != 0)) {
1058 Status
= EFI_DEVICE_ERROR
;
1061 FreeAlignedPages (Asb
, EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)));
1063 ZeroMem (Buffer
, sizeof (Buffer
));
1065 DEBUG ((DEBUG_INFO
, "%a() - %r\n", __FUNCTION__
, Status
));
1070 Send set hdd password cmd through Ata Pass Thru Protocol.
1072 @param[in] AtaPassThru The pointer to the ATA_PASS_THRU protocol.
1073 @param[in] Port The port number of the ATA device to send the command.
1074 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
1075 If there is no port multiplier, then specify 0xFFFF.
1076 @param[in] Identifier The identifier to set user or master password.
1077 @param[in] SecurityLevel The security level to be set to device.
1078 @param[in] MasterPasswordIdentifier The master password identifier to be set to device.
1079 @param[in] Password The hdd password of attached ATA device.
1081 @retval EFI_SUCCESS Successful to set hdd password cmd.
1082 @retval EFI_INVALID_PARAMETER The parameter passed-in is invalid.
1083 @retval EFI_OUT_OF_RESOURCES Not enough memory to set hdd password cmd.
1084 @retval EFI_DEVICE_ERROR Can not set hdd password cmd.
1089 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
1091 IN UINT16 PortMultiplierPort
,
1092 IN CHAR8 Identifier
,
1093 IN CHAR8 SecurityLevel
,
1094 IN CHAR16 MasterPasswordIdentifier
,
1099 EFI_ATA_COMMAND_BLOCK Acb
;
1100 EFI_ATA_STATUS_BLOCK
*Asb
;
1101 EFI_ATA_PASS_THRU_COMMAND_PACKET Packet
;
1102 UINT8 Buffer
[HDD_PAYLOAD
];
1104 if ((AtaPassThru
== NULL
) || (Password
== NULL
)) {
1105 return EFI_INVALID_PARAMETER
;
1109 // The 'Asb' field (a pointer to the EFI_ATA_STATUS_BLOCK structure) in
1110 // EFI_ATA_PASS_THRU_COMMAND_PACKET is required to be aligned specified by
1111 // the 'IoAlign' field in the EFI_ATA_PASS_THRU_MODE structure. Meanwhile,
1112 // the structure EFI_ATA_STATUS_BLOCK is composed of only UINT8 fields, so it
1113 // may not be aligned when allocated on stack for some compilers. Hence, we
1114 // use the API AllocateAlignedPages to ensure this structure is properly
1117 Asb
= AllocateAlignedPages (
1118 EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)),
1119 AtaPassThru
->Mode
->IoAlign
1122 return EFI_OUT_OF_RESOURCES
;
1126 // Prepare for ATA command block.
1128 ZeroMem (&Acb
, sizeof (Acb
));
1129 ZeroMem (Asb
, sizeof (EFI_ATA_STATUS_BLOCK
));
1130 Acb
.AtaCommand
= ATA_SECURITY_SET_PASSWORD_CMD
;
1131 Acb
.AtaDeviceHead
= (UINT8
) (PortMultiplierPort
== 0xFFFF ? 0 : (PortMultiplierPort
<< 4));
1134 // Prepare for ATA pass through packet.
1136 ZeroMem (&Packet
, sizeof (Packet
));
1137 Packet
.Protocol
= EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT
;
1138 Packet
.Length
= EFI_ATA_PASS_THRU_LENGTH_BYTES
;
1142 ((CHAR16
*) Buffer
)[0] = (Identifier
| (UINT16
)(SecurityLevel
<< 8)) & (BIT0
| BIT8
);
1143 CopyMem (&((CHAR16
*) Buffer
)[1], Password
, HDD_PASSWORD_MAX_LENGTH
);
1144 if ((Identifier
& BIT0
) != 0) {
1145 ((CHAR16
*) Buffer
)[17] = MasterPasswordIdentifier
;
1148 Packet
.OutDataBuffer
= Buffer
;
1149 Packet
.OutTransferLength
= sizeof (Buffer
);
1150 Packet
.Timeout
= ATA_TIMEOUT
;
1152 Status
= AtaPassThru
->PassThru (
1159 if (!EFI_ERROR (Status
) &&
1160 ((Asb
->AtaStatus
& ATA_STSREG_ERR
) != 0) &&
1161 ((Asb
->AtaError
& ATA_ERRREG_ABRT
) != 0)) {
1162 Status
= EFI_DEVICE_ERROR
;
1165 FreeAlignedPages (Asb
, EFI_SIZE_TO_PAGES (sizeof (EFI_ATA_STATUS_BLOCK
)));
1167 ZeroMem (Buffer
, sizeof (Buffer
));
1169 DEBUG ((DEBUG_INFO
, "%a() - %r\n", __FUNCTION__
, Status
));
1174 Get attached harddisk model number from identify data buffer.
1176 @param[in] IdentifyData Pointer to identify data buffer.
1177 @param[in, out] String The buffer to store harddisk model number.
1181 GetHddDeviceModelNumber (
1182 IN ATA_IDENTIFY_DATA
*IdentifyData
,
1183 IN OUT CHAR16
*String
1189 // Swap the byte order in the original module name.
1190 // From Ata spec, the maximum length is 40 bytes.
1192 for (Index
= 0; Index
< 40; Index
+= 2) {
1193 String
[Index
] = IdentifyData
->ModelName
[Index
+ 1];
1194 String
[Index
+ 1] = IdentifyData
->ModelName
[Index
];
1198 // Chap it off after 20 characters
1206 Get password input from the popup windows.
1208 @param[in] PopUpString1 Pop up string 1.
1209 @param[in] PopUpString2 Pop up string 2.
1210 @param[in, out] Password The buffer to hold the input password.
1212 @retval EFI_ABORTED It is given up by pressing 'ESC' key.
1213 @retval EFI_SUCCESS Get password input successfully.
1217 PopupHddPasswordInputWindows (
1218 IN CHAR16
*PopUpString1
,
1219 IN CHAR16
*PopUpString2
,
1220 IN OUT CHAR8
*Password
1225 CHAR16 Mask
[HDD_PASSWORD_MAX_LENGTH
+ 1];
1226 CHAR16 Unicode
[HDD_PASSWORD_MAX_LENGTH
+ 1];
1227 CHAR8 Ascii
[HDD_PASSWORD_MAX_LENGTH
+ 1];
1229 ZeroMem (Unicode
, sizeof (Unicode
));
1230 ZeroMem (Ascii
, sizeof (Ascii
));
1231 ZeroMem (Mask
, sizeof (Mask
));
1233 gST
->ConOut
->ClearScreen(gST
->ConOut
);
1237 Mask
[Length
] = L
'_';
1238 if (PopUpString2
== NULL
) {
1240 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1243 L
"---------------------",
1249 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1253 L
"---------------------",
1261 if (Key
.ScanCode
== SCAN_NULL
) {
1262 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
1264 // Add the null terminator.
1266 Unicode
[Length
] = 0;
1268 } else if ((Key
.UnicodeChar
== CHAR_NULL
) ||
1269 (Key
.UnicodeChar
== CHAR_TAB
) ||
1270 (Key
.UnicodeChar
== CHAR_LINEFEED
)
1274 if (Key
.UnicodeChar
== CHAR_BACKSPACE
) {
1276 Unicode
[Length
] = 0;
1281 Unicode
[Length
] = Key
.UnicodeChar
;
1282 Mask
[Length
] = L
'*';
1284 if (Length
== HDD_PASSWORD_MAX_LENGTH
) {
1286 // Add the null terminator.
1288 Unicode
[Length
] = 0;
1296 if (Key
.ScanCode
== SCAN_ESC
) {
1297 ZeroMem (Unicode
, sizeof (Unicode
));
1298 ZeroMem (Ascii
, sizeof (Ascii
));
1299 gST
->ConOut
->ClearScreen(gST
->ConOut
);
1304 UnicodeStrToAsciiStrS (Unicode
, Ascii
, sizeof (Ascii
));
1305 CopyMem (Password
, Ascii
, HDD_PASSWORD_MAX_LENGTH
);
1306 ZeroMem (Unicode
, sizeof (Unicode
));
1307 ZeroMem (Ascii
, sizeof (Ascii
));
1309 gST
->ConOut
->ClearScreen(gST
->ConOut
);
1314 Check if disk is locked, show popup window and ask for password if it is.
1316 @param[in] AtaPassThru Pointer to ATA_PASSTHRU instance.
1317 @param[in] Port The port number of attached ATA device.
1318 @param[in] PortMultiplierPort The port number of port multiplier of attached ATA device.
1319 @param[in] ConfigFormEntry The HDD Password configuration form entry.
1323 HddPasswordRequestPassword (
1324 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
1326 IN UINT16 PortMultiplierPort
,
1327 IN HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
1331 CHAR16 PopUpString
[100];
1332 ATA_IDENTIFY_DATA IdentifyData
;
1335 CHAR8 Password
[HDD_PASSWORD_MAX_LENGTH
];
1339 DEBUG ((DEBUG_INFO
, "%a()\n", __FUNCTION__
));
1341 UnicodeSPrint (PopUpString
, sizeof (PopUpString
), L
"Unlock: %s", ConfigFormEntry
->HddString
);
1344 // Check the device security status.
1346 if ((ConfigFormEntry
->IfrData
.SecurityStatus
.Supported
) &&
1347 (ConfigFormEntry
->IfrData
.SecurityStatus
.Enabled
)) {
1349 // As soon as the HDD password is in enabled state, we pop up a window to unlock hdd
1350 // no matter it's really in locked or unlocked state.
1351 // This way forces user to enter password every time to provide best safety.
1354 Status
= PopupHddPasswordInputWindows (PopUpString
, NULL
, Password
);
1355 if (!EFI_ERROR (Status
)) {
1357 // The HDD is in locked state, unlock it by user input.
1359 if (!PasswordIsFullZero (Password
)) {
1360 if (!ConfigFormEntry
->IfrData
.SecurityStatus
.Frozen
) {
1361 Status
= UnlockHddPassword (AtaPassThru
, Port
, PortMultiplierPort
, 0, Password
);
1364 // Use saved HDD password variable to validate HDD password
1365 // when the device is at frozen state.
1367 Status
= ValidateHddPassword (ConfigFormEntry
, Password
);
1370 Status
= EFI_INVALID_PARAMETER
;
1372 if (!EFI_ERROR (Status
)) {
1373 CopyMem (ConfigFormEntry
->Password
, Password
, HDD_PASSWORD_MAX_LENGTH
);
1374 if (!ConfigFormEntry
->IfrData
.SecurityStatus
.Frozen
) {
1375 SaveHddPasswordVariable (ConfigFormEntry
, Password
);
1377 ZeroMem (Password
, HDD_PASSWORD_MAX_LENGTH
);
1378 Status
= GetHddDeviceIdentifyData (AtaPassThru
, Port
, PortMultiplierPort
, &IdentifyData
);
1379 ASSERT_EFI_ERROR (Status
);
1382 // Check the device security status again.
1384 GetHddPasswordSecurityStatus (&IdentifyData
, &ConfigFormEntry
->IfrData
);
1388 ZeroMem (Password
, HDD_PASSWORD_MAX_LENGTH
);
1390 if (EFI_ERROR (Status
)) {
1392 if (RetryCount
< MAX_HDD_PASSWORD_RETRY_COUNT
) {
1395 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1397 L
"Invalid password.",
1398 L
"Press ENTER to retry",
1401 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1406 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1408 L
"Hdd password retry count is expired. Please shutdown the machine.",
1409 L
"Press ENTER to shutdown",
1412 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1413 gRT
->ResetSystem (EfiResetShutdown
, EFI_SUCCESS
, 0, NULL
);
1417 } else if (Status
== EFI_ABORTED
) {
1418 if (ConfigFormEntry
->IfrData
.SecurityStatus
.Locked
) {
1420 // Current device in the lock status and
1421 // User not input password and press ESC,
1422 // keep device in lock status and continue boot.
1426 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1428 L
"Press ENTER to skip the request and continue boot,",
1429 L
"Press ESC to input password again",
1432 } while ((Key
.ScanCode
!= SCAN_ESC
) && (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
));
1434 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
1435 gST
->ConOut
->ClearScreen(gST
->ConOut
);
1437 // Keep lock and continue boot.
1442 // Let user input password again.
1448 // Current device in the unlock status and
1449 // User not input password and press ESC,
1450 // Shutdown the device.
1454 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1456 L
"Press ENTER to shutdown, Press ESC to input password again",
1459 } while ((Key
.ScanCode
!= SCAN_ESC
) && (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
));
1461 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
1462 gRT
->ResetSystem (EfiResetShutdown
, EFI_SUCCESS
, 0, NULL
);
1465 // Let user input password again.
1476 Process Set User Pwd HDD password request.
1478 @param[in] AtaPassThru Pointer to ATA_PASSTHRU instance.
1479 @param[in] Port The port number of attached ATA device.
1480 @param[in] PortMultiplierPort The port number of port multiplier of attached ATA device.
1481 @param[in] ConfigFormEntry The HDD Password configuration form entry.
1485 ProcessHddPasswordRequestSetUserPwd (
1486 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
1488 IN UINT16 PortMultiplierPort
,
1489 IN HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
1493 CHAR16 PopUpString
[100];
1494 ATA_IDENTIFY_DATA IdentifyData
;
1497 CHAR8 Password
[HDD_PASSWORD_MAX_LENGTH
];
1498 CHAR8 PasswordConfirm
[HDD_PASSWORD_MAX_LENGTH
];
1502 DEBUG ((DEBUG_INFO
, "%a()\n", __FUNCTION__
));
1504 if (ConfigFormEntry
->IfrData
.SecurityStatus
.Frozen
) {
1505 DEBUG ((DEBUG_INFO
, "%s is frozen, do nothing\n", ConfigFormEntry
->HddString
));
1509 if (ConfigFormEntry
->IfrData
.SecurityStatus
.Locked
) {
1510 DEBUG ((DEBUG_INFO
, "%s is locked, do nothing\n", ConfigFormEntry
->HddString
));
1514 UnicodeSPrint (PopUpString
, sizeof (PopUpString
), L
"Set User Pwd: %s", ConfigFormEntry
->HddString
);
1517 // Check the device security status.
1519 if (ConfigFormEntry
->IfrData
.SecurityStatus
.Supported
) {
1521 Status
= PopupHddPasswordInputWindows (PopUpString
, L
"Please type in your new password", Password
);
1522 if (!EFI_ERROR (Status
)) {
1523 Status
= PopupHddPasswordInputWindows (PopUpString
, L
"Please confirm your new password", PasswordConfirm
);
1524 if (!EFI_ERROR (Status
)) {
1525 if (CompareMem (Password
, PasswordConfirm
, HDD_PASSWORD_MAX_LENGTH
) == 0) {
1526 if (!PasswordIsFullZero (Password
)) {
1527 Status
= SetHddPassword (AtaPassThru
, Port
, PortMultiplierPort
, 0, 1, 0, Password
);
1529 if (ConfigFormEntry
->IfrData
.SecurityStatus
.Enabled
) {
1530 Status
= DisableHddPassword (AtaPassThru
, Port
, PortMultiplierPort
, 0, ConfigFormEntry
->Password
);
1532 Status
= EFI_INVALID_PARAMETER
;
1535 if (!EFI_ERROR (Status
)) {
1536 CopyMem (ConfigFormEntry
->Password
, Password
, HDD_PASSWORD_MAX_LENGTH
);
1537 SaveHddPasswordVariable (ConfigFormEntry
, Password
);
1538 ZeroMem (Password
, HDD_PASSWORD_MAX_LENGTH
);
1539 ZeroMem (PasswordConfirm
, HDD_PASSWORD_MAX_LENGTH
);
1540 Status
= GetHddDeviceIdentifyData (AtaPassThru
, Port
, PortMultiplierPort
, &IdentifyData
);
1541 ASSERT_EFI_ERROR (Status
);
1544 // Check the device security status again.
1546 GetHddPasswordSecurityStatus (&IdentifyData
, &ConfigFormEntry
->IfrData
);
1551 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1553 L
"Set/Disable User Pwd failed or invalid password.",
1554 L
"Press ENTER to retry",
1557 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1562 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1564 L
"Passwords are not the same.",
1565 L
"Press ENTER to retry",
1568 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1569 Status
= EFI_INVALID_PARAMETER
;
1573 ZeroMem (Password
, HDD_PASSWORD_MAX_LENGTH
);
1574 ZeroMem (PasswordConfirm
, HDD_PASSWORD_MAX_LENGTH
);
1576 if (EFI_ERROR (Status
)) {
1578 if (RetryCount
>= MAX_HDD_PASSWORD_RETRY_COUNT
) {
1581 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1583 L
"Hdd password retry count is expired.",
1584 L
"Press ENTER to skip the request and continue boot",
1587 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1588 gST
->ConOut
->ClearScreen(gST
->ConOut
);
1592 } else if (Status
== EFI_ABORTED
) {
1595 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1597 L
"Press ENTER to skip the request and continue boot,",
1598 L
"Press ESC to input password again",
1601 } while ((Key
.ScanCode
!= SCAN_ESC
) && (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
));
1603 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
1604 gST
->ConOut
->ClearScreen(gST
->ConOut
);
1608 // Let user input password again.
1618 Process Set Master Pwd HDD password request.
1620 @param[in] AtaPassThru Pointer to ATA_PASSTHRU instance.
1621 @param[in] Port The port number of attached ATA device.
1622 @param[in] PortMultiplierPort The port number of port multiplier of attached ATA device.
1623 @param[in] ConfigFormEntry The HDD Password configuration form entry.
1627 ProcessHddPasswordRequestSetMasterPwd (
1628 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
1630 IN UINT16 PortMultiplierPort
,
1631 IN HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
1635 CHAR16 PopUpString
[100];
1638 CHAR8 Password
[HDD_PASSWORD_MAX_LENGTH
];
1639 CHAR8 PasswordConfirm
[HDD_PASSWORD_MAX_LENGTH
];
1643 DEBUG ((DEBUG_INFO
, "%a()\n", __FUNCTION__
));
1645 if (ConfigFormEntry
->IfrData
.SecurityStatus
.Frozen
) {
1646 DEBUG ((DEBUG_INFO
, "%s is frozen, do nothing\n", ConfigFormEntry
->HddString
));
1650 if (ConfigFormEntry
->IfrData
.SecurityStatus
.Locked
) {
1651 DEBUG ((DEBUG_INFO
, "%s is locked, do nothing\n", ConfigFormEntry
->HddString
));
1655 UnicodeSPrint (PopUpString
, sizeof (PopUpString
), L
"Set Master Pwd: %s", ConfigFormEntry
->HddString
);
1658 // Check the device security status.
1660 if (ConfigFormEntry
->IfrData
.SecurityStatus
.Supported
) {
1662 Status
= PopupHddPasswordInputWindows (PopUpString
, L
"Please type in your new password", Password
);
1663 if (!EFI_ERROR (Status
)) {
1664 Status
= PopupHddPasswordInputWindows (PopUpString
, L
"Please confirm your new password", PasswordConfirm
);
1665 if (!EFI_ERROR (Status
)) {
1666 if (CompareMem (Password
, PasswordConfirm
, HDD_PASSWORD_MAX_LENGTH
) == 0) {
1667 if (!PasswordIsFullZero (Password
)) {
1668 Status
= SetHddPassword (AtaPassThru
, Port
, PortMultiplierPort
, 1, 1, 1, Password
);
1670 Status
= EFI_INVALID_PARAMETER
;
1672 if (!EFI_ERROR (Status
)) {
1673 ZeroMem (Password
, HDD_PASSWORD_MAX_LENGTH
);
1674 ZeroMem (PasswordConfirm
, HDD_PASSWORD_MAX_LENGTH
);
1679 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1681 L
"Set Master Pwd failed or invalid password.",
1682 L
"Press ENTER to retry",
1685 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1690 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1692 L
"Passwords are not the same.",
1693 L
"Press ENTER to retry",
1696 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1697 Status
= EFI_INVALID_PARAMETER
;
1701 ZeroMem (Password
, HDD_PASSWORD_MAX_LENGTH
);
1702 ZeroMem (PasswordConfirm
, HDD_PASSWORD_MAX_LENGTH
);
1704 if (EFI_ERROR (Status
)) {
1706 if (RetryCount
>= MAX_HDD_PASSWORD_RETRY_COUNT
) {
1709 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1711 L
"Hdd password retry count is expired.",
1712 L
"Press ENTER to skip the request and continue boot",
1715 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1716 gST
->ConOut
->ClearScreen(gST
->ConOut
);
1720 } else if (Status
== EFI_ABORTED
) {
1723 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
1725 L
"Press ENTER to skip the request and continue boot,",
1726 L
"Press ESC to input password again",
1729 } while ((Key
.ScanCode
!= SCAN_ESC
) && (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
));
1731 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
1732 gST
->ConOut
->ClearScreen(gST
->ConOut
);
1736 // Let user input password again.
1746 Process HDD password request.
1748 @param[in] AtaPassThru Pointer to ATA_PASSTHRU instance.
1749 @param[in] Port The port number of attached ATA device.
1750 @param[in] PortMultiplierPort The port number of port multiplier of attached ATA device.
1751 @param[in] ConfigFormEntry The HDD Password configuration form entry.
1755 ProcessHddPasswordRequest (
1756 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
1758 IN UINT16 PortMultiplierPort
,
1759 IN HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
1763 HDD_PASSWORD_REQUEST_VARIABLE
*TempVariable
;
1764 HDD_PASSWORD_REQUEST_VARIABLE
*Variable
;
1767 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
1769 if (mHddPasswordRequestVariable
== NULL
) {
1770 Status
= GetVariable2 (
1771 HDD_PASSWORD_REQUEST_VARIABLE_NAME
,
1772 &mHddPasswordVendorGuid
,
1773 (VOID
**) &Variable
,
1776 if (EFI_ERROR (Status
) || (Variable
== NULL
)) {
1779 mHddPasswordRequestVariable
= Variable
;
1780 mHddPasswordRequestVariableSize
= VariableSize
;
1783 // Delete the HDD password request variable.
1785 Status
= gRT
->SetVariable (
1786 HDD_PASSWORD_REQUEST_VARIABLE_NAME
,
1787 &mHddPasswordVendorGuid
,
1792 ASSERT_EFI_ERROR (Status
);
1794 Variable
= mHddPasswordRequestVariable
;
1795 VariableSize
= mHddPasswordRequestVariableSize
;
1799 // Process the HDD password requests.
1801 TempVariable
= Variable
;
1802 while (VariableSize
>= sizeof (HDD_PASSWORD_REQUEST_VARIABLE
)) {
1803 if ((TempVariable
->Device
.Bus
== ConfigFormEntry
->Bus
) &&
1804 (TempVariable
->Device
.Device
== ConfigFormEntry
->Device
) &&
1805 (TempVariable
->Device
.Function
== ConfigFormEntry
->Function
) &&
1806 (TempVariable
->Device
.Port
== ConfigFormEntry
->Port
) &&
1807 (TempVariable
->Device
.PortMultiplierPort
== ConfigFormEntry
->PortMultiplierPort
)) {
1809 // Found the node for the HDD password device.
1811 if (TempVariable
->Request
.UserPassword
!= 0) {
1812 ProcessHddPasswordRequestSetUserPwd (AtaPassThru
, Port
, PortMultiplierPort
, ConfigFormEntry
);
1814 if (TempVariable
->Request
.MasterPassword
!= 0) {
1815 ProcessHddPasswordRequestSetMasterPwd (AtaPassThru
, Port
, PortMultiplierPort
, ConfigFormEntry
);
1821 VariableSize
-= sizeof (HDD_PASSWORD_REQUEST_VARIABLE
);
1825 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
1829 Get saved HDD password request.
1831 @param[in, out] ConfigFormEntry The HDD Password configuration form entry.
1835 GetSavedHddPasswordRequest (
1836 IN OUT HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
1840 HDD_PASSWORD_REQUEST_VARIABLE
*TempVariable
;
1841 HDD_PASSWORD_REQUEST_VARIABLE
*Variable
;
1844 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
1849 Status
= GetVariable2 (
1850 HDD_PASSWORD_REQUEST_VARIABLE_NAME
,
1851 &mHddPasswordVendorGuid
,
1852 (VOID
**) &Variable
,
1855 if (EFI_ERROR (Status
) || (Variable
== NULL
)) {
1859 TempVariable
= Variable
;
1860 while (VariableSize
>= sizeof (HDD_PASSWORD_REQUEST_VARIABLE
)) {
1861 if ((TempVariable
->Device
.Bus
== ConfigFormEntry
->Bus
) &&
1862 (TempVariable
->Device
.Device
== ConfigFormEntry
->Device
) &&
1863 (TempVariable
->Device
.Function
== ConfigFormEntry
->Function
) &&
1864 (TempVariable
->Device
.Port
== ConfigFormEntry
->Port
) &&
1865 (TempVariable
->Device
.PortMultiplierPort
== ConfigFormEntry
->PortMultiplierPort
)) {
1867 // Found the node for the HDD password device.
1868 // Get the HDD password request.
1870 CopyMem (&ConfigFormEntry
->IfrData
.Request
, &TempVariable
->Request
, sizeof (HDD_PASSWORD_REQUEST
));
1873 "HddPasswordRequest got: 0x%x\n",
1874 ConfigFormEntry
->IfrData
.Request
1878 VariableSize
-= sizeof (HDD_PASSWORD_REQUEST_VARIABLE
);
1882 FreePool (Variable
);
1884 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
1888 Save HDD password request.
1890 @param[in] ConfigFormEntry The HDD Password configuration form entry.
1894 SaveHddPasswordRequest (
1895 IN HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
1899 HDD_PASSWORD_REQUEST_VARIABLE
*TempVariable
;
1900 UINTN TempVariableSize
;
1901 HDD_PASSWORD_REQUEST_VARIABLE
*Variable
;
1903 HDD_PASSWORD_REQUEST_VARIABLE
*NewVariable
;
1904 UINTN NewVariableSize
;
1906 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
1910 "HddPasswordRequest to save: 0x%x\n",
1911 ConfigFormEntry
->IfrData
.Request
1917 NewVariableSize
= 0;
1919 Status
= GetVariable2 (
1920 HDD_PASSWORD_REQUEST_VARIABLE_NAME
,
1921 &mHddPasswordVendorGuid
,
1922 (VOID
**) &Variable
,
1925 if (!EFI_ERROR (Status
) && (Variable
!= NULL
)) {
1926 TempVariable
= Variable
;
1927 TempVariableSize
= VariableSize
;
1928 while (TempVariableSize
>= sizeof (HDD_PASSWORD_REQUEST_VARIABLE
)) {
1929 if ((TempVariable
->Device
.Bus
== ConfigFormEntry
->Bus
) &&
1930 (TempVariable
->Device
.Device
== ConfigFormEntry
->Device
) &&
1931 (TempVariable
->Device
.Function
== ConfigFormEntry
->Function
) &&
1932 (TempVariable
->Device
.Port
== ConfigFormEntry
->Port
) &&
1933 (TempVariable
->Device
.PortMultiplierPort
== ConfigFormEntry
->PortMultiplierPort
)) {
1935 // Found the node for the HDD password device.
1936 // Update the HDD password request.
1938 CopyMem (&TempVariable
->Request
, &ConfigFormEntry
->IfrData
.Request
, sizeof (HDD_PASSWORD_REQUEST
));
1939 NewVariable
= Variable
;
1940 NewVariableSize
= VariableSize
;
1943 TempVariableSize
-= sizeof (HDD_PASSWORD_REQUEST_VARIABLE
);
1946 if (NewVariable
== NULL
) {
1948 // The node for the HDD password device is not found.
1949 // Create node for the HDD password device.
1951 NewVariableSize
= VariableSize
+ sizeof (HDD_PASSWORD_REQUEST_VARIABLE
);
1952 NewVariable
= AllocateZeroPool (NewVariableSize
);
1953 ASSERT (NewVariable
!= NULL
);
1954 CopyMem (NewVariable
, Variable
, VariableSize
);
1955 TempVariable
= (HDD_PASSWORD_REQUEST_VARIABLE
*) ((UINTN
) NewVariable
+ VariableSize
);
1956 TempVariable
->Device
.Bus
= (UINT8
) ConfigFormEntry
->Bus
;
1957 TempVariable
->Device
.Device
= (UINT8
) ConfigFormEntry
->Device
;
1958 TempVariable
->Device
.Function
= (UINT8
) ConfigFormEntry
->Function
;
1959 TempVariable
->Device
.Port
= ConfigFormEntry
->Port
;
1960 TempVariable
->Device
.PortMultiplierPort
= ConfigFormEntry
->PortMultiplierPort
;
1961 CopyMem (&TempVariable
->Request
, &ConfigFormEntry
->IfrData
.Request
, sizeof (HDD_PASSWORD_REQUEST
));
1964 NewVariableSize
= sizeof (HDD_PASSWORD_REQUEST_VARIABLE
);
1965 NewVariable
= AllocateZeroPool (NewVariableSize
);
1966 ASSERT (NewVariable
!= NULL
);
1967 NewVariable
->Device
.Bus
= (UINT8
) ConfigFormEntry
->Bus
;
1968 NewVariable
->Device
.Device
= (UINT8
) ConfigFormEntry
->Device
;
1969 NewVariable
->Device
.Function
= (UINT8
) ConfigFormEntry
->Function
;
1970 NewVariable
->Device
.Port
= ConfigFormEntry
->Port
;
1971 NewVariable
->Device
.PortMultiplierPort
= ConfigFormEntry
->PortMultiplierPort
;
1972 CopyMem (&NewVariable
->Request
, &ConfigFormEntry
->IfrData
.Request
, sizeof (HDD_PASSWORD_REQUEST
));
1974 Status
= gRT
->SetVariable (
1975 HDD_PASSWORD_REQUEST_VARIABLE_NAME
,
1976 &mHddPasswordVendorGuid
,
1977 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
1981 if (EFI_ERROR (Status
)) {
1982 DEBUG ((DEBUG_INFO
, "HddPasswordRequest variable set failed (%r)\n", Status
));
1984 if (NewVariable
!= Variable
) {
1985 FreePool (NewVariable
);
1987 if (Variable
!= NULL
) {
1988 FreePool (Variable
);
1991 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
1995 Get the HDD Password configuration form entry by the index of the goto opcode actived.
1997 @param[in] Index The 0-based index of the goto opcode actived.
1999 @return The HDD Password configuration form entry found.
2001 HDD_PASSWORD_CONFIG_FORM_ENTRY
*
2002 HddPasswordGetConfigFormEntryByIndex (
2007 UINT32 CurrentIndex
;
2008 HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
2011 ConfigFormEntry
= NULL
;
2013 EFI_LIST_FOR_EACH (Entry
, &mHddPasswordConfigFormList
) {
2014 if (CurrentIndex
== Index
) {
2015 ConfigFormEntry
= BASE_CR (Entry
, HDD_PASSWORD_CONFIG_FORM_ENTRY
, Link
);
2022 return ConfigFormEntry
;
2026 This function allows the caller to request the current
2027 configuration for one or more named elements. The resulting
2028 string is in <ConfigAltResp> format. Any and all alternative
2029 configuration strings shall also be appended to the end of the
2030 current configuration string. If they are, they must appear
2031 after the current configuration. They must contain the same
2032 routing (GUID, NAME, PATH) as the current configuration string.
2033 They must have an additional description indicating the type of
2034 alternative configuration the string represents,
2035 "ALTCFG=<StringToken>". That <StringToken> (when
2036 converted from Hex UNICODE to binary) is a reference to a
2037 string in the associated string pack.
2039 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
2040 @param[in] Request A null-terminated Unicode string in
2041 <ConfigRequest> format. Note that this
2042 includes the routing information as well as
2043 the configurable name / value pairs. It is
2044 invalid for this string to be in
2045 <MultiConfigRequest> format.
2046 @param[out] Progress On return, points to a character in the
2047 Request string. Points to the string's null
2048 terminator if request was successful. Points
2049 to the most recent "&" before the first
2050 failing name / value pair (or the beginning
2051 of the string if the failure is in the first
2052 name / value pair) if the request was not
2054 @param[out] Results A null-terminated Unicode string in
2055 <ConfigAltResp> format which has all values
2056 filled in for the names in the Request string.
2057 String to be allocated by the called function.
2059 @retval EFI_SUCCESS The Results string is filled with the
2060 values corresponding to all requested
2062 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
2063 parts of the results that must be
2064 stored awaiting possible future
2066 @retval EFI_INVALID_PARAMETER For example, passing in a NULL
2067 for the Request parameter
2068 would result in this type of
2069 error. In this case, the
2070 Progress parameter would be
2072 @retval EFI_NOT_FOUND Routing data doesn't match any
2073 known driver. Progress set to the
2074 first character in the routing header.
2075 Note: There is no requirement that the
2076 driver validate the routing data. It
2077 must skip the <ConfigHdr> in order to
2079 @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
2080 to most recent & before the
2081 error or the beginning of the
2083 @retval EFI_INVALID_PARAMETER Unknown name. Progress points
2084 to the & before the name in
2085 question.Currently not implemented.
2089 HddPasswordFormExtractConfig (
2090 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
2091 IN CONST EFI_STRING Request
,
2092 OUT EFI_STRING
*Progress
,
2093 OUT EFI_STRING
*Results
2098 HDD_PASSWORD_CONFIG
*IfrData
;
2099 HDD_PASSWORD_DXE_PRIVATE_DATA
*Private
;
2100 EFI_STRING ConfigRequestHdr
;
2101 EFI_STRING ConfigRequest
;
2102 BOOLEAN AllocatedRequest
;
2105 if (Progress
== NULL
|| Results
== NULL
) {
2106 return EFI_INVALID_PARAMETER
;
2109 *Progress
= Request
;
2110 if ((Request
!= NULL
) && !HiiIsConfigHdrMatch (Request
, &mHddPasswordVendorGuid
, mHddPasswordVendorStorageName
)) {
2111 return EFI_NOT_FOUND
;
2114 ConfigRequestHdr
= NULL
;
2115 ConfigRequest
= NULL
;
2116 AllocatedRequest
= FALSE
;
2119 Private
= HDD_PASSWORD_DXE_PRIVATE_FROM_THIS (This
);
2120 IfrData
= AllocateZeroPool (sizeof (HDD_PASSWORD_CONFIG
));
2121 ASSERT (IfrData
!= NULL
);
2122 if (Private
->Current
!= NULL
) {
2123 CopyMem (IfrData
, &Private
->Current
->IfrData
, sizeof (HDD_PASSWORD_CONFIG
));
2127 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
2129 BufferSize
= sizeof (HDD_PASSWORD_CONFIG
);
2130 ConfigRequest
= Request
;
2131 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
2133 // Request has no request element, construct full request string.
2134 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
2135 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
2137 ConfigRequestHdr
= HiiConstructConfigHdr (&mHddPasswordVendorGuid
, mHddPasswordVendorStorageName
, Private
->DriverHandle
);
2138 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
2139 ConfigRequest
= AllocateZeroPool (Size
);
2140 ASSERT (ConfigRequest
!= NULL
);
2141 AllocatedRequest
= TRUE
;
2142 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
2143 FreePool (ConfigRequestHdr
);
2145 Status
= gHiiConfigRouting
->BlockToConfig (
2155 // Free the allocated config request string.
2157 if (AllocatedRequest
) {
2158 FreePool (ConfigRequest
);
2159 ConfigRequest
= NULL
;
2163 // Set Progress string to the original request string.
2165 if (Request
== NULL
) {
2167 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
2168 *Progress
= Request
+ StrLen (Request
);
2175 This function applies changes in a driver's configuration.
2176 Input is a Configuration, which has the routing data for this
2177 driver followed by name / value configuration pairs. The driver
2178 must apply those pairs to its configurable storage. If the
2179 driver's configuration is stored in a linear block of data
2180 and the driver's name / value pairs are in <BlockConfig>
2181 format, it may use the ConfigToBlock helper function (above) to
2182 simplify the job. Currently not implemented.
2184 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
2185 @param[in] Configuration A null-terminated Unicode string in
2186 <ConfigString> format.
2187 @param[out] Progress A pointer to a string filled in with the
2188 offset of the most recent '&' before the
2189 first failing name / value pair (or the
2190 beginn ing of the string if the failure
2191 is in the first name / value pair) or
2192 the terminating NULL if all was
2195 @retval EFI_SUCCESS The results have been distributed or are
2196 awaiting distribution.
2197 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
2198 parts of the results that must be
2199 stored awaiting possible future
2201 @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
2202 Results parameter would result
2203 in this type of error.
2204 @retval EFI_NOT_FOUND Target for the specified routing data
2209 HddPasswordFormRouteConfig (
2210 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
2211 IN CONST EFI_STRING Configuration
,
2212 OUT EFI_STRING
*Progress
2215 if (Configuration
== NULL
|| Progress
== NULL
) {
2216 return EFI_INVALID_PARAMETER
;
2220 // Check routing data in <ConfigHdr>.
2221 // Note: if only one Storage is used, then this checking could be skipped.
2223 if (!HiiIsConfigHdrMatch (Configuration
, &mHddPasswordVendorGuid
, mHddPasswordVendorStorageName
)) {
2224 *Progress
= Configuration
;
2225 return EFI_NOT_FOUND
;
2228 *Progress
= Configuration
+ StrLen (Configuration
);
2233 This function is called to provide results data to the driver.
2234 This data consists of a unique key that is used to identify
2235 which data is either being passed back or being asked for.
2237 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
2238 @param[in] Action Specifies the type of action taken by the browser.
2239 @param[in] QuestionId A unique value which is sent to the original
2240 exporting driver so that it can identify the type
2241 of data to expect. The format of the data tends to
2242 vary based on the opcode that enerated the callback.
2243 @param[in] Type The type of value for the question.
2244 @param[in] Value A pointer to the data being sent to the original
2246 @param[out] ActionRequest On return, points to the action requested by the
2249 @retval EFI_SUCCESS The callback successfully handled the action.
2250 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
2251 variable and its data.
2252 @retval EFI_DEVICE_ERROR The variable could not be saved.
2253 @retval EFI_UNSUPPORTED The specified Action is not supported by the
2254 callback.Currently not implemented.
2255 @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.
2256 @retval Others Other errors as indicated.
2260 HddPasswordFormCallback (
2261 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
2262 IN EFI_BROWSER_ACTION Action
,
2263 IN EFI_QUESTION_ID QuestionId
,
2265 IN EFI_IFR_TYPE_VALUE
*Value
,
2266 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
2269 HDD_PASSWORD_DXE_PRIVATE_DATA
*Private
;
2270 EFI_STRING_ID DeviceFormTitleToken
;
2271 HDD_PASSWORD_CONFIG
*IfrData
;
2272 HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
2274 if (ActionRequest
!= NULL
) {
2275 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
2277 return EFI_INVALID_PARAMETER
;
2280 if ((Action
!= EFI_BROWSER_ACTION_CHANGING
) && (Action
!= EFI_BROWSER_ACTION_CHANGED
)) {
2282 // Do nothing for other UEFI Action. Only do call back when data is changing or changed.
2284 return EFI_UNSUPPORTED
;
2287 Private
= HDD_PASSWORD_DXE_PRIVATE_FROM_THIS (This
);
2290 // Retrive data from Browser
2292 IfrData
= AllocateZeroPool (sizeof (HDD_PASSWORD_CONFIG
));
2293 ASSERT (IfrData
!= NULL
);
2294 if (!HiiGetBrowserData (&mHddPasswordVendorGuid
, mHddPasswordVendorStorageName
, sizeof (HDD_PASSWORD_CONFIG
), (UINT8
*) IfrData
)) {
2296 return EFI_NOT_FOUND
;
2299 switch (QuestionId
) {
2300 case KEY_HDD_USER_PASSWORD
:
2301 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
2302 DEBUG ((DEBUG_INFO
, "KEY_HDD_USER_PASSWORD\n"));
2303 ConfigFormEntry
= Private
->Current
;
2304 ConfigFormEntry
->IfrData
.Request
.UserPassword
= Value
->b
;
2305 SaveHddPasswordRequest (ConfigFormEntry
);
2306 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
2309 case KEY_HDD_MASTER_PASSWORD
:
2310 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
2311 DEBUG ((DEBUG_INFO
, "KEY_HDD_MASTER_PASSWORD\n"));
2312 ConfigFormEntry
= Private
->Current
;
2313 ConfigFormEntry
->IfrData
.Request
.MasterPassword
= Value
->b
;
2314 SaveHddPasswordRequest (ConfigFormEntry
);
2315 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
2320 if ((QuestionId
>= KEY_HDD_DEVICE_ENTRY_BASE
) && (QuestionId
< (mNumberOfHddDevices
+ KEY_HDD_DEVICE_ENTRY_BASE
))) {
2321 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
2323 // In case goto the device configuration form, update the device form title.
2325 ConfigFormEntry
= HddPasswordGetConfigFormEntryByIndex ((UINT32
) (QuestionId
- KEY_HDD_DEVICE_ENTRY_BASE
));
2326 ASSERT (ConfigFormEntry
!= NULL
);
2328 DeviceFormTitleToken
= (EFI_STRING_ID
) STR_HDD_SECURITY_HD
;
2329 HiiSetString (Private
->HiiHandle
, DeviceFormTitleToken
, ConfigFormEntry
->HddString
, NULL
);
2331 Private
->Current
= ConfigFormEntry
;
2332 CopyMem (IfrData
, &ConfigFormEntry
->IfrData
, sizeof (HDD_PASSWORD_CONFIG
));
2340 // Pass changed uncommitted data back to Form Browser
2342 HiiSetBrowserData (&mHddPasswordVendorGuid
, mHddPasswordVendorStorageName
, sizeof (HDD_PASSWORD_CONFIG
), (UINT8
*) IfrData
, NULL
);
2349 Updates the HDD Password configuration form to add an entry for the attached
2350 ata harddisk device specified by the Controller.
2352 @param[in] HiiHandle The HII Handle associated with the registered package list.
2353 @param[in] AtaPassThru Pointer to ATA_PASSTHRU instance.
2354 @param[in] PciIo Pointer to PCI_IO instance.
2355 @param[in] Controller The controller handle of the attached ata controller.
2356 @param[in] Bus The bus number of ATA controller.
2357 @param[in] Device The device number of ATA controller.
2358 @param[in] Function The function number of ATA controller.
2359 @param[in] Port The port number of attached ATA device.
2360 @param[in] PortMultiplierPort The port number of port multiplier of attached ATA device.
2362 @retval EFI_SUCCESS The Hdd Password configuration form is updated.
2363 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
2364 @retval Others Other errors as indicated.
2368 HddPasswordConfigUpdateForm (
2369 IN EFI_HII_HANDLE HiiHandle
,
2370 IN EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
,
2371 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
2372 IN EFI_HANDLE Controller
,
2377 IN UINT16 PortMultiplierPort
2381 HDD_PASSWORD_CONFIG_FORM_ENTRY
*ConfigFormEntry
;
2382 BOOLEAN EntryExisted
;
2384 VOID
*StartOpCodeHandle
;
2385 VOID
*EndOpCodeHandle
;
2386 EFI_IFR_GUID_LABEL
*StartLabel
;
2387 EFI_IFR_GUID_LABEL
*EndLabel
;
2388 CHAR16 HddString
[40];
2389 ATA_IDENTIFY_DATA IdentifyData
;
2390 EFI_DEVICE_PATH_PROTOCOL
*AtaDeviceNode
;
2392 ConfigFormEntry
= NULL
;
2393 EntryExisted
= FALSE
;
2395 EFI_LIST_FOR_EACH (Entry
, &mHddPasswordConfigFormList
) {
2396 ConfigFormEntry
= BASE_CR (Entry
, HDD_PASSWORD_CONFIG_FORM_ENTRY
, Link
);
2398 if ((ConfigFormEntry
->Bus
== Bus
) &&
2399 (ConfigFormEntry
->Device
== Device
) &&
2400 (ConfigFormEntry
->Function
== Function
) &&
2401 (ConfigFormEntry
->Port
== Port
) &&
2402 (ConfigFormEntry
->PortMultiplierPort
== PortMultiplierPort
)) {
2403 EntryExisted
= TRUE
;
2408 if (!EntryExisted
) {
2412 ConfigFormEntry
= AllocateZeroPool (sizeof (HDD_PASSWORD_CONFIG_FORM_ENTRY
));
2413 if (ConfigFormEntry
== NULL
) {
2414 return EFI_OUT_OF_RESOURCES
;
2417 InitializeListHead (&ConfigFormEntry
->Link
);
2418 ConfigFormEntry
->Controller
= Controller
;
2419 ConfigFormEntry
->Bus
= Bus
;
2420 ConfigFormEntry
->Device
= Device
;
2421 ConfigFormEntry
->Function
= Function
;
2422 ConfigFormEntry
->Port
= Port
;
2423 ConfigFormEntry
->PortMultiplierPort
= PortMultiplierPort
;
2424 ConfigFormEntry
->AtaPassThru
= AtaPassThru
;
2426 DEBUG ((DEBUG_INFO
, "HddPasswordDxe: Create new form for device[%d][%d] at Bus 0x%x Dev 0x%x Func 0x%x\n", Port
, PortMultiplierPort
, Bus
, Device
, Function
));
2429 // Construct the device path for the HDD password device
2431 Status
= AtaPassThru
->BuildDevicePath (
2437 if (EFI_ERROR (Status
)) {
2440 ConfigFormEntry
->DevicePath
= AppendDevicePathNode (DevicePathFromHandle (Controller
), AtaDeviceNode
);
2441 FreePool (AtaDeviceNode
);
2442 if (ConfigFormEntry
->DevicePath
== NULL
) {
2443 return EFI_OUT_OF_RESOURCES
;
2447 // Get attached harddisk model number
2449 Status
= GetHddDeviceIdentifyData (AtaPassThru
, Port
, PortMultiplierPort
, &IdentifyData
);
2450 ASSERT_EFI_ERROR (Status
);
2451 if (EFI_ERROR (Status
)) {
2454 GetHddDeviceModelNumber (&IdentifyData
, HddString
);
2456 // Compose the HDD title string and help string of this port and create a new EFI_STRING_ID.
2458 UnicodeSPrint (ConfigFormEntry
->HddString
, sizeof (ConfigFormEntry
->HddString
), L
"HDD %d:%s", mNumberOfHddDevices
, HddString
);
2459 ConfigFormEntry
->TitleToken
= HiiSetString (HiiHandle
, 0, ConfigFormEntry
->HddString
, NULL
);
2460 ConfigFormEntry
->TitleHelpToken
= HiiSetString (HiiHandle
, 0, L
"Request to set HDD Password", NULL
);
2462 GetHddPasswordSecurityStatus (&IdentifyData
, &ConfigFormEntry
->IfrData
);
2464 InsertTailList (&mHddPasswordConfigFormList
, &ConfigFormEntry
->Link
);
2467 // Init OpCode Handle
2469 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
2470 ASSERT (StartOpCodeHandle
!= NULL
);
2472 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
2473 ASSERT (EndOpCodeHandle
!= NULL
);
2476 // Create Hii Extend Label OpCode as the start opcode
2478 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
2479 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
2480 StartLabel
->Number
= HDD_DEVICE_ENTRY_LABEL
;
2483 // Create Hii Extend Label OpCode as the end opcode
2485 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
2486 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
2487 EndLabel
->Number
= HDD_DEVICE_LABEL_END
;
2489 mNumberOfHddDevices
= 0;
2490 EFI_LIST_FOR_EACH (Entry
, &mHddPasswordConfigFormList
) {
2491 ConfigFormEntry
= BASE_CR (Entry
, HDD_PASSWORD_CONFIG_FORM_ENTRY
, Link
);
2493 HiiCreateGotoOpCode (
2494 StartOpCodeHandle
, // Container for dynamic created opcodes
2495 FORMID_HDD_DEVICE_FORM
, // Target Form ID
2496 ConfigFormEntry
->TitleToken
, // Prompt text
2497 ConfigFormEntry
->TitleHelpToken
, // Help text
2498 EFI_IFR_FLAG_CALLBACK
, // Question flag
2499 (UINT16
) (KEY_HDD_DEVICE_ENTRY_BASE
+ mNumberOfHddDevices
) // Question ID
2502 mNumberOfHddDevices
++;
2507 &mHddPasswordVendorGuid
,
2508 FORMID_HDD_MAIN_FORM
,
2513 HiiFreeOpCodeHandle (StartOpCodeHandle
);
2514 HiiFreeOpCodeHandle (EndOpCodeHandle
);
2517 // Check if device is locked and prompt for password.
2519 HddPasswordRequestPassword (AtaPassThru
, Port
, PortMultiplierPort
, ConfigFormEntry
);
2522 // Process HDD password request from last boot.
2524 ProcessHddPasswordRequest (AtaPassThru
, Port
, PortMultiplierPort
, ConfigFormEntry
);
2531 Ata Pass Thru Protocol notification event handler.
2533 Check attached harddisk status to see if it's locked. If yes, then pop up a password windows to require user input.
2534 It also registers a form for user configuration on Hdd password configuration.
2536 @param[in] Event Event whose notification function is being invoked.
2537 @param[in] Context Pointer to the notification function's context.
2542 HddPasswordNotificationEvent (
2548 HDD_PASSWORD_DXE_PRIVATE_DATA
*Private
;
2549 EFI_ATA_PASS_THRU_PROTOCOL
*AtaPassThru
;
2551 UINT16 PortMultiplierPort
;
2552 EFI_HANDLE Controller
;
2553 EFI_HANDLE
*HandleBuffer
;
2556 EFI_PCI_IO_PROTOCOL
*PciIo
;
2562 if (mHddPasswordEndOfDxe
) {
2563 gBS
->CloseEvent (Event
);
2567 Private
= (HDD_PASSWORD_DXE_PRIVATE_DATA
*)Context
;
2570 // Locate all handles of AtaPassThru protocol
2572 Status
= gBS
->LocateHandleBuffer (
2574 &gEfiAtaPassThruProtocolGuid
,
2579 if (EFI_ERROR (Status
)) {
2584 // Check attached hard disk status to see if it's locked
2586 for (Index
= 0; Index
< HandleCount
; Index
+= 1) {
2587 Controller
= HandleBuffer
[Index
];
2588 Status
= gBS
->HandleProtocol (
2590 &gEfiAtaPassThruProtocolGuid
,
2591 (VOID
**) &AtaPassThru
2593 if (EFI_ERROR (Status
)) {
2598 // Ignore those logical ATA_PASS_THRU instance.
2600 if ((AtaPassThru
->Mode
->Attributes
& EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL
) == 0) {
2604 Status
= gBS
->HandleProtocol (
2606 &gEfiPciIoProtocolGuid
,
2609 ASSERT_EFI_ERROR (Status
);
2610 if (EFI_ERROR (Status
)) {
2614 Status
= PciIo
->GetLocation (
2621 ASSERT_EFI_ERROR (Status
);
2622 if (EFI_ERROR (Status
)) {
2627 // Assume and only support Segment == 0.
2629 ASSERT (SegNum
== 0);
2632 // traverse all attached harddisk devices to update form and unlock it
2637 Status
= AtaPassThru
->GetNextPort (AtaPassThru
, &Port
);
2638 if (EFI_ERROR (Status
)) {
2640 // We cannot find more legal port then we are done.
2645 PortMultiplierPort
= 0xFFFF;
2647 Status
= AtaPassThru
->GetNextDevice (AtaPassThru
, Port
, &PortMultiplierPort
);
2648 if (EFI_ERROR (Status
)) {
2650 // We cannot find more legal port multiplier port number for ATA device
2651 // on the port, then we are done.
2656 // Find out the attached harddisk devices.
2657 // Try to add a HDD Password configuration page for the attached devices.
2659 gBS
->RestoreTPL (TPL_APPLICATION
);
2660 Status
= HddPasswordConfigUpdateForm (Private
->HiiHandle
, AtaPassThru
, PciIo
, Controller
, BusNum
, DevNum
, FuncNum
, Port
, PortMultiplierPort
);
2661 gBS
->RaiseTPL (TPL_CALLBACK
);
2662 if (EFI_ERROR (Status
)) {
2669 FreePool (HandleBuffer
);
2674 Initialize the HDD Password configuration form.
2676 @param[out] Instance Pointer to private instance.
2678 @retval EFI_SUCCESS The HDD Password configuration form is initialized.
2679 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
2680 @retval Others Other errors as indicated.
2683 HddPasswordConfigFormInit (
2684 OUT HDD_PASSWORD_DXE_PRIVATE_DATA
**Instance
2688 HDD_PASSWORD_DXE_PRIVATE_DATA
*Private
;
2690 InitializeListHead (&mHddPasswordConfigFormList
);
2692 Private
= AllocateZeroPool (sizeof (HDD_PASSWORD_DXE_PRIVATE_DATA
));
2693 if (Private
== NULL
) {
2694 return EFI_OUT_OF_RESOURCES
;
2697 Private
->Signature
= HDD_PASSWORD_DXE_PRIVATE_SIGNATURE
;
2699 Private
->ConfigAccess
.ExtractConfig
= HddPasswordFormExtractConfig
;
2700 Private
->ConfigAccess
.RouteConfig
= HddPasswordFormRouteConfig
;
2701 Private
->ConfigAccess
.Callback
= HddPasswordFormCallback
;
2704 // Install Device Path Protocol and Config Access protocol to driver handle
2706 Status
= gBS
->InstallMultipleProtocolInterfaces (
2707 &Private
->DriverHandle
,
2708 &gEfiDevicePathProtocolGuid
,
2709 &mHddPasswordHiiVendorDevicePath
,
2710 &gEfiHiiConfigAccessProtocolGuid
,
2711 &Private
->ConfigAccess
,
2714 ASSERT_EFI_ERROR (Status
);
2715 if (EFI_ERROR (Status
)) {
2721 // Publish our HII data
2723 Private
->HiiHandle
= HiiAddPackages (
2724 &mHddPasswordVendorGuid
,
2725 Private
->DriverHandle
,
2726 HddPasswordDxeStrings
,
2730 if (Private
->HiiHandle
== NULL
) {
2732 return EFI_OUT_OF_RESOURCES
;
2735 *Instance
= Private
;
2740 Main entry for this driver.
2742 @param ImageHandle Image handle this driver.
2743 @param SystemTable Pointer to SystemTable.
2745 @retval EFI_SUCESS This function always complete successfully.
2750 HddPasswordDxeInit (
2751 IN EFI_HANDLE ImageHandle
,
2752 IN EFI_SYSTEM_TABLE
*SystemTable
2756 HDD_PASSWORD_DXE_PRIVATE_DATA
*Private
;
2757 EFI_EVENT Registration
;
2758 EFI_EVENT EndOfDxeEvent
;
2759 EDKII_VARIABLE_LOCK_PROTOCOL
*VariableLock
;
2764 // Initialize the configuration form of HDD Password.
2766 Status
= HddPasswordConfigFormInit (&Private
);
2767 if (EFI_ERROR (Status
)) {
2772 // Register HddPasswordNotificationEvent() notify function.
2774 EfiCreateProtocolNotifyEvent (
2775 &gEfiAtaPassThruProtocolGuid
,
2777 HddPasswordNotificationEvent
,
2782 Status
= gBS
->CreateEventEx (
2785 HddPasswordEndOfDxeEventNotify
,
2787 &gEfiEndOfDxeEventGroupGuid
,
2790 ASSERT_EFI_ERROR (Status
);
2793 // Make HDD_PASSWORD_VARIABLE_NAME varible read-only.
2795 Status
= gBS
->LocateProtocol (&gEdkiiVariableLockProtocolGuid
, NULL
, (VOID
**) &VariableLock
);
2796 if (!EFI_ERROR (Status
)) {
2797 Status
= VariableLock
->RequestToLock (
2799 HDD_PASSWORD_VARIABLE_NAME
,
2800 &mHddPasswordVendorGuid
2802 DEBUG ((DEBUG_INFO
, "%a(): Lock %s variable (%r)\n", __FUNCTION__
, HDD_PASSWORD_VARIABLE_NAME
, Status
));
2803 ASSERT_EFI_ERROR (Status
);