TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishMisc.c
Go to the documentation of this file.
1
12#include "RedfishMisc.h"
13
14EDKII_REDFISH_CREDENTIAL_PROTOCOL *mCredentialProtocol = NULL;
15
27 IN REDFISH_SERVICE RedfishService,
28 OUT CHAR8 **ServiceVersionStr
29 )
30{
31 redfishService *Redfish;
32 CHAR8 **KeysArray;
33 UINTN KeysNum;
34
35 if ((RedfishService == NULL) || (ServiceVersionStr == NULL)) {
36 return EFI_INVALID_PARAMETER;
37 }
38
39 Redfish = (redfishService *)RedfishService;
40 if (Redfish->versions == NULL) {
41 return EFI_INVALID_PARAMETER;
42 }
43
44 KeysArray = JsonObjectGetKeys (Redfish->versions, &KeysNum);
45 if ((KeysNum == 0) || (KeysArray == NULL)) {
46 return EFI_NOT_FOUND;
47 }
48
49 *ServiceVersionStr = *KeysArray;
50 return EFI_SUCCESS;
51}
52
70REDFISH_SERVICE
72 IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo,
74 IN CHAR8 *UserId,
75 IN CHAR8 *Password
76 )
77{
78 UINTN Flags;
80 redfishService *Redfish;
81
82 Redfish = NULL;
83
84 ZeroMem (&Auth, sizeof (Auth));
85 if (AuthMethod == AuthMethodHttpBasic) {
86 Auth.authType = REDFISH_AUTH_BASIC;
87 } else if (AuthMethod == AuthMethodRedfishSession) {
88 Auth.authType = REDFISH_AUTH_SESSION;
89 }
90
91 Auth.authCodes.userPass.username = UserId;
92 Auth.authCodes.userPass.password = Password;
93
94 Flags = REDFISH_FLAG_SERVICE_NO_VERSION_DOC;
95
96 if (AuthMethod != AuthMethodNone) {
97 Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, &Auth, (unsigned int)Flags);
98 } else {
99 Redfish = createServiceEnumerator (RedfishConfigServiceInfo, NULL, NULL, (unsigned int)Flags);
100 }
101
102 //
103 // Zero the Password after use.
104 //
105 if (Password != NULL) {
106 ZeroMem (Password, AsciiStrLen (Password));
107 }
108
109 return (REDFISH_SERVICE)Redfish;
110}
111
137 OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod,
138 OUT CHAR8 **UserId,
139 OUT CHAR8 **Password
140 )
141{
142 EFI_STATUS Status;
143
144 if ((AuthMethod == NULL) || (UserId == NULL) || (Password == NULL)) {
145 return EFI_INVALID_PARAMETER;
146 }
147
148 //
149 // Locate Redfish Credential Protocol.
150 //
151 if (mCredentialProtocol == NULL) {
152 Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **)&mCredentialProtocol);
153 if (EFI_ERROR (Status)) {
154 return EFI_UNSUPPORTED;
155 }
156 }
157
158 ASSERT (mCredentialProtocol != NULL);
159
160 Status = mCredentialProtocol->GetAuthInfo (mCredentialProtocol, AuthMethod, UserId, Password);
161 if (EFI_ERROR (Status)) {
162 DEBUG ((DEBUG_ERROR, "RedfishGetAuthInfo: failed to retrieve Redfish credential - %r\n", Status));
163 return Status;
164 }
165
166 return Status;
167}
168
183 IN CHAR8 *ServiceVersionStr,
184 IN CHAR8 *Url,
185 IN CHAR8 *Id,
186 OUT CHAR8 **Redpath
187 )
188{
189 UINTN RedpathSize;
190
191 if ((Redpath == NULL) || (ServiceVersionStr == NULL) || (Url == NULL) || (Id == NULL)) {
192 return EFI_INVALID_PARAMETER;
193 }
194
195 RedpathSize = AsciiStrLen ("/") +
196 AsciiStrLen (ServiceVersionStr) +
197 AsciiStrLen (Url) +
198 AsciiStrLen ("[Id=]") +
199 AsciiStrLen (Id) + 1;
200 *Redpath = AllocatePool (RedpathSize);
201 if (*Redpath == NULL) {
202 return EFI_OUT_OF_RESOURCES;
203 }
204
205 AsciiSPrint (*Redpath, RedpathSize, "/%a%a[Id=%a]", ServiceVersionStr, Url, Id);
206 return EFI_SUCCESS;
207}
UINT64 UINTN
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EDKII_REDFISH_AUTH_METHOD
@ AuthMethodHttpBasic
Basic authentication is required.
@ AuthMethodNone
No authentication is required.
@ AuthMethodRedfishSession
Session authentication is required.
CHAR8 ** JsonObjectGetKeys(IN EDKII_JSON_OBJECT JsonObj, OUT UINTN *KeyCount)
Definition: JsonLib.c:714
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS RedfishBuildRedpathUseId(IN CHAR8 *ServiceVersionStr, IN CHAR8 *Url, IN CHAR8 *Id, OUT CHAR8 **Redpath)
Definition: RedfishMisc.c:182
EFI_STATUS RedfishGetAuthInfo(OUT EDKII_REDFISH_AUTH_METHOD *AuthMethod, OUT CHAR8 **UserId, OUT CHAR8 **Password)
Definition: RedfishMisc.c:136
REDFISH_SERVICE RedfishCreateLibredfishService(IN REDFISH_CONFIG_SERVICE_INFORMATION *RedfishConfigServiceInfo, IN EDKII_REDFISH_AUTH_METHOD AuthMethod, IN CHAR8 *UserId, IN CHAR8 *Password)
Definition: RedfishMisc.c:71
EFI_STATUS RedfishGetServiceVersion(IN REDFISH_SERVICE RedfishService, OUT CHAR8 **ServiceVersionStr)
Definition: RedfishMisc.c:26
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS