VirtualBox

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

Last change on this file since 101283 was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

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