VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Library/DxeRestExLib/DxeRestExLib.c@ 101283

Last change on this file since 101283 was 99404, checked in by vboxsync, 23 months ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1/** @file
2 This library provides help functions for REST EX Protocol.
3
4 (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include <Uefi.h>
11#include <Library/BaseMemoryLib.h>
12#include <Library/MemoryAllocationLib.h>
13#include <Library/NetLib.h>
14#include <Library/UefiBootServicesTableLib.h>
15#include <Protocol/Http.h>
16#include <Protocol/RestEx.h>
17
18#define REST_EX_CONFIG_DATA_LEN_UNKNOWN 0xff
19
20/**
21 This function allows the caller to create child handle for specific
22 REST server.
23
24 @param[in] Image The image handle used to open service.
25 @param[in] AccessMode Access mode of REST server.
26 @param[in] ConfigType Underlying configuration to communicate with REST server.
27 @param[in] ServiceType REST service type.
28 @param[out] ChildInstanceHandle The handle to receive the create child.
29
30 @retval EFI_SUCCESS Can't create the corresponding REST EX child instance.
31 @retval EFI_INVALID_PARAMETERS Any of input parameters is improper.
32
33**/
34EFI_STATUS
35RestExLibCreateChild (
36 IN EFI_HANDLE Image,
37 IN EFI_REST_EX_SERVICE_ACCESS_MODE AccessMode,
38 IN EFI_REST_EX_CONFIG_TYPE ConfigType,
39 IN EFI_REST_EX_SERVICE_TYPE ServiceType,
40 OUT EFI_HANDLE *ChildInstanceHandle
41 )
42{
43 EFI_STATUS Status;
44 UINTN NoBuffer;
45 EFI_HANDLE *Handle;
46 EFI_HANDLE ChildHandle;
47 EFI_REST_EX_PROTOCOL *RestEx;
48 EFI_REST_EX_SERVICE_INFO *RestExServiceInfo;
49 UINT8 LenOfConfig;
50
51 if ((Image == NULL) ||
52 (AccessMode >= EfiRestExServiceModeMax) ||
53 (ConfigType >= EfiRestExConfigTypeMax) ||
54 (ServiceType >= EfiRestExServiceTypeMax) ||
55 (ChildInstanceHandle == NULL)
56 )
57 {
58 return EFI_INVALID_PARAMETER;
59 }
60
61 *ChildInstanceHandle = NULL;
62 //
63 // Locate all REST EX binding service.
64 //
65 Handle = NULL;
66 NoBuffer = 0;
67 Status = gBS->LocateHandleBuffer (
68 ByProtocol,
69 &gEfiRestExServiceBindingProtocolGuid,
70 NULL,
71 &NoBuffer,
72 &Handle
73 );
74 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
75 return Status;
76 }
77
78 Handle = (EFI_HANDLE *)AllocateZeroPool (sizeof (EFI_HANDLE) * NoBuffer);
79 if (Handle == NULL) {
80 return EFI_OUT_OF_RESOURCES;
81 }
82
83 Status = gBS->LocateHandleBuffer (
84 ByProtocol,
85 &gEfiRestExServiceBindingProtocolGuid,
86 NULL,
87 &NoBuffer,
88 &Handle
89 );
90 if (EFI_ERROR (Status)) {
91 FreePool (Handle);
92 return Status;
93 }
94
95 //
96 // Search for the proper REST EX instance.
97 //
98 while (NoBuffer != 0) {
99 ChildHandle = NULL;
100 Status = NetLibCreateServiceChild (
101 *(Handle + (NoBuffer - 1)),
102 Image,
103 &gEfiRestExServiceBindingProtocolGuid,
104 &ChildHandle
105 );
106 if (!EFI_ERROR (Status)) {
107 Status = gBS->OpenProtocol (
108 ChildHandle,
109 &gEfiRestExProtocolGuid,
110 (VOID **)&RestEx,
111 Image,
112 NULL,
113 EFI_OPEN_PROTOCOL_GET_PROTOCOL
114 );
115 if (EFI_ERROR (Status)) {
116 goto ON_ERROR;
117 }
118
119 //
120 // Get the information of REST service provided by this EFI REST EX driver
121 //
122 Status = RestEx->GetService (
123 RestEx,
124 &RestExServiceInfo
125 );
126 if (EFI_ERROR (Status)) {
127 goto ON_ERROR;
128 }
129
130 //
131 // Check REST EX property.
132 //
133 switch (ConfigType) {
134 case EfiRestExConfigHttp:
135 LenOfConfig = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA);
136 break;
137
138 case EfiRestExConfigUnspecific:
139 LenOfConfig = REST_EX_CONFIG_DATA_LEN_UNKNOWN;
140 break;
141
142 default:
143 goto ON_ERROR;
144 }
145
146 if ((RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceAccessMode != AccessMode) ||
147 (RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType != ServiceType) ||
148 (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType != ConfigType) ||
149 ((LenOfConfig != REST_EX_CONFIG_DATA_LEN_UNKNOWN) && (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength != LenOfConfig)))
150 {
151 goto ON_ERROR;
152 }
153 }
154
155 //
156 // This is proper REST EX instance.
157 //
158 *ChildInstanceHandle = ChildHandle;
159 FreePool (Handle);
160 return EFI_SUCCESS;
161
162ON_ERROR:;
163 NetLibDestroyServiceChild (
164 *(Handle + (NoBuffer - 1)),
165 Image,
166 &gEfiRestExServiceBindingProtocolGuid,
167 ChildHandle
168 );
169 NoBuffer--;
170 }
171
172 FreePool (Handle);
173 return EFI_NOT_FOUND;
174}
Note: See TracBrowser for help on using the repository browser.

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