VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c@ 105668

Last change on this file since 105668 was 101291, checked in by vboxsync, 20 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette