VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c@ 105668

最後變更 在這個檔案從105668是 101291,由 vboxsync 提交於 18 月 前

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 5.7 KB
 
1/** @file
2 RestExDxe support functions implementation.
3
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
6 Copyright (c) 2023, American Megatrends International LLC.
7 Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
8
9 SPDX-License-Identifier: BSD-2-Clause-Patent
10
11**/
12#include <Uefi.h>
13#include "RedfishRestExInternal.h"
14
15/**
16 Create a new TLS session because the previous one is closed.
17
18 @param[in] Instance Pointer to EFI_REST_EX_PROTOCOL instance for a particular
19 REST service.
20 @retval EFI_SUCCESS operation succeeded.
21 @retval EFI_ERROR Other errors.
22
23**/
24EFI_STATUS
25ResetHttpTslSession (
26 IN RESTEX_INSTANCE *Instance
27 )
28{
29 EFI_STATUS Status;
30
31 DEBUG ((DEBUG_MANAGEABILITY, "%a: TCP connection is finished. Could be TSL session closure, reset HTTP instance for the new TLS session.\n", __func__));
32
33 Status = Instance->HttpIo.Http->Configure (Instance->HttpIo.Http, NULL);
34 if (EFI_ERROR (Status)) {
35 DEBUG ((DEBUG_ERROR, "%a: Error to reset HTTP instance.\n", __func__));
36 return Status;
37 }
38
39 Status = Instance->HttpIo.Http->Configure (Instance->HttpIo.Http, &((EFI_REST_EX_HTTP_CONFIG_DATA *)Instance->ConfigData)->HttpConfigData);
40 if (EFI_ERROR (Status)) {
41 DEBUG ((DEBUG_ERROR, "%a: Error to re-initiate HTTP instance.\n", __func__));
42 }
43
44 return Status;
45}
46
47/**
48 This function check Http receive status.
49
50 @param[in] Instance Pointer to EFI_REST_EX_PROTOCOL instance for a particular
51 REST service.
52 @param[in] HttpIoReceiveStatus This is the status return from HttpIoRecvResponse
53
54 @retval EFI_SUCCESS The payload receive from Redfish service in successfully.
55 @retval EFI_NOT_READY May need to resend the HTTP request.
56 @retval EFI_DEVICE_ERROR Something wrong and can't be resolved.
57 @retval Others Other errors as indicated.
58
59**/
60EFI_STATUS
61RedfishCheckHttpReceiveStatus (
62 IN RESTEX_INSTANCE *Instance,
63 IN EFI_STATUS HttpIoReceiveStatus
64 )
65{
66 EFI_STATUS Status;
67 EFI_STATUS ReturnStatus;
68
69 if (!EFI_ERROR (HttpIoReceiveStatus)) {
70 ReturnStatus = EFI_SUCCESS;
71 } else if (HttpIoReceiveStatus != EFI_CONNECTION_FIN) {
72 if ((Instance->Flags & RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY) == 0) {
73 DEBUG ((DEBUG_ERROR, "%a: TCP error, reset HTTP session.\n", __func__));
74 Instance->Flags |= RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY;
75 gBS->Stall (500);
76 Status = ResetHttpTslSession (Instance);
77 if (!EFI_ERROR (Status)) {
78 return EFI_NOT_READY;
79 }
80
81 DEBUG ((DEBUG_ERROR, "%a: Reset HTTP instance fail.\n", __func__));
82 }
83
84 ReturnStatus = EFI_DEVICE_ERROR;
85 } else {
86 if ((Instance->Flags & RESTEX_INSTANCE_FLAGS_TLS_RETRY) != 0) {
87 DEBUG ((DEBUG_ERROR, "%a: REST_EX Send and receive fail even with a new TLS session.\n", __func__));
88 ReturnStatus = EFI_DEVICE_ERROR;
89 }
90
91 Instance->Flags |= RESTEX_INSTANCE_FLAGS_TLS_RETRY;
92 Status = ResetHttpTslSession (Instance);
93 if (EFI_ERROR (Status)) {
94 DEBUG ((DEBUG_ERROR, "%a: Reset HTTP instance fail.\n", __func__));
95 ReturnStatus = EFI_DEVICE_ERROR;
96 }
97
98 return EFI_NOT_READY;
99 }
100
101 //
102 // Clean TLS new session retry and error try flags.
103 //
104 Instance->Flags &= ~(RESTEX_INSTANCE_FLAGS_TLS_RETRY | RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY);
105 return ReturnStatus;
106}
107
108/**
109 This function send the HTTP request without body to see
110 if the write to URL is permitted by Redfish service. This function
111 checks if the HTTP request has Content-length in HTTP header. If yes,
112 set HTTP body to NULL and then send to service. Check the HTTP status
113 for the firther actions.
114
115 @param[in] This Pointer to EFI_REST_EX_PROTOCOL instance for a particular
116 REST service.
117 @param[in] RequestMessage Pointer to the HTTP request data for this resource
118 @param[in] PreservedRequestHeaders The pointer to save the request headers
119 @param[in] ItsWrite This is write method to URL.
120
121 @retval EFI_INVALID_PARAMETER Improper given parameters.
122 @retval EFI_SUCCESS This HTTP request is free to send to Redfish service.
123 @retval EFI_OUT_OF_RESOURCES NOt enough memory to process.
124 @retval EFI_ACCESS_DENIED Not allowed to write to this URL.
125
126 @retval Others Other errors as indicated.
127
128**/
129EFI_STATUS
130RedfishHttpAddExpectation (
131 IN EFI_REST_EX_PROTOCOL *This,
132 IN EFI_HTTP_MESSAGE *RequestMessage,
133 IN EFI_HTTP_HEADER **PreservedRequestHeaders,
134 IN BOOLEAN *ItsWrite
135 )
136{
137 EFI_HTTP_HEADER *NewHeaders;
138
139 if ((This == NULL) || (RequestMessage == NULL)) {
140 return EFI_INVALID_PARAMETER;
141 }
142
143 *ItsWrite = FALSE;
144
145 if ((RequestMessage->Data.Request->Method != HttpMethodPut) && (RequestMessage->Data.Request->Method != HttpMethodPost) &&
146 (RequestMessage->Data.Request->Method != HttpMethodPatch))
147 {
148 return EFI_SUCCESS;
149 }
150
151 *ItsWrite = TRUE;
152
153 //
154 // Check PCD before adding Expect header
155 //
156 if (FixedPcdGetBool (PcdRedfishRestExAddingExpect)) {
157 if (PreservedRequestHeaders != NULL) {
158 *PreservedRequestHeaders = RequestMessage->Headers;
159 }
160
161 NewHeaders = AllocateZeroPool ((RequestMessage->HeaderCount + 1) * sizeof (EFI_HTTP_HEADER));
162 CopyMem ((VOID *)NewHeaders, (VOID *)RequestMessage->Headers, RequestMessage->HeaderCount * sizeof (EFI_HTTP_HEADER));
163 HttpSetFieldNameAndValue (NewHeaders + RequestMessage->HeaderCount, HTTP_HEADER_EXPECT, HTTP_EXPECT_100_CONTINUE);
164 RequestMessage->HeaderCount++;
165 RequestMessage->Headers = NewHeaders;
166 }
167
168 return EFI_SUCCESS;
169}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette