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