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