Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Redfish http protocol and library #57

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 56 additions & 24 deletions RedfishClientPkg/Features/Bios/v1_0_9/Common/BiosCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,22 @@ ProvisioningBiosResource (
IN EFI_STRING ConfigureLang
)
{
CHAR8 *Json;
CHAR8 *JsonWithAddendum;
EFI_STATUS Status;
EFI_STRING NewResourceLocation;
CHAR8 *EtagStr;
CHAR8 ResourceId[16];
CHAR8 *Json;
CHAR8 *JsonWithAddendum;
EFI_STATUS Status;
EFI_STRING NewResourceLocation;
CHAR8 *EtagStr;
CHAR8 ResourceId[16];
REDFISH_RESPONSE Response;

if (IS_EMPTY_STRING (ConfigureLang) || (Private == NULL)) {
return EFI_INVALID_PARAMETER;
}

EtagStr = NULL;
EtagStr = NULL;
Json = NULL;
NewResourceLocation = NULL;
ZeroMem (&Response, sizeof (REDFISH_RESPONSE));
AsciiSPrint (ResourceId, sizeof (ResourceId), "%d", Index);

Status = ProvisioningBiosProperties (
Expand Down Expand Up @@ -326,19 +330,25 @@ ProvisioningBiosResource (
JsonWithAddendum = NULL;
}

Status = CreatePayloadToPostResource (Private->RedfishService, Private->Payload, Json, &NewResourceLocation, &EtagStr);
Status = RedfishHttpPostResource (Private->RedfishService, Private->Uri, Json, &Response);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, post Bios resource for %s failed: %r\n", __func__, ConfigureLang, Status));
goto RELEASE_RESOURCE;
}

Status = GetEtagAndLocation (&Response, &EtagStr, &NewResourceLocation);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, get ETag and location failed: %r\n", __func__, Status));
goto RELEASE_RESOURCE;
}

ASSERT (NewResourceLocation != NULL);

//
// Keep location of new resource.
//
if (NewResourceLocation != NULL) {
RedfisSetRedfishUri (ConfigureLang, NewResourceLocation);
RedfishSetRedfishUri (ConfigureLang, NewResourceLocation);
}

//
Expand All @@ -359,6 +369,8 @@ ProvisioningBiosResource (
FreePool (Json);
}

RedfishHttpFreeResource (&Response);

return Status;
}

Expand Down Expand Up @@ -401,11 +413,12 @@ ProvisioningBiosExistResource (
IN REDFISH_RESOURCE_COMMON_PRIVATE *Private
)
{
EFI_STATUS Status;
EFI_STRING ConfigureLang;
CHAR8 *EtagStr;
CHAR8 *Json;
CHAR8 *JsonWithAddendum;
EFI_STATUS Status;
EFI_STRING ConfigureLang;
CHAR8 *EtagStr;
CHAR8 *Json;
CHAR8 *JsonWithAddendum;
REDFISH_RESPONSE Response;

if (Private == NULL) {
return EFI_INVALID_PARAMETER;
Expand All @@ -414,6 +427,7 @@ ProvisioningBiosExistResource (
EtagStr = NULL;
Json = NULL;
ConfigureLang = NULL;
ZeroMem (&Response, sizeof (REDFISH_RESPONSE));

ConfigureLang = RedfishGetConfigLanguage (Private->Uri);
if (ConfigureLang == NULL) {
Expand Down Expand Up @@ -472,13 +486,19 @@ ProvisioningBiosExistResource (

DEBUG ((REDFISH_DEBUG_TRACE, "%a, provisioning existing resource for %s\n", __func__, ConfigureLang));
//
// PUT back to instance
// PATCH back to instance
//
Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr);
Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status));
}

Status = GetEtagAndLocation (&Response, &EtagStr, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, get ETag failed: %r\n", __func__, Status));
goto ON_RELEASE;
}

//
// Handle Etag
//
Expand All @@ -497,6 +517,8 @@ ProvisioningBiosExistResource (
FreePool (ConfigureLang);
}

RedfishHttpFreeResource (&Response);

return Status;
}

Expand Down Expand Up @@ -595,11 +617,12 @@ RedfishUpdateResourceCommon (
IN CHAR8 *InputJson
)
{
EFI_STATUS Status;
CHAR8 *Json;
CHAR8 *JsonWithAddendum;
EFI_STRING ConfigureLang;
CHAR8 *EtagStr;
EFI_STATUS Status;
CHAR8 *Json;
CHAR8 *JsonWithAddendum;
EFI_STRING ConfigureLang;
CHAR8 *EtagStr;
REDFISH_RESPONSE Response;

if ((Private == NULL) || IS_EMPTY_STRING (InputJson)) {
return EFI_INVALID_PARAMETER;
Expand All @@ -608,6 +631,7 @@ RedfishUpdateResourceCommon (
EtagStr = NULL;
Json = NULL;
ConfigureLang = NULL;
ZeroMem (&Response, sizeof (REDFISH_RESPONSE));

ConfigureLang = RedfishGetConfigLanguage (Private->Uri);
if (ConfigureLang == NULL) {
Expand Down Expand Up @@ -666,13 +690,19 @@ RedfishUpdateResourceCommon (

DEBUG ((REDFISH_DEBUG_TRACE, "%a, update resource for %s\n", __func__, ConfigureLang));
//
// PUT back to instance
// PATCH back to instance
//
Status = CreatePayloadToPatchResource (Private->RedfishService, Private->Payload, Json, &EtagStr);
Status = RedfishHttpPatchResource (Private->RedfishService, Private->Uri, Json, &Response);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, patch resource for %s failed: %r\n", __func__, ConfigureLang, Status));
}

Status = GetEtagAndLocation (&Response, &EtagStr, NULL);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, get ETag failed: %r\n", __func__, Status));
goto ON_RELEASE;
}

//
// Handle Etag
//
Expand All @@ -691,6 +721,8 @@ RedfishUpdateResourceCommon (
FreePool (ConfigureLang);
}

RedfishHttpFreeResource (&Response);

return Status;
}

Expand Down Expand Up @@ -745,7 +777,7 @@ RedfishIdentifyResourceCommon (
//
// Keep URI and ConfigLang mapping
//
RedfisSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Uri);
RedfishSetRedfishUri (ConfigLangList.List[0].ConfigureLang, Private->Uri);
//
// Set the configuration language in the RESOURCE_INFORMATION_EXCHANGE.
// This information is sent back to the parent resource (e.g. the collection driver).
Expand Down
59 changes: 17 additions & 42 deletions RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ RedfishResourceProvisioningResource (
return EFI_NOT_READY;
}

Status = GetResourceByUri (Private->RedfishService, Uri, &Response);
ZeroMem (&Response, sizeof (Response));
Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
return Status;
Expand All @@ -72,12 +73,7 @@ RedfishResourceProvisioningResource (
// Release resource
//
if (Private->Payload != NULL) {
RedfishFreeResponse (
Response.StatusCode,
Response.HeaderCount,
Response.Headers,
Response.Payload
);
RedfishHttpFreeResource (&Response);
Private->Payload = NULL;
}

Expand Down Expand Up @@ -122,7 +118,8 @@ RedfishResourceConsumeResource (
return EFI_NOT_READY;
}

Status = GetResourceByUri (Private->RedfishService, Uri, &Response);
ZeroMem (&Response, sizeof (Response));
Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
return Status;
Expand Down Expand Up @@ -151,7 +148,7 @@ RedfishResourceConsumeResource (
//
RedfishSettingsUri = JsonValueGetUnicodeString (JsonValue);

Status = GetResourceByUri (Private->RedfishService, RedfishSettingsUri, &RedfishSettingsResponse);
Status = RedfishHttpGetResource (Private->RedfishService, RedfishSettingsUri, &RedfishSettingsResponse, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, @Redfish.Settings exists, get resource from: %s failed\n", __FUNCTION__, RedfishSettingsUri));
} else {
Expand Down Expand Up @@ -195,21 +192,11 @@ RedfishResourceConsumeResource (
//
if (Private->Payload != NULL) {
if (Response.Payload != NULL) {
RedfishFreeResponse (
Response.StatusCode,
Response.HeaderCount,
Response.Headers,
Response.Payload
);
RedfishHttpFreeResource (&Response);
}

if (RedfishSettingsResponse.Payload != NULL) {
RedfishFreeResponse (
RedfishSettingsResponse.StatusCode,
RedfishSettingsResponse.HeaderCount,
RedfishSettingsResponse.Headers,
RedfishSettingsResponse.Payload
);
RedfishHttpFreeResource (&RedfishSettingsResponse);
}

Private->Payload = NULL;
Expand Down Expand Up @@ -290,7 +277,8 @@ RedfishResourceUpdate (
return EFI_NOT_READY;
}

Status = GetResourceByUri (Private->RedfishService, Uri, &Response);
ZeroMem (&Response, sizeof (Response));
Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
return Status;
Expand All @@ -312,12 +300,7 @@ RedfishResourceUpdate (
// Release resource
//
if (Private->Payload != NULL) {
RedfishFreeResponse (
Response.StatusCode,
Response.HeaderCount,
Response.Headers,
Response.Payload
);
RedfishHttpFreeResource (&Response);
Private->Payload = NULL;
}

Expand Down Expand Up @@ -360,7 +343,8 @@ RedfishResourceCheck (
return EFI_NOT_READY;
}

Status = GetResourceByUri (Private->RedfishService, Uri, &Response);
ZeroMem (&Response, sizeof (Response));
Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
return Status;
Expand All @@ -382,12 +366,7 @@ RedfishResourceCheck (
// Release resource
//
if (Private->Payload != NULL) {
RedfishFreeResponse (
Response.StatusCode,
Response.HeaderCount,
Response.Headers,
Response.Payload
);
RedfishHttpFreeResource (&Response);
Private->Payload = NULL;
}

Expand Down Expand Up @@ -431,7 +410,8 @@ RedfishResourceIdentify (
return EFI_NOT_READY;
}

Status = GetResourceByUri (Private->RedfishService, Uri, &Response);
ZeroMem (&Response, sizeof (Response));
Status = RedfishHttpGetResource (Private->RedfishService, Uri, &Response, TRUE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __func__, Uri));
return Status;
Expand All @@ -453,12 +433,7 @@ RedfishResourceIdentify (
// Release resource
//
if (Private->Payload != NULL) {
RedfishFreeResponse (
Response.StatusCode,
Response.HeaderCount,
Response.Headers,
Response.Payload
);
RedfishHttpFreeResource (&Response);
Private->Payload = NULL;
}

Expand Down
1 change: 1 addition & 0 deletions RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.inf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
UefiLib
UefiDriverEntryPoint
RedfishAddendumLib
RedfishHttpLib

[Protocols]
gEdkIIRedfishConfigHandlerProtocolGuid ## PRODUCED
Expand Down
Loading
Loading