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