TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishRestExImpl.c
Go to the documentation of this file.
1
12#include <Uefi.h>
14
26 IN RESTEX_INSTANCE *Instance
27 )
28{
29 EFI_STATUS Status;
30
31 DEBUG ((DEBUG_MANAGEABILITY, "%a: TCP connection is finished. Could be TSL session closure, reset HTTP instance for the new TLS session.\n", __func__));
32
33 Status = Instance->HttpIo.Http->Configure (Instance->HttpIo.Http, NULL);
34 if (EFI_ERROR (Status)) {
35 DEBUG ((DEBUG_ERROR, "%a: Error to reset HTTP instance.\n", __func__));
36 return Status;
37 }
38
39 Status = Instance->HttpIo.Http->Configure (Instance->HttpIo.Http, &((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData);
40 if (EFI_ERROR (Status)) {
41 DEBUG ((DEBUG_ERROR, "%a: Error to re-initiate HTTP instance.\n", __func__));
42 }
43
44 return Status;
45}
46
62 IN RESTEX_INSTANCE *Instance,
63 IN EFI_STATUS HttpIoReceiveStatus
64 )
65{
66 EFI_STATUS Status;
67 EFI_STATUS ReturnStatus;
68
69 if (!EFI_ERROR (HttpIoReceiveStatus)) {
70 ReturnStatus = EFI_SUCCESS;
71 } else if (HttpIoReceiveStatus != EFI_CONNECTION_FIN) {
72 if ((Instance->Flags & RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY) == 0) {
73 DEBUG ((DEBUG_ERROR, "%a: TCP error, reset HTTP session.\n", __func__));
74 Instance->Flags |= RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY;
75 gBS->Stall (500);
76 Status = ResetHttpTslSession (Instance);
77 if (!EFI_ERROR (Status)) {
78 return EFI_NOT_READY;
79 }
80
81 DEBUG ((DEBUG_ERROR, "%a: Reset HTTP instance fail.\n", __func__));
82 }
83
84 ReturnStatus = EFI_DEVICE_ERROR;
85 } else {
86 if ((Instance->Flags & RESTEX_INSTANCE_FLAGS_TLS_RETRY) != 0) {
87 DEBUG ((DEBUG_ERROR, "%a: REST_EX Send and receive fail even with a new TLS session.\n", __func__));
88 ReturnStatus = EFI_DEVICE_ERROR;
89 }
90
91 Instance->Flags |= RESTEX_INSTANCE_FLAGS_TLS_RETRY;
92 Status = ResetHttpTslSession (Instance);
93 if (EFI_ERROR (Status)) {
94 DEBUG ((DEBUG_ERROR, "%a: Reset HTTP instance fail.\n", __func__));
95 ReturnStatus = EFI_DEVICE_ERROR;
96 }
97
98 return EFI_NOT_READY;
99 }
100
101 //
102 // Clean TLS new session retry and error try flags.
103 //
104 Instance->Flags &= ~(RESTEX_INSTANCE_FLAGS_TLS_RETRY | RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY);
105 return ReturnStatus;
106}
107
132 IN EFI_HTTP_MESSAGE *RequestMessage,
133 IN EFI_HTTP_HEADER **PreservedRequestHeaders,
134 IN BOOLEAN *ItsWrite
135 )
136{
137 EFI_HTTP_HEADER *NewHeaders;
138
139 if ((This == NULL) || (RequestMessage == NULL)) {
140 return EFI_INVALID_PARAMETER;
141 }
142
143 *ItsWrite = FALSE;
144
145 if ((RequestMessage->Data.Request->Method != HttpMethodPut) && (RequestMessage->Data.Request->Method != HttpMethodPost) &&
146 (RequestMessage->Data.Request->Method != HttpMethodPatch))
147 {
148 return EFI_SUCCESS;
149 }
150
151 *ItsWrite = TRUE;
152
153 //
154 // Check PCD before adding Expect header
155 //
156 if (FixedPcdGetBool (PcdRedfishRestExAddingExpect)) {
157 if (PreservedRequestHeaders != NULL) {
158 *PreservedRequestHeaders = RequestMessage->Headers;
159 }
160
161 NewHeaders = AllocateZeroPool ((RequestMessage->HeaderCount + 1) * sizeof (EFI_HTTP_HEADER));
162 CopyMem ((VOID *)NewHeaders, (VOID *)RequestMessage->Headers, RequestMessage->HeaderCount * sizeof (EFI_HTTP_HEADER));
163 HttpSetFieldNameAndValue (NewHeaders + RequestMessage->HeaderCount, HTTP_HEADER_EXPECT, HTTP_EXPECT_100_CONTINUE);
164 RequestMessage->HeaderCount++;
165 RequestMessage->Headers = NewHeaders;
166 }
167
168 return EFI_SUCCESS;
169}
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define HTTP_EXPECT_100_CONTINUE
Definition: Http11.h:249
#define HTTP_HEADER_EXPECT
Definition: Http11.h:244
EFI_STATUS EFIAPI HttpSetFieldNameAndValue(IN OUT EFI_HTTP_HEADER *HttpHeader, IN CONST CHAR8 *FieldName, IN CONST CHAR8 *FieldValue)
Definition: DxeHttpLib.c:1529
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define FixedPcdGetBool(TokenName)
Definition: PcdLib.h:120
EFI_STATUS RedfishCheckHttpReceiveStatus(IN RESTEX_INSTANCE *Instance, IN EFI_STATUS HttpIoReceiveStatus)
EFI_STATUS RedfishHttpAddExpectation(IN EFI_REST_EX_PROTOCOL *This, IN EFI_HTTP_MESSAGE *RequestMessage, IN EFI_HTTP_HEADER **PreservedRequestHeaders, IN BOOLEAN *ItsWrite)
EFI_STATUS ResetHttpTslSession(IN RESTEX_INSTANCE *Instance)
#define EFI_CONNECTION_FIN
Definition: UefiBaseType.h:175
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS