14#define REDFISH_VERSION_DEFAULT_STRING L"v1"
52 gBS->CloseEvent (Event);
61 IN REDFISH_SERVICE RedfishService
97 if ((This ==
NULL) || (AuthMethod ==
NULL) || (UserId ==
NULL) || (Password ==
NULL)) {
98 return EFI_INVALID_PARAMETER;
129 return EFI_INVALID_PARAMETER;
170 if ((AuthMethod ==
NULL) || (UserId ==
NULL) || (Password ==
NULL)) {
171 return EFI_INVALID_PARAMETER;
174 if (mCredentialPrivate ==
NULL) {
175 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
176 return EFI_NOT_STARTED;
179 Status = mCredentialPrivate->RedfishCredentialProtocol.GetAuthInfo (
180 &mCredentialPrivate->RedfishCredentialProtocol,
185 if (EFI_ERROR (Status)) {
186 DEBUG ((DEBUG_ERROR,
"%a: Failed to retrieve Redfish credential - %r\n", __func__, Status));
221 if (mCredentialPrivate ==
NULL) {
222 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
223 return EFI_NOT_STARTED;
232 if (!
IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
241 Status = mCredentialPrivate->RedfishCredentialProtocol.StopService (
242 &mCredentialPrivate->RedfishCredentialProtocol,
245 if (EFI_ERROR (Status)) {
246 DEBUG ((DEBUG_ERROR,
"%a: Failed to stop service - %r\n", __func__, Status));
263 IN REDFISH_SERVICE RedfishService,
270 if (mCredentialPrivate ==
NULL) {
271 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
272 return EFI_NOT_STARTED;
276 DEBUG ((DEBUG_ERROR,
"%a: Redfish service is not available\n", __func__));
277 return EFI_INVALID_PARAMETER;
292 if (EFI_ERROR (Status)) {
293 DEBUG ((DEBUG_ERROR,
"%a: can not remove bootstrap account at BMC: %r", __func__, Status));
297 (REDFISH_CREDENTIAL_DEBUG,
"%a: bootstrap account: %a is removed from: %s\nURI - %s",
298 __func__, mCredentialPrivate->AccountName, REDFISH_MANAGER_ACCOUNT_COLLECTION_URI, TargetUri)
319 IN REDFISH_SERVICE RedfishService,
320 IN EFI_STRING AccountUri
323 EDKII_JSON_VALUE JsonUserName;
324 EDKII_JSON_VALUE JsonValue;
330 if (mCredentialPrivate ==
NULL) {
331 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
335 if ((RedfishService ==
NULL) || IS_EMPTY_STRING (AccountUri) ||
344 if (EFI_ERROR (Status) || (RedfishResponse.Payload ==
NULL)) {
345 DEBUG ((DEBUG_ERROR,
"%a: can not get account from BMC: %r", __func__, Status));
378 OUT CHAR16 **ServiceVersionStr
381 *ServiceVersionStr = (CHAR16 *)
PcdGetPtr (PcdDefaultRedfishVersion);
382 if (*ServiceVersionStr ==
NULL) {
383 *ServiceVersionStr = REDFISH_VERSION_DEFAULT_STRING;
401 IN REDFISH_SERVICE RedfishService
405 EDKII_JSON_VALUE JsonMembers;
406 EDKII_JSON_VALUE JsonValue;
407 EDKII_JSON_VALUE OdataId;
408 CHAR16 TargetUri[REDFISH_URI_LENGTH];
409 CHAR16 *RedfishVersion;
412 UINTN MembersCount, Index;
414 RedfishVersion =
NULL;
415 Status = EFI_NOT_FOUND;
417 if (mCredentialPrivate ==
NULL) {
418 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
419 return EFI_NOT_STARTED;
423 IS_EMPTY_STRING (mCredentialPrivate->AccountName))
425 return EFI_INVALID_PARAMETER;
433 if (EFI_ERROR (Status)) {
434 DEBUG ((DEBUG_ERROR,
"%a: can not get Redfish version\n", __func__));
440 (
sizeof (CHAR16) * REDFISH_URI_LENGTH),
443 REDFISH_MANAGER_ACCOUNT_COLLECTION_URI
446 DEBUG ((REDFISH_CREDENTIAL_DEBUG,
"%a: account collection URI: %s\n", __func__, TargetUri));
451 if (EFI_ERROR (Status) || (RedfishResponse.Payload ==
NULL)) {
452 DEBUG ((DEBUG_ERROR,
"%a: can not get accounts from BMC: %r\n", __func__, Status));
459 Status = EFI_LOAD_ERROR;
465 Status = EFI_LOAD_ERROR;
469 Status = EFI_NOT_FOUND;
472 for (Index = 0; Index < MembersCount; Index++) {
475 Status = EFI_LOAD_ERROR;
481 Status = EFI_LOAD_ERROR;
487 (
sizeof (CHAR16) * REDFISH_URI_LENGTH),
491 DEBUG ((REDFISH_CREDENTIAL_DEBUG,
"%a: account URI: %s\n", __func__, TargetUri));
533 if ((AuthMethod ==
NULL) || (UserId ==
NULL)) {
534 return EFI_INVALID_PARAMETER;
537 if (mCredentialPrivate ==
NULL) {
538 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
539 return EFI_NOT_STARTED;
542 Status = mCredentialPrivate->RedfishCredentialProtocol.GetAuthInfo (
543 &mCredentialPrivate->RedfishCredentialProtocol,
548 if (EFI_ERROR (Status)) {
549 DEBUG ((DEBUG_ERROR,
"%a: failed to retrieve Redfish credential - %r\n", __func__, Status));
553 if (Password !=
NULL) {
576 if (mCredentialPrivate ==
NULL) {
577 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
578 return EFI_NOT_STARTED;
581 if (!
IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
588 if (!
IsNodeAtEnd (&mCredentialPrivate->RedfishServiceList, &Instance->NextInstance)) {
590 &mCredentialPrivate->RedfishServiceList,
591 &Instance->NextInstance
597 Instance = NextInstance;
598 }
while (Instance !=
NULL);
614 IN REDFISH_SERVICE RedfishService
617 BOOLEAN ServiceFound;
620 RedfishServiceInstance =
NULL;
621 ServiceFound =
FALSE;
623 if (mCredentialPrivate ==
NULL) {
624 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
625 return EFI_NOT_STARTED;
628 if (!
IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
631 if (RedfishServiceInstance->RedfishService == RedfishService) {
636 if (
IsNodeAtEnd (&mCredentialPrivate->RedfishServiceList, &RedfishServiceInstance->NextInstance)) {
641 &mCredentialPrivate->RedfishServiceList,
642 &RedfishServiceInstance->NextInstance
649 if (RedfishServiceInstance ==
NULL) {
650 return EFI_OUT_OF_RESOURCES;
653 RedfishServiceInstance->RedfishService = RedfishService;
654 InsertTailList (&mCredentialPrivate->RedfishServiceList, &RedfishServiceInstance->NextInstance);
671 IN REDFISH_SERVICE RedfishService
676 if (mCredentialPrivate ==
NULL) {
677 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
678 return EFI_NOT_STARTED;
681 if (!
IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
684 if (RedfishServiceInstance->RedfishService == RedfishService) {
690 if (
IsNodeAtEnd (&mCredentialPrivate->RedfishServiceList, &RedfishServiceInstance->NextInstance)) {
698 return EFI_NOT_FOUND;
715 IN REDFISH_SERVICE RedfishService
722 if (mCredentialPrivate ==
NULL) {
723 DEBUG ((DEBUG_ERROR,
"%a: failed with error - %r\n", __func__, EFI_NOT_STARTED));
724 return EFI_NOT_STARTED;
728 if (mCredentialPrivate->AuthMethod == AuthMethodMax) {
730 &mCredentialPrivate->AuthMethod,
731 &mCredentialPrivate->AccountName
738 if (EFI_ERROR (Status)) {
739 DEBUG ((DEBUG_ERROR,
"%a: Failed to register Redfish service - %r\n", __func__, Status));
761 IN REDFISH_SERVICE RedfishService
774 if (
IsListEmpty (&mCredentialPrivate->RedfishServiceList)) {
777 if (!EFI_ERROR (Status)) {
778 if (mCredentialPrivate->AccountName !=
NULL) {
780 FreePool (mCredentialPrivate->AccountName);
781 mCredentialPrivate->AccountName =
NULL;
784 mCredentialPrivate->AuthMethod = AuthMethodMax;
785 Status = mCredentialPrivate->RedfishCredentialProtocol.StopService (
786 &mCredentialPrivate->RedfishCredentialProtocol,
789 if (EFI_ERROR (Status)) {
790 DEBUG ((DEBUG_ERROR,
"%a: Failed to stop service - %r\n", __func__, Status));
817 if (mCredentialPrivate ==
NULL) {
818 return EFI_OUT_OF_RESOURCES;
821 mCredentialPrivate->AuthMethod = AuthMethodMax;
827 mCredentialPrivate->RedfishCredential2Protocol.Revision = REDFISH_CREDENTIAL_PROTOCOL_REVISION;
836 Status =
gBS->InstallMultipleProtocolInterfaces (
837 &mCredentialPrivate->Handle,
838 &gEdkIIRedfishCredentialProtocolGuid,
839 &mCredentialPrivate->RedfishCredentialProtocol,
840 &gEdkIIRedfishCredential2ProtocolGuid,
841 &mCredentialPrivate->RedfishCredential2Protocol,
844 if (EFI_ERROR (Status)) {
854 Status =
gBS->CreateEventEx (
858 (VOID *)&mCredentialPrivate->RedfishCredentialProtocol,
859 &gEfiEndOfDxeEventGroupGuid,
860 &mCredentialPrivate->EndOfDxeEvent
862 if (EFI_ERROR (Status)) {
870 Status =
gBS->CreateEventEx (
874 (VOID *)&mCredentialPrivate->RedfishCredentialProtocol,
875 &gEfiEventExitBootServicesGuid,
876 &mCredentialPrivate->ExitBootServiceEvent
878 if (EFI_ERROR (Status)) {
879 gBS->CloseEvent (mCredentialPrivate->EndOfDxeEvent);
880 mCredentialPrivate->EndOfDxeEvent =
NULL;
888 gBS->UninstallMultipleProtocolInterfaces (
889 mCredentialPrivate->Handle,
890 &gEdkIIRedfishCredentialProtocolGuid,
891 &mCredentialPrivate->RedfishCredentialProtocol,
892 &gEdkIIRedfishCredential2ProtocolGuid,
893 &mCredentialPrivate->RedfishCredential2Protocol,
914 if (mCredentialPrivate !=
NULL) {
915 if (mCredentialPrivate->AccountName !=
NULL) {
917 FreePool (mCredentialPrivate->AccountName);
918 mCredentialPrivate->AccountName =
NULL;
945 if (mCredentialPrivate !=
NULL) {
946 gBS->UninstallMultipleProtocolInterfaces (
947 mCredentialPrivate->Handle,
948 &gEdkIIRedfishCredentialProtocolGuid,
949 &mCredentialPrivate->RedfishCredentialProtocol,
950 &gEdkIIRedfishCredential2ProtocolGuid,
951 &mCredentialPrivate->RedfishCredential2Protocol,
955 if (mCredentialPrivate->EndOfDxeEvent !=
NULL) {
956 gBS->CloseEvent (mCredentialPrivate->EndOfDxeEvent);
957 mCredentialPrivate->EndOfDxeEvent =
NULL;
960 if (mCredentialPrivate->ExitBootServiceEvent !=
NULL) {
961 gBS->CloseEvent (mCredentialPrivate->ExitBootServiceEvent);
962 mCredentialPrivate->ExitBootServiceEvent =
NULL;
968 mCredentialPrivate =
NULL;
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
BOOLEAN EFIAPI IsNodeAtEnd(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE
@ ServiceStopTypeExitBootService
@ ServiceStopTypeNone
Stop Redfsih service without reason.
EDKII_REDFISH_AUTH_METHOD
@ AuthMethodHttpBasic
Basic authentication is required.
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
BOOLEAN EFIAPI JsonValueIsString(IN EDKII_JSON_VALUE Json)
EDKII_JSON_ARRAY EFIAPI JsonValueGetArray(IN EDKII_JSON_VALUE Json)
EDKII_JSON_OBJECT EFIAPI JsonValueGetObject(IN EDKII_JSON_VALUE Json)
EDKII_JSON_VALUE EFIAPI JsonArrayGetValue(IN EDKII_JSON_ARRAY JsonArray, IN UINTN Index)
CONST CHAR8 *EFIAPI JsonValueGetAsciiString(IN EDKII_JSON_VALUE Json)
BOOLEAN EFIAPI JsonValueIsArray(IN EDKII_JSON_VALUE Json)
EDKII_JSON_VALUE EFIAPI JsonObjectGetValue(IN CONST EDKII_JSON_OBJECT JsonObj, IN CONST CHAR8 *Key)
UINTN EFIAPI JsonArrayCount(IN EDKII_JSON_ARRAY JsonArray)
BOOLEAN EFIAPI JsonValueIsObject(IN EDKII_JSON_VALUE Json)
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
#define DEBUG(Expression)
#define FixedPcdGetBool(TokenName)
#define PcdGetPtr(TokenName)
EFI_STATUS ReleaseCredentialPrivate()
EFI_STATUS EFIAPI RedfishCredential2StopService(IN EDKII_REDFISH_CREDENTIAL2_PROTOCOL *This, IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType)
EFI_STATUS EFIAPI RedfishCredential2GetAuthInfo(IN EDKII_REDFISH_CREDENTIAL2_PROTOCOL *This, OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod, OUT CHAR8 **UserId, OUT CHAR8 **Password)
EFI_STATUS EFIAPI RedfishCredential2RegisterService(IN EDKII_REDFISH_CREDENTIAL2_PROTOCOL *This, IN REDFISH_SERVICE RedfishService)
EFI_STATUS DeleteRedfishServiceFromList(IN REDFISH_SERVICE RedfishService)
EFI_STATUS EFIAPI DeleteRedfishBootstrapAccount(IN REDFISH_SERVICE RedfishService, IN CHAR16 *TargetUri)
EFI_STATUS ClearRedfishServiceList(VOID)
EFI_STATUS EFIAPI RedfishCredentialDxeDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS RedfishGetServiceVersion(OUT CHAR16 **ServiceVersionStr)
EFI_STATUS RedfishGetAuthConfig(OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod, OUT CHAR8 **UserId)
EFI_STATUS EFIAPI RedfishCredentialStopService(IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This, IN EDKII_REDFISH_CREDENTIAL_STOP_SERVICE_TYPE ServiceStopType)
EFI_STATUS EFIAPI RedfishCredential2UnregisterService(IN EDKII_REDFISH_CREDENTIAL2_PROTOCOL *This, IN REDFISH_SERVICE RedfishService)
VOID EFIAPI RedfishCredentialEndOfDxeEventNotify(IN EFI_EVENT Event, OUT VOID *Context)
EFI_STATUS IterateThroughBootstrapAccounts(IN REDFISH_SERVICE RedfishService)
VOID EFIAPI RedfishCredentialExitBootServicesEventNotify(IN EFI_EVENT Event, OUT VOID *Context)
EFI_STATUS EFIAPI RedfishCredentialDxeDriverUnload(IN EFI_HANDLE ImageHandle)
EFI_STATUS EFIAPI RedfishCredentialGetAuthInfo(IN EDKII_REDFISH_CREDENTIAL_PROTOCOL *This, OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod, OUT CHAR8 **UserId, OUT CHAR8 **Password)
EFI_STATUS AddRedfishServiceToList(IN REDFISH_SERVICE RedfishService)
BOOLEAN ProcessRedfishBootstarpAccount(IN REDFISH_SERVICE RedfishService, IN EFI_STRING AccountUri)
EFI_STATUS DumpRedfishResponse(IN CONST CHAR8 *Message, IN UINTN ErrorLevel, IN REDFISH_RESPONSE *Response)
EFI_STATUS RedfishHttpGetResource(IN REDFISH_SERVICE Service, IN EFI_STRING Uri, IN REDFISH_REQUEST *Request OPTIONAL, OUT REDFISH_RESPONSE *Response, IN BOOLEAN UseCache)
EFI_STATUS RedfishHttpDeleteResourceEx(IN REDFISH_SERVICE Service, IN EFI_STRING Uri, IN CHAR8 *Content OPTIONAL, IN UINTN ContentSize OPTIONAL, IN CHAR8 *ContentType OPTIONAL, OUT REDFISH_RESPONSE *Response)
EFI_STATUS RedfishHttpFreeResponse(IN REDFISH_RESPONSE *Response)
EFI_STATUS RedfishHttpFreeRequest(IN REDFISH_REQUEST *Request)
EDKII_JSON_VALUE RedfishJsonInPayload(IN REDFISH_PAYLOAD RedfishPayload)