1 | /** @file
|
---|
2 | Implementation of Redfish EFI_REST_EX_PROTOCOL interfaces.
|
---|
3 |
|
---|
4 | Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
|
---|
5 | (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
|
---|
6 | Copyright (c) 2023, American Megatrends International LLC.
|
---|
7 | Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
---|
8 |
|
---|
9 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
10 |
|
---|
11 | **/
|
---|
12 | #include <Uefi.h>
|
---|
13 | #include "RedfishRestExInternal.h"
|
---|
14 |
|
---|
15 | EFI_REST_EX_PROTOCOL mRedfishRestExProtocol = {
|
---|
16 | RedfishRestExSendReceive,
|
---|
17 | RedfishRestExGetServiceTime,
|
---|
18 | RedfishRestExGetService,
|
---|
19 | RedfishRestExGetModeData,
|
---|
20 | RedfishRestExConfigure,
|
---|
21 | RedfishRestExAyncSendReceive,
|
---|
22 | RedfishRestExEventService
|
---|
23 | };
|
---|
24 |
|
---|
25 | /**
|
---|
26 | Provides a simple HTTP-like interface to send and receive resources from a REST service.
|
---|
27 |
|
---|
28 | The SendReceive() function sends an HTTP request to this REST service, and returns a
|
---|
29 | response when the data is retrieved from the service. RequestMessage contains the HTTP
|
---|
30 | request to the REST resource identified by RequestMessage.Request.Url. The
|
---|
31 | ResponseMessage is the returned HTTP response for that request, including any HTTP
|
---|
32 | status. It's caller's responsibility to free this ResponseMessage using FreePool().
|
---|
33 | RestConfigFreeHttpMessage() in RedfishLib is an example to release ResponseMessage structure.
|
---|
34 |
|
---|
35 | @param[in] This Pointer to EFI_REST_EX_PROTOCOL instance for a particular
|
---|
36 | REST service.
|
---|
37 | @param[in] RequestMessage Pointer to the HTTP request data for this resource
|
---|
38 | @param[out] ResponseMessage Pointer to the HTTP response data obtained for this requested.
|
---|
39 |
|
---|
40 | @retval EFI_SUCCESS operation succeeded.
|
---|
41 | @retval EFI_INVALID_PARAMETER This, RequestMessage, or ResponseMessage are NULL.
|
---|
42 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
|
---|
43 | @retval EFI_ACCESS_DENIED HTTP method is not allowed on this URL.
|
---|
44 | @retval EFI_BAD_BUFFER_SIZE The payload is to large to be handled on server side.
|
---|
45 | @retval EFI_UNSUPPORTED Unsupported HTTP response.
|
---|
46 |
|
---|
47 | **/
|
---|
48 | EFI_STATUS
|
---|
49 | EFIAPI
|
---|
50 | RedfishRestExSendReceive (
|
---|
51 | IN EFI_REST_EX_PROTOCOL *This,
|
---|
52 | IN EFI_HTTP_MESSAGE *RequestMessage,
|
---|
53 | OUT EFI_HTTP_MESSAGE *ResponseMessage
|
---|
54 | )
|
---|
55 | {
|
---|
56 | EFI_STATUS Status;
|
---|
57 | RESTEX_INSTANCE *Instance;
|
---|
58 | HTTP_IO_RESPONSE_DATA *ResponseData;
|
---|
59 | UINTN TotalReceivedSize;
|
---|
60 | UINTN Index;
|
---|
61 | LIST_ENTRY *ChunkListLink;
|
---|
62 | HTTP_IO_CHUNKS *ThisChunk;
|
---|
63 | BOOLEAN CopyChunkData;
|
---|
64 | BOOLEAN MediaPresent;
|
---|
65 | EFI_HTTP_HEADER *PreservedRequestHeaders;
|
---|
66 | BOOLEAN ItsWrite;
|
---|
67 | BOOLEAN IsGetChunkedTransfer;
|
---|
68 | HTTP_IO_SEND_CHUNK_PROCESS SendChunkProcess;
|
---|
69 | HTTP_IO_SEND_NON_CHUNK_PROCESS SendNonChunkProcess;
|
---|
70 | EFI_HTTP_MESSAGE ChunkTransferRequestMessage;
|
---|
71 |
|
---|
72 | Status = EFI_SUCCESS;
|
---|
73 | ResponseData = NULL;
|
---|
74 | IsGetChunkedTransfer = FALSE;
|
---|
75 | SendChunkProcess = HttpIoSendChunkNone;
|
---|
76 | SendNonChunkProcess = HttpIoSendNonChunkNone;
|
---|
77 | ItsWrite = FALSE;
|
---|
78 | PreservedRequestHeaders = NULL;
|
---|
79 |
|
---|
80 | //
|
---|
81 | // Validate the parameters
|
---|
82 | //
|
---|
83 | if ((This == NULL) || (RequestMessage == NULL) || (ResponseMessage == NULL)) {
|
---|
84 | return EFI_INVALID_PARAMETER;
|
---|
85 | }
|
---|
86 |
|
---|
87 | Instance = RESTEX_INSTANCE_FROM_THIS (This);
|
---|
88 |
|
---|
89 | //
|
---|
90 | // Check Media Status.
|
---|
91 | //
|
---|
92 | MediaPresent = TRUE;
|
---|
93 | NetLibDetectMedia (Instance->Service->ControllerHandle, &MediaPresent);
|
---|
94 | if (!MediaPresent) {
|
---|
95 | DEBUG ((DEBUG_REDFISH_NETWORK, "RedfishRestExSendReceive(): No MediaPresent.\n"));
|
---|
96 | return EFI_NO_MEDIA;
|
---|
97 | }
|
---|
98 |
|
---|
99 | DEBUG ((DEBUG_REDFISH_NETWORK, "\nRedfishRestExSendReceive():\n"));
|
---|
100 | DEBUG ((DEBUG_REDFISH_NETWORK, "*** Perform HTTP Request Method - %d, URL: %s\n", RequestMessage->Data.Request->Method, RequestMessage->Data.Request->Url));
|
---|
101 |
|
---|
102 | if (FixedPcdGetBool (PcdRedfishRestExChunkRequestMode)) {
|
---|
103 | //
|
---|
104 | // Add header "Expect" to server, only for URL write.
|
---|
105 | //
|
---|
106 | Status = RedfishHttpAddExpectation (This, RequestMessage, &PreservedRequestHeaders, &ItsWrite);
|
---|
107 | if (EFI_ERROR (Status)) {
|
---|
108 | return Status;
|
---|
109 | }
|
---|
110 |
|
---|
111 | if (ItsWrite == TRUE) {
|
---|
112 | if (RequestMessage->BodyLength > HTTP_IO_MAX_SEND_PAYLOAD) {
|
---|
113 | //
|
---|
114 | // Send chunked transfer.
|
---|
115 | //
|
---|
116 | SendChunkProcess++;
|
---|
117 | CopyMem ((VOID *)&ChunkTransferRequestMessage, (VOID *)RequestMessage, sizeof (EFI_HTTP_MESSAGE));
|
---|
118 | } else {
|
---|
119 | SendNonChunkProcess++;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | ReSendRequest:;
|
---|
125 |
|
---|
126 | if (FixedPcdGetBool (PcdRedfishRestExChunkRequestMode)) {
|
---|
127 | //
|
---|
128 | // Send the chunked request to REST service.
|
---|
129 | //
|
---|
130 | if (ItsWrite == TRUE) {
|
---|
131 | //
|
---|
132 | // This is write to URI
|
---|
133 | //
|
---|
134 | if (SendChunkProcess > HttpIoSendChunkNone) {
|
---|
135 | //
|
---|
136 | // This is chunk transfer for writing large payload.
|
---|
137 | // Send request header first and then handle the
|
---|
138 | // following request message body using chunk transfer.
|
---|
139 | //
|
---|
140 | do {
|
---|
141 | Status = HttpIoSendChunkedTransfer (
|
---|
142 | &(Instance->HttpIo),
|
---|
143 | &SendChunkProcess,
|
---|
144 | &ChunkTransferRequestMessage
|
---|
145 | );
|
---|
146 | if (EFI_ERROR (Status)) {
|
---|
147 | goto ON_EXIT;
|
---|
148 | }
|
---|
149 | } while (SendChunkProcess == HttpIoSendChunkContent || SendChunkProcess == HttpIoSendChunkEndChunk);
|
---|
150 | } else {
|
---|
151 | //
|
---|
152 | // This is the non-chunk transfer, send request header first and then
|
---|
153 | // handle the following request message body using chunk transfer.
|
---|
154 | //
|
---|
155 | Status = HttpIoSendRequest (
|
---|
156 | &(Instance->HttpIo),
|
---|
157 | (SendNonChunkProcess == HttpIoSendNonChunkContent) ? NULL : RequestMessage->Data.Request,
|
---|
158 | (SendNonChunkProcess == HttpIoSendNonChunkContent) ? 0 : RequestMessage->HeaderCount,
|
---|
159 | (SendNonChunkProcess == HttpIoSendNonChunkContent) ? NULL : RequestMessage->Headers,
|
---|
160 | (SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent) ? 0 : RequestMessage->BodyLength,
|
---|
161 | (SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent) ? NULL : RequestMessage->Body
|
---|
162 | );
|
---|
163 | }
|
---|
164 | } else {
|
---|
165 | //
|
---|
166 | // This is read from URI.
|
---|
167 | //
|
---|
168 | Status = HttpIoSendRequest (
|
---|
169 | &(Instance->HttpIo),
|
---|
170 | RequestMessage->Data.Request,
|
---|
171 | RequestMessage->HeaderCount,
|
---|
172 | RequestMessage->Headers,
|
---|
173 | RequestMessage->BodyLength,
|
---|
174 | RequestMessage->Body
|
---|
175 | );
|
---|
176 | }
|
---|
177 | } else {
|
---|
178 | //
|
---|
179 | // This is normal request to URI.
|
---|
180 | //
|
---|
181 | Status = HttpIoSendRequest (
|
---|
182 | &(Instance->HttpIo),
|
---|
183 | RequestMessage->Data.Request,
|
---|
184 | RequestMessage->HeaderCount,
|
---|
185 | RequestMessage->Headers,
|
---|
186 | RequestMessage->BodyLength,
|
---|
187 | RequestMessage->Body
|
---|
188 | );
|
---|
189 | }
|
---|
190 |
|
---|
191 | if (EFI_ERROR (Status)) {
|
---|
192 | //
|
---|
193 | // Communication failure happens. Reset the session.
|
---|
194 | //
|
---|
195 | ResetHttpTslSession (Instance);
|
---|
196 | goto ON_EXIT;
|
---|
197 | }
|
---|
198 |
|
---|
199 | //
|
---|
200 | // ResponseMessage->Data.Response is to indicate whether to receive the HTTP header or not.
|
---|
201 | // ResponseMessage->BodyLength/ResponseMessage->Body are to indicate whether to receive the response body or not.
|
---|
202 | // Clean the previous buffers and all of them will be allocated later according to the actual situation.
|
---|
203 | //
|
---|
204 | if (ResponseMessage->Data.Response != NULL) {
|
---|
205 | FreePool (ResponseMessage->Data.Response);
|
---|
206 | ResponseMessage->Data.Response = NULL;
|
---|
207 | }
|
---|
208 |
|
---|
209 | ResponseMessage->BodyLength = 0;
|
---|
210 | if (ResponseMessage->Body != NULL) {
|
---|
211 | FreePool (ResponseMessage->Body);
|
---|
212 | ResponseMessage->Body = NULL;
|
---|
213 | }
|
---|
214 |
|
---|
215 | //
|
---|
216 | // Use zero BodyLength to only receive the response headers.
|
---|
217 | //
|
---|
218 | ResponseData = AllocateZeroPool (sizeof (HTTP_IO_RESPONSE_DATA));
|
---|
219 | if (ResponseData == NULL) {
|
---|
220 | Status = EFI_OUT_OF_RESOURCES;
|
---|
221 | goto ON_EXIT;
|
---|
222 | }
|
---|
223 |
|
---|
224 | DEBUG ((DEBUG_REDFISH_NETWORK, "Receiving HTTP response and headers...\n"));
|
---|
225 | Status = RedfishCheckHttpReceiveStatus (
|
---|
226 | Instance,
|
---|
227 | HttpIoRecvResponse (
|
---|
228 | &(Instance->HttpIo),
|
---|
229 | TRUE,
|
---|
230 | ResponseData
|
---|
231 | )
|
---|
232 | );
|
---|
233 | if (Status == EFI_NOT_READY) {
|
---|
234 | goto ReSendRequest;
|
---|
235 | } else if (Status == EFI_DEVICE_ERROR) {
|
---|
236 | goto ON_EXIT;
|
---|
237 | }
|
---|
238 |
|
---|
239 | //
|
---|
240 | // Restore the headers if it ever changed in RedfishHttpAddExpectation().
|
---|
241 | //
|
---|
242 | if (FixedPcdGetBool (PcdRedfishRestExAddingExpect) && (RequestMessage->Headers != PreservedRequestHeaders)) {
|
---|
243 | FreePool (RequestMessage->Headers);
|
---|
244 | RequestMessage->Headers = PreservedRequestHeaders; // Restore headers before we adding "Expect".
|
---|
245 | RequestMessage->HeaderCount--; // Minus one header count for "Expect".
|
---|
246 | }
|
---|
247 |
|
---|
248 | DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP Response StatusCode - %d:", ResponseData->Response.StatusCode));
|
---|
249 | if (ResponseData->Response.StatusCode == HTTP_STATUS_200_OK) {
|
---|
250 | DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_200_OK\n"));
|
---|
251 |
|
---|
252 | if (FixedPcdGetBool (PcdRedfishRestExChunkRequestMode) && (SendChunkProcess == HttpIoSendChunkHeaderZeroContent)) {
|
---|
253 | DEBUG ((DEBUG_REDFISH_NETWORK, "This is chunk transfer, start to send all chunks - %d.", ResponseData->Response.StatusCode));
|
---|
254 | SendChunkProcess++;
|
---|
255 | goto ReSendRequest;
|
---|
256 | }
|
---|
257 | } else if (ResponseData->Response.StatusCode == HTTP_STATUS_204_NO_CONTENT) {
|
---|
258 | DEBUG ((DEBUG_MANAGEABILITY, "HTTP_STATUS_204_NO_CONTENT\n"));
|
---|
259 |
|
---|
260 | if (FixedPcdGetBool (PcdRedfishRestExChunkRequestMode) && (SendChunkProcess == HttpIoSendChunkHeaderZeroContent)) {
|
---|
261 | DEBUG ((DEBUG_MANAGEABILITY, "This is chunk transfer, start to send all chunks - %d.", ResponseData->Response.StatusCode));
|
---|
262 | SendChunkProcess++;
|
---|
263 | goto ReSendRequest;
|
---|
264 | }
|
---|
265 | } else if (ResponseData->Response.StatusCode == HTTP_STATUS_201_CREATED) {
|
---|
266 | DEBUG ((DEBUG_MANAGEABILITY, "HTTP_STATUS_201_CREATED\n"));
|
---|
267 | } else if (ResponseData->Response.StatusCode == HTTP_STATUS_202_ACCEPTED) {
|
---|
268 | DEBUG ((DEBUG_MANAGEABILITY, "HTTP_STATUS_202_ACCEPTED\n"));
|
---|
269 | } else if (ResponseData->Response.StatusCode == HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE) {
|
---|
270 | DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE\n"));
|
---|
271 |
|
---|
272 | Status = EFI_BAD_BUFFER_SIZE;
|
---|
273 | goto ON_EXIT;
|
---|
274 | } else if (ResponseData->Response.StatusCode == HTTP_STATUS_405_METHOD_NOT_ALLOWED) {
|
---|
275 | DEBUG ((DEBUG_ERROR, "HTTP_STATUS_405_METHOD_NOT_ALLOWED\n"));
|
---|
276 |
|
---|
277 | Status = EFI_ACCESS_DENIED;
|
---|
278 | goto ON_EXIT;
|
---|
279 | } else if (ResponseData->Response.StatusCode == HTTP_STATUS_400_BAD_REQUEST) {
|
---|
280 | DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_400_BAD_REQUEST\n"));
|
---|
281 | if (FixedPcdGetBool (PcdRedfishRestExChunkRequestMode) && (SendChunkProcess == HttpIoSendChunkHeaderZeroContent)) {
|
---|
282 | DEBUG ((DEBUG_REDFISH_NETWORK, "Bad request may caused by zero length chunk. Try to send all chunks...\n"));
|
---|
283 | SendChunkProcess++;
|
---|
284 | goto ReSendRequest;
|
---|
285 | }
|
---|
286 | } else if (ResponseData->Response.StatusCode == HTTP_STATUS_100_CONTINUE) {
|
---|
287 | DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_100_CONTINUE\n"));
|
---|
288 | if (FixedPcdGetBool (PcdRedfishRestExChunkRequestMode) && (SendChunkProcess == HttpIoSendChunkHeaderZeroContent)) {
|
---|
289 | //
|
---|
290 | // We get HTTP_STATUS_100_CONTINUE to send the body using chunk transfer.
|
---|
291 | //
|
---|
292 | DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_100_CONTINUE for chunk transfer...\n"));
|
---|
293 | SendChunkProcess++;
|
---|
294 | goto ReSendRequest;
|
---|
295 | }
|
---|
296 |
|
---|
297 | if (FixedPcdGetBool (PcdRedfishRestExChunkRequestMode) && (SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent)) {
|
---|
298 | DEBUG ((DEBUG_REDFISH_NETWORK, "HTTP_STATUS_100_CONTINUE for non chunk transfer...\n"));
|
---|
299 | SendNonChunkProcess++;
|
---|
300 | goto ReSendRequest;
|
---|
301 | }
|
---|
302 |
|
---|
303 | //
|
---|
304 | // It's the REST protocol's responsibility to handle the interim HTTP response (e.g. 100 Continue Informational),
|
---|
305 | // and return the final response content to the caller.
|
---|
306 | //
|
---|
307 | if ((ResponseData->Headers != NULL) && (ResponseData->HeaderCount != 0)) {
|
---|
308 | FreePool (ResponseData->Headers);
|
---|
309 | }
|
---|
310 |
|
---|
311 | ZeroMem (ResponseData, sizeof (HTTP_IO_RESPONSE_DATA));
|
---|
312 | Status = HttpIoRecvResponse (
|
---|
313 | &(Instance->HttpIo),
|
---|
314 | TRUE,
|
---|
315 | ResponseData
|
---|
316 | );
|
---|
317 | if (EFI_ERROR (Status)) {
|
---|
318 | goto ON_EXIT;
|
---|
319 | }
|
---|
320 | } else {
|
---|
321 | DEBUG ((DEBUG_ERROR, "This HTTP Status is not handled!\n"));
|
---|
322 | DumpHttpStatusCode (DEBUG_REDFISH_NETWORK, ResponseData->Response.StatusCode);
|
---|
323 | Status = EFI_UNSUPPORTED;
|
---|
324 |
|
---|
325 | //
|
---|
326 | // Deliver status code back to caller so caller can handle it.
|
---|
327 | //
|
---|
328 | ResponseMessage->Data.Response = AllocateZeroPool (sizeof (EFI_HTTP_RESPONSE_DATA));
|
---|
329 | if (ResponseMessage->Data.Response == NULL) {
|
---|
330 | Status = EFI_OUT_OF_RESOURCES;
|
---|
331 | goto ON_EXIT;
|
---|
332 | }
|
---|
333 |
|
---|
334 | ResponseMessage->Data.Response->StatusCode = ResponseData->Response.StatusCode;
|
---|
335 |
|
---|
336 | goto ON_EXIT;
|
---|
337 | }
|
---|
338 |
|
---|
339 | //
|
---|
340 | // Ready to return the StatusCode, Header info and BodyLength.
|
---|
341 | //
|
---|
342 | ResponseMessage->Data.Response = AllocateZeroPool (sizeof (EFI_HTTP_RESPONSE_DATA));
|
---|
343 | if (ResponseMessage->Data.Response == NULL) {
|
---|
344 | Status = EFI_OUT_OF_RESOURCES;
|
---|
345 | goto ON_EXIT;
|
---|
346 | }
|
---|
347 |
|
---|
348 | ResponseMessage->Data.Response->StatusCode = ResponseData->Response.StatusCode;
|
---|
349 | ResponseMessage->HeaderCount = ResponseData->HeaderCount;
|
---|
350 | ResponseMessage->Headers = ResponseData->Headers;
|
---|
351 |
|
---|
352 | //
|
---|
353 | // Get response message body.
|
---|
354 | //
|
---|
355 | if (ResponseMessage->HeaderCount > 0) {
|
---|
356 | Status = HttpIoGetContentLength (ResponseMessage->HeaderCount, ResponseMessage->Headers, &ResponseMessage->BodyLength);
|
---|
357 | if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
|
---|
358 | goto ON_EXIT;
|
---|
359 | }
|
---|
360 |
|
---|
361 | if (Status == EFI_NOT_FOUND) {
|
---|
362 | ASSERT (ResponseMessage->BodyLength == 0);
|
---|
363 | }
|
---|
364 |
|
---|
365 | if (ResponseMessage->BodyLength == 0) {
|
---|
366 | //
|
---|
367 | // Check if Chunked Transfer Coding.
|
---|
368 | //
|
---|
369 | Status = HttpIoGetChunkedTransferContent (
|
---|
370 | &(Instance->HttpIo),
|
---|
371 | ResponseMessage->HeaderCount,
|
---|
372 | ResponseMessage->Headers,
|
---|
373 | &ChunkListLink,
|
---|
374 | &ResponseMessage->BodyLength
|
---|
375 | );
|
---|
376 | if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
|
---|
377 | goto ON_EXIT;
|
---|
378 | }
|
---|
379 |
|
---|
380 | if ((Status == EFI_SUCCESS) &&
|
---|
381 | (ChunkListLink != NULL) &&
|
---|
382 | !IsListEmpty (ChunkListLink) &&
|
---|
383 | (ResponseMessage->BodyLength != 0))
|
---|
384 | {
|
---|
385 | IsGetChunkedTransfer = TRUE;
|
---|
386 | //
|
---|
387 | // Copy data to Message body.
|
---|
388 | //
|
---|
389 | CopyChunkData = TRUE;
|
---|
390 | ResponseMessage->Body = AllocateZeroPool (ResponseMessage->BodyLength);
|
---|
391 | if (ResponseMessage->Body == NULL) {
|
---|
392 | Status = EFI_OUT_OF_RESOURCES;
|
---|
393 | CopyChunkData = FALSE;
|
---|
394 | }
|
---|
395 |
|
---|
396 | Index = 0;
|
---|
397 | while (!IsListEmpty (ChunkListLink)) {
|
---|
398 | ThisChunk = (HTTP_IO_CHUNKS *)GetFirstNode (ChunkListLink);
|
---|
399 | if (CopyChunkData) {
|
---|
400 | CopyMem (((UINT8 *)ResponseMessage->Body + Index), (UINT8 *)ThisChunk->Data, ThisChunk->Length);
|
---|
401 | Index += ThisChunk->Length;
|
---|
402 | }
|
---|
403 |
|
---|
404 | RemoveEntryList (&ThisChunk->NextChunk);
|
---|
405 | FreePool ((VOID *)ThisChunk->Data);
|
---|
406 | FreePool ((VOID *)ThisChunk);
|
---|
407 | }
|
---|
408 |
|
---|
409 | FreePool ((VOID *)ChunkListLink);
|
---|
410 | }
|
---|
411 | }
|
---|
412 |
|
---|
413 | Status = EFI_SUCCESS;
|
---|
414 | }
|
---|
415 |
|
---|
416 | //
|
---|
417 | // Ready to return the Body from REST service if have any.
|
---|
418 | //
|
---|
419 | if ((ResponseMessage->BodyLength > 0) && !IsGetChunkedTransfer) {
|
---|
420 | ResponseData->HeaderCount = 0;
|
---|
421 | ResponseData->Headers = NULL;
|
---|
422 |
|
---|
423 | ResponseMessage->Body = AllocateZeroPool (ResponseMessage->BodyLength);
|
---|
424 | if (ResponseMessage->Body == NULL) {
|
---|
425 | Status = EFI_OUT_OF_RESOURCES;
|
---|
426 | goto ON_EXIT;
|
---|
427 | }
|
---|
428 |
|
---|
429 | //
|
---|
430 | // Only receive the Body.
|
---|
431 | //
|
---|
432 | TotalReceivedSize = 0;
|
---|
433 | while (TotalReceivedSize < ResponseMessage->BodyLength) {
|
---|
434 | ResponseData->BodyLength = ResponseMessage->BodyLength - TotalReceivedSize;
|
---|
435 | ResponseData->Body = (CHAR8 *)ResponseMessage->Body + TotalReceivedSize;
|
---|
436 | Status = HttpIoRecvResponse (
|
---|
437 | &(Instance->HttpIo),
|
---|
438 | FALSE,
|
---|
439 | ResponseData
|
---|
440 | );
|
---|
441 | if (EFI_ERROR (Status)) {
|
---|
442 | goto ON_EXIT;
|
---|
443 | }
|
---|
444 |
|
---|
445 | TotalReceivedSize += ResponseData->BodyLength;
|
---|
446 | }
|
---|
447 |
|
---|
448 | DEBUG ((DEBUG_REDFISH_NETWORK, "Total of length of Response :%d\n", TotalReceivedSize));
|
---|
449 | }
|
---|
450 |
|
---|
451 | DEBUG ((DEBUG_REDFISH_NETWORK, "RedfishRestExSendReceive()- EFI_STATUS: %r\n", Status));
|
---|
452 |
|
---|
453 | ON_EXIT:
|
---|
454 |
|
---|
455 | if (ResponseData != NULL) {
|
---|
456 | FreePool (ResponseData);
|
---|
457 | }
|
---|
458 |
|
---|
459 | return Status;
|
---|
460 | }
|
---|
461 |
|
---|
462 | /**
|
---|
463 | Obtain the current time from this REST service instance.
|
---|
464 |
|
---|
465 | The GetServiceTime() function is an optional interface to obtain the current time from
|
---|
466 | this REST service instance. If this REST service does not support to retrieve the time,
|
---|
467 | this function returns EFI_UNSUPPORTED. This function must returns EFI_UNSUPPORTED if
|
---|
468 | EFI_REST_EX_SERVICE_TYPE returned in EFI_REST_EX_SERVICE_INFO from GetService() is
|
---|
469 | EFI_REST_EX_SERVICE_UNSPECIFIC.
|
---|
470 |
|
---|
471 | @param[in] This Pointer to EFI_REST_EX_PROTOCOL instance for a particular
|
---|
472 | REST service.
|
---|
473 | @param[out] Time A pointer to storage to receive a snapshot of the current time of
|
---|
474 | the REST service.
|
---|
475 |
|
---|
476 | @retval EFI_SUCCESS operation succeeded.
|
---|
477 | @retval EFI_INVALID_PARAMETER This or Time are NULL.
|
---|
478 | @retval EFI_UNSUPPORTED The RESTful service does not support returning the time.
|
---|
479 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
|
---|
480 | @retval EFI_NOT_READY The configuration of this instance is not set yet. Configure() must
|
---|
481 | be executed and returns successfully prior to invoke this function.
|
---|
482 |
|
---|
483 | **/
|
---|
484 | EFI_STATUS
|
---|
485 | EFIAPI
|
---|
486 | RedfishRestExGetServiceTime (
|
---|
487 | IN EFI_REST_EX_PROTOCOL *This,
|
---|
488 | OUT EFI_TIME *Time
|
---|
489 | )
|
---|
490 | {
|
---|
491 | return EFI_UNSUPPORTED;
|
---|
492 | }
|
---|
493 |
|
---|
494 | /**
|
---|
495 | This function returns the information of REST service provided by this EFI REST EX driver instance.
|
---|
496 |
|
---|
497 | The information such as the type of REST service and the access mode of REST EX driver instance
|
---|
498 | (In-band or Out-of-band) are described in EFI_REST_EX_SERVICE_INFO structure. For the vendor-specific
|
---|
499 | REST service, vendor-specific REST service information is returned in VendorSpecifcData.
|
---|
500 | REST EX driver designer is well know what REST service this REST EX driver instance intends to
|
---|
501 | communicate with. The designer also well know this driver instance is used to talk to BMC through
|
---|
502 | specific platform mechanism or talk to REST server through UEFI HTTP protocol. REST EX driver is
|
---|
503 | responsible to fill up the correct information in EFI_REST_EX_SERVICE_INFO. EFI_REST_EX_SERVICE_INFO
|
---|
504 | is referred by EFI REST clients to pickup the proper EFI REST EX driver instance to get and set resource.
|
---|
505 | GetService() is a basic and mandatory function which must be able to use even Configure() is not invoked
|
---|
506 | in previously.
|
---|
507 |
|
---|
508 | @param[in] This Pointer to EFI_REST_EX_PROTOCOL instance for a particular
|
---|
509 | REST service.
|
---|
510 | @param[out] RestExServiceInfo Pointer to receive a pointer to EFI_REST_EX_SERVICE_INFO structure. The
|
---|
511 | format of EFI_REST_EX_SERVICE_INFO is version controlled for the future
|
---|
512 | extension. The version of EFI_REST_EX_SERVICE_INFO structure is returned
|
---|
513 | in the header within this structure. EFI REST client refers to the correct
|
---|
514 | format of structure according to the version number. The pointer to
|
---|
515 | EFI_REST_EX_SERVICE_INFO is a memory block allocated by EFI REST EX driver
|
---|
516 | instance. That is caller's responsibility to free this memory when this
|
---|
517 | structure is no longer needed. Refer to Related Definitions below for the
|
---|
518 | definitions of EFI_REST_EX_SERVICE_INFO structure.
|
---|
519 |
|
---|
520 | @retval EFI_SUCCESS EFI_REST_EX_SERVICE_INFO is returned in RestExServiceInfo. This function
|
---|
521 | is not supported in this REST EX Protocol driver instance.
|
---|
522 | @retval EFI_UNSUPPORTED This function is not supported in this REST EX Protocol driver instance.
|
---|
523 |
|
---|
524 | **/
|
---|
525 | EFI_STATUS
|
---|
526 | EFIAPI
|
---|
527 | RedfishRestExGetService (
|
---|
528 | IN EFI_REST_EX_PROTOCOL *This,
|
---|
529 | OUT EFI_REST_EX_SERVICE_INFO **RestExServiceInfo
|
---|
530 | )
|
---|
531 | {
|
---|
532 | EFI_TPL OldTpl;
|
---|
533 | RESTEX_INSTANCE *Instance;
|
---|
534 | EFI_REST_EX_SERVICE_INFO *ServiceInfo;
|
---|
535 |
|
---|
536 | ServiceInfo = NULL;
|
---|
537 |
|
---|
538 | if ((This == NULL) || (RestExServiceInfo == NULL)) {
|
---|
539 | return EFI_INVALID_PARAMETER;
|
---|
540 | }
|
---|
541 |
|
---|
542 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
543 |
|
---|
544 | Instance = RESTEX_INSTANCE_FROM_THIS (This);
|
---|
545 |
|
---|
546 | ServiceInfo = AllocateZeroPool (sizeof (EFI_REST_EX_SERVICE_INFO));
|
---|
547 | if (ServiceInfo == NULL) {
|
---|
548 | return EFI_OUT_OF_RESOURCES;
|
---|
549 | }
|
---|
550 |
|
---|
551 | CopyMem (ServiceInfo, &(Instance->Service->RestExServiceInfo), sizeof (EFI_REST_EX_SERVICE_INFO));
|
---|
552 |
|
---|
553 | *RestExServiceInfo = ServiceInfo;
|
---|
554 |
|
---|
555 | gBS->RestoreTPL (OldTpl);
|
---|
556 |
|
---|
557 | return EFI_SUCCESS;
|
---|
558 | }
|
---|
559 |
|
---|
560 | /**
|
---|
561 | This function returns operational configuration of current EFI REST EX child instance.
|
---|
562 |
|
---|
563 | This function returns the current configuration of EFI REST EX child instance. The format of
|
---|
564 | operational configuration depends on the implementation of EFI REST EX driver instance. For
|
---|
565 | example, HTTP-aware EFI REST EX driver instance uses EFI HTTP protocol as the undying protocol
|
---|
566 | to communicate with REST service. In this case, the type of configuration is
|
---|
567 | EFI_REST_EX_CONFIG_TYPE_HTTP returned from GetService(). EFI_HTTP_CONFIG_DATA is used as EFI REST
|
---|
568 | EX configuration format and returned to EFI REST client. User has to type cast RestExConfigData
|
---|
569 | to EFI_HTTP_CONFIG_DATA. For those non HTTP-aware REST EX driver instances, the type of configuration
|
---|
570 | is EFI_REST_EX_CONFIG_TYPE_UNSPECIFIC returned from GetService(). In this case, the format of
|
---|
571 | returning data could be non industrial. Instead, the format of configuration data is system/platform
|
---|
572 | specific definition such as BMC mechanism used in EFI REST EX driver instance. EFI REST client and
|
---|
573 | EFI REST EX driver instance have to refer to the specific system /platform spec which is out of UEFI scope.
|
---|
574 |
|
---|
575 | @param[in] This This is the EFI_REST_EX_PROTOCOL instance.
|
---|
576 | @param[out] RestExConfigData Pointer to receive a pointer to EFI_REST_EX_CONFIG_DATA.
|
---|
577 | The memory allocated for configuration data should be freed
|
---|
578 | by caller. See Related Definitions for the details.
|
---|
579 |
|
---|
580 | @retval EFI_SUCCESS EFI_REST_EX_CONFIG_DATA is returned in successfully.
|
---|
581 | @retval EFI_UNSUPPORTED This function is not supported in this REST EX Protocol driver instance.
|
---|
582 | @retval EFI_NOT_READY The configuration of this instance is not set yet. Configure() must be
|
---|
583 | executed and returns successfully prior to invoke this function.
|
---|
584 |
|
---|
585 | **/
|
---|
586 | EFI_STATUS
|
---|
587 | EFIAPI
|
---|
588 | RedfishRestExGetModeData (
|
---|
589 | IN EFI_REST_EX_PROTOCOL *This,
|
---|
590 | OUT EFI_REST_EX_CONFIG_DATA *RestExConfigData
|
---|
591 | )
|
---|
592 | {
|
---|
593 | return EFI_UNSUPPORTED;
|
---|
594 | }
|
---|
595 |
|
---|
596 | /**
|
---|
597 | This function is used to configure EFI REST EX child instance.
|
---|
598 |
|
---|
599 | This function is used to configure the setting of underlying protocol of REST EX child
|
---|
600 | instance. The type of configuration is according to the implementation of EFI REST EX
|
---|
601 | driver instance. For example, HTTP-aware EFI REST EX driver instance uses EFI HTTP protocol
|
---|
602 | as the undying protocol to communicate with REST service. The type of configuration is
|
---|
603 | EFI_REST_EX_CONFIG_TYPE_HTTP and RestExConfigData is the same format with EFI_HTTP_CONFIG_DATA.
|
---|
604 | Akin to HTTP configuration, REST EX child instance can be configure to use different HTTP
|
---|
605 | local access point for the data transmission. Multiple REST clients may use different
|
---|
606 | configuration of HTTP to distinguish themselves, such as to use the different TCP port.
|
---|
607 | For those non HTTP-aware REST EX driver instance, the type of configuration is
|
---|
608 | EFI_REST_EX_CONFIG_TYPE_UNSPECIFIC. RestExConfigData refers to the non industrial standard.
|
---|
609 | Instead, the format of configuration data is system/platform specific definition such as BMC.
|
---|
610 | In this case, EFI REST client and EFI REST EX driver instance have to refer to the specific
|
---|
611 | system/platform spec which is out of the UEFI scope. Besides GetService()function, no other
|
---|
612 | EFI REST EX functions can be executed by this instance until Configure()is executed and returns
|
---|
613 | successfully. All other functions must returns EFI_NOT_READY if this instance is not configured
|
---|
614 | yet. Set RestExConfigData to NULL means to put EFI REST EX child instance into the unconfigured
|
---|
615 | state.
|
---|
616 |
|
---|
617 | @param[in] This This is the EFI_REST_EX_PROTOCOL instance.
|
---|
618 | @param[in] RestExConfigData Pointer to EFI_REST_EX_CONFIG_DATA. See Related Definitions in
|
---|
619 | GetModeData() protocol interface.
|
---|
620 |
|
---|
621 | @retval EFI_SUCCESS EFI_REST_EX_CONFIG_DATA is set in successfully.
|
---|
622 | @retval EFI_DEVICE_ERROR Configuration for this REST EX child instance is failed with the given
|
---|
623 | EFI_REST_EX_CONFIG_DATA.
|
---|
624 | @retval EFI_UNSUPPORTED This function is not supported in this REST EX Protocol driver instance.
|
---|
625 |
|
---|
626 | **/
|
---|
627 | EFI_STATUS
|
---|
628 | EFIAPI
|
---|
629 | RedfishRestExConfigure (
|
---|
630 | IN EFI_REST_EX_PROTOCOL *This,
|
---|
631 | IN EFI_REST_EX_CONFIG_DATA RestExConfigData
|
---|
632 | )
|
---|
633 | {
|
---|
634 | EFI_STATUS Status;
|
---|
635 | EFI_TPL OldTpl;
|
---|
636 | RESTEX_INSTANCE *Instance;
|
---|
637 |
|
---|
638 | EFI_HTTP_CONFIG_DATA *HttpConfigData;
|
---|
639 |
|
---|
640 | Status = EFI_SUCCESS;
|
---|
641 | HttpConfigData = NULL;
|
---|
642 |
|
---|
643 | if (This == NULL) {
|
---|
644 | return EFI_INVALID_PARAMETER;
|
---|
645 | }
|
---|
646 |
|
---|
647 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
648 |
|
---|
649 | Instance = RESTEX_INSTANCE_FROM_THIS (This);
|
---|
650 |
|
---|
651 | if (RestExConfigData == NULL) {
|
---|
652 | //
|
---|
653 | // Set RestExConfigData to NULL means to put EFI REST EX child instance into the unconfigured state.
|
---|
654 | //
|
---|
655 | HttpIoDestroyIo (&(Instance->HttpIo));
|
---|
656 |
|
---|
657 | if (Instance->ConfigData != NULL) {
|
---|
658 | if (((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv4Node != NULL) {
|
---|
659 | FreePool (((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv4Node);
|
---|
660 | }
|
---|
661 |
|
---|
662 | FreePool (Instance->ConfigData);
|
---|
663 | Instance->ConfigData = NULL;
|
---|
664 | }
|
---|
665 |
|
---|
666 | Instance->State = RESTEX_STATE_UNCONFIGED;
|
---|
667 | } else {
|
---|
668 | HttpConfigData = &((EFI_REST_EX_HTTP_CONFIG_DATA *)RestExConfigData)->HttpConfigData;
|
---|
669 | Status = Instance->HttpIo.Http->Configure (Instance->HttpIo.Http, HttpConfigData);
|
---|
670 | if (EFI_ERROR (Status)) {
|
---|
671 | goto ON_EXIT;
|
---|
672 | }
|
---|
673 |
|
---|
674 | Instance->HttpIo.Timeout = ((EFI_REST_EX_HTTP_CONFIG_DATA *)RestExConfigData)->SendReceiveTimeout;
|
---|
675 |
|
---|
676 | Instance->ConfigData = AllocateZeroPool (sizeof (EFI_REST_EX_HTTP_CONFIG_DATA));
|
---|
677 | if (Instance->ConfigData == NULL) {
|
---|
678 | Status = EFI_OUT_OF_RESOURCES;
|
---|
679 | goto ON_EXIT;
|
---|
680 | }
|
---|
681 |
|
---|
682 | CopyMem (Instance->ConfigData, RestExConfigData, sizeof (EFI_REST_EX_HTTP_CONFIG_DATA));
|
---|
683 | if (HttpConfigData->LocalAddressIsIPv6 == TRUE) {
|
---|
684 | ((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv6Node = AllocateZeroPool (sizeof (EFI_HTTPv6_ACCESS_POINT));
|
---|
685 | if (((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv6Node == NULL) {
|
---|
686 | Status = EFI_OUT_OF_RESOURCES;
|
---|
687 | goto ON_EXIT;
|
---|
688 | }
|
---|
689 |
|
---|
690 | CopyMem (
|
---|
691 | ((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv6Node,
|
---|
692 | HttpConfigData->AccessPoint.IPv6Node,
|
---|
693 | sizeof (EFI_HTTPv6_ACCESS_POINT)
|
---|
694 | );
|
---|
695 | } else {
|
---|
696 | ((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv4Node = AllocateZeroPool (sizeof (EFI_HTTPv4_ACCESS_POINT));
|
---|
697 | if (((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv4Node == NULL) {
|
---|
698 | Status = EFI_OUT_OF_RESOURCES;
|
---|
699 | goto ON_EXIT;
|
---|
700 | }
|
---|
701 |
|
---|
702 | CopyMem (
|
---|
703 | ((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData.AccessPoint.IPv4Node,
|
---|
704 | HttpConfigData->AccessPoint.IPv4Node,
|
---|
705 | sizeof (EFI_HTTPv4_ACCESS_POINT)
|
---|
706 | );
|
---|
707 | }
|
---|
708 |
|
---|
709 | Instance->State = RESTEX_STATE_CONFIGED;
|
---|
710 | }
|
---|
711 |
|
---|
712 | ON_EXIT:
|
---|
713 | gBS->RestoreTPL (OldTpl);
|
---|
714 | return Status;
|
---|
715 | }
|
---|
716 |
|
---|
717 | /**
|
---|
718 | This function sends REST request to REST service and signal caller's event asynchronously when
|
---|
719 | the final response is received by REST EX Protocol driver instance.
|
---|
720 |
|
---|
721 | The essential design of this function is to handle asynchronous send/receive implicitly according
|
---|
722 | to REST service asynchronous request mechanism. Caller will get the notification once the response
|
---|
723 | is returned from REST service.
|
---|
724 |
|
---|
725 | @param[in] This This is the EFI_REST_EX_PROTOCOL instance.
|
---|
726 | @param[in] RequestMessage This is the HTTP request message sent to REST service. Set RequestMessage
|
---|
727 | to NULL to cancel the previous asynchronous request associated with the
|
---|
728 | corresponding RestExToken. See descriptions for the details.
|
---|
729 | @param[in] RestExToken REST EX token which REST EX Protocol instance uses to notify REST client
|
---|
730 | the status of response of asynchronous REST request. See related definition
|
---|
731 | of EFI_REST_EX_TOKEN.
|
---|
732 | @param[in] TimeOutInMilliSeconds The pointer to the timeout in milliseconds which REST EX Protocol driver
|
---|
733 | instance refers as the duration to drop asynchronous REST request. NULL
|
---|
734 | pointer means no timeout for this REST request. REST EX Protocol driver
|
---|
735 | signals caller's event with EFI_STATUS set to EFI_TIMEOUT in RestExToken
|
---|
736 | if REST EX Protocol can't get the response from REST service within
|
---|
737 | TimeOutInMilliSeconds.
|
---|
738 |
|
---|
739 | @retval EFI_SUCCESS Asynchronous REST request is established.
|
---|
740 | @retval EFI_UNSUPPORTED This REST EX Protocol driver instance doesn't support asynchronous request.
|
---|
741 | @retval EFI_TIMEOUT Asynchronous REST request is not established and timeout is expired.
|
---|
742 | @retval EFI_ABORT Previous asynchronous REST request has been canceled.
|
---|
743 | @retval EFI_DEVICE_ERROR Otherwise, returns EFI_DEVICE_ERROR for other errors according to HTTP Status Code.
|
---|
744 | @retval EFI_NOT_READY The configuration of this instance is not set yet. Configure() must be executed
|
---|
745 | and returns successfully prior to invoke this function.
|
---|
746 |
|
---|
747 | **/
|
---|
748 | EFI_STATUS
|
---|
749 | EFIAPI
|
---|
750 | RedfishRestExAyncSendReceive (
|
---|
751 | IN EFI_REST_EX_PROTOCOL *This,
|
---|
752 | IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
|
---|
753 | IN EFI_REST_EX_TOKEN *RestExToken,
|
---|
754 | IN UINTN *TimeOutInMilliSeconds OPTIONAL
|
---|
755 | )
|
---|
756 | {
|
---|
757 | return EFI_UNSUPPORTED;
|
---|
758 | }
|
---|
759 |
|
---|
760 | /**
|
---|
761 | This function sends REST request to a REST Event service and signals caller's event
|
---|
762 | token asynchronously when the URI resource change event is received by REST EX
|
---|
763 | Protocol driver instance.
|
---|
764 |
|
---|
765 | The essential design of this function is to monitor event implicitly according to
|
---|
766 | REST service event service mechanism. Caller will get the notification if certain
|
---|
767 | resource is changed.
|
---|
768 |
|
---|
769 | @param[in] This This is the EFI_REST_EX_PROTOCOL instance.
|
---|
770 | @param[in] RequestMessage This is the HTTP request message sent to REST service. Set RequestMessage
|
---|
771 | to NULL to cancel the previous event service associated with the corresponding
|
---|
772 | RestExToken. See descriptions for the details.
|
---|
773 | @param[in] RestExToken REST EX token which REST EX Protocol driver instance uses to notify REST client
|
---|
774 | the URI resource which monitored by REST client has been changed. See the related
|
---|
775 | definition of EFI_REST_EX_TOKEN in EFI_REST_EX_PROTOCOL.AsyncSendReceive().
|
---|
776 |
|
---|
777 | @retval EFI_SUCCESS Asynchronous REST request is established.
|
---|
778 | @retval EFI_UNSUPPORTED This REST EX Protocol driver instance doesn't support asynchronous request.
|
---|
779 | @retval EFI_ABORT Previous asynchronous REST request has been canceled or event subscription has been
|
---|
780 | delete from service.
|
---|
781 | @retval EFI_DEVICE_ERROR Otherwise, returns EFI_DEVICE_ERROR for other errors according to HTTP Status Code.
|
---|
782 | @retval EFI_NOT_READY The configuration of this instance is not set yet. Configure() must be executed
|
---|
783 | and returns successfully prior to invoke this function.
|
---|
784 |
|
---|
785 | **/
|
---|
786 | EFI_STATUS
|
---|
787 | EFIAPI
|
---|
788 | RedfishRestExEventService (
|
---|
789 | IN EFI_REST_EX_PROTOCOL *This,
|
---|
790 | IN EFI_HTTP_MESSAGE *RequestMessage OPTIONAL,
|
---|
791 | IN EFI_REST_EX_TOKEN *RestExToken
|
---|
792 | )
|
---|
793 | {
|
---|
794 | return EFI_UNSUPPORTED;
|
---|
795 | }
|
---|