RedfishRestExProtocol.c 33 KB

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