1 | /** @file
|
---|
2 | This library provides help functions for REST EX Protocol.
|
---|
3 |
|
---|
4 | (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
|
---|
5 | Copyright (c) 2023, Ampere Computing LLC. All rights reserved.<BR>
|
---|
6 |
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 |
|
---|
11 | #include <Uefi.h>
|
---|
12 | #include <Library/BaseMemoryLib.h>
|
---|
13 | #include <Library/DebugLib.h>
|
---|
14 | #include <Library/MemoryAllocationLib.h>
|
---|
15 | #include <Library/NetLib.h>
|
---|
16 | #include <Library/UefiBootServicesTableLib.h>
|
---|
17 | #include <Protocol/Http.h>
|
---|
18 | #include <Protocol/RestEx.h>
|
---|
19 |
|
---|
20 | #define REST_EX_CONFIG_DATA_LEN_UNKNOWN 0xff
|
---|
21 |
|
---|
22 | /**
|
---|
23 | This function allows the caller to create child handle for specific
|
---|
24 | REST server.
|
---|
25 |
|
---|
26 | @param[in] Controller The controller handle used of selected interface.
|
---|
27 | @param[in] Image The image handle used to open service.
|
---|
28 | @param[in] AccessMode Access mode of REST server.
|
---|
29 | @param[in] ConfigType Underlying configuration to communicate with REST server.
|
---|
30 | @param[in] ServiceType REST service type.
|
---|
31 | @param[out] ChildInstanceHandle The handle to receive the create child.
|
---|
32 |
|
---|
33 | @retval EFI_SUCCESS Can't create the corresponding REST EX child instance.
|
---|
34 | @retval EFI_INVALID_PARAMETERS Any of input parameters is improper.
|
---|
35 |
|
---|
36 | **/
|
---|
37 | EFI_STATUS
|
---|
38 | RestExLibCreateChild (
|
---|
39 | IN EFI_HANDLE Controller,
|
---|
40 | IN EFI_HANDLE Image,
|
---|
41 | IN EFI_REST_EX_SERVICE_ACCESS_MODE AccessMode,
|
---|
42 | IN EFI_REST_EX_CONFIG_TYPE ConfigType,
|
---|
43 | IN EFI_REST_EX_SERVICE_TYPE ServiceType,
|
---|
44 | OUT EFI_HANDLE *ChildInstanceHandle
|
---|
45 | )
|
---|
46 | {
|
---|
47 | EFI_STATUS Status;
|
---|
48 | EFI_HANDLE ChildHandle;
|
---|
49 | EFI_REST_EX_PROTOCOL *RestEx;
|
---|
50 | EFI_REST_EX_SERVICE_INFO *RestExServiceInfo;
|
---|
51 | UINT8 LenOfConfig;
|
---|
52 |
|
---|
53 | if ((Image == NULL) ||
|
---|
54 | (AccessMode >= EfiRestExServiceModeMax) ||
|
---|
55 | (ConfigType >= EfiRestExConfigTypeMax) ||
|
---|
56 | (ServiceType >= EfiRestExServiceTypeMax) ||
|
---|
57 | (ChildInstanceHandle == NULL)
|
---|
58 | )
|
---|
59 | {
|
---|
60 | return EFI_INVALID_PARAMETER;
|
---|
61 | }
|
---|
62 |
|
---|
63 | *ChildInstanceHandle = NULL;
|
---|
64 |
|
---|
65 | ChildHandle = NULL;
|
---|
66 | Status = NetLibCreateServiceChild (
|
---|
67 | Controller,
|
---|
68 | Image,
|
---|
69 | &gEfiRestExServiceBindingProtocolGuid,
|
---|
70 | &ChildHandle
|
---|
71 | );
|
---|
72 | if (EFI_ERROR (Status)) {
|
---|
73 | DEBUG ((
|
---|
74 | DEBUG_ERROR,
|
---|
75 | "%a: Failed to create service child - %r \n",
|
---|
76 | __func__,
|
---|
77 | Status
|
---|
78 | ));
|
---|
79 | return Status;
|
---|
80 | }
|
---|
81 |
|
---|
82 | Status = gBS->OpenProtocol (
|
---|
83 | ChildHandle,
|
---|
84 | &gEfiRestExProtocolGuid,
|
---|
85 | (VOID **)&RestEx,
|
---|
86 | Image,
|
---|
87 | NULL,
|
---|
88 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
---|
89 | );
|
---|
90 | if (EFI_ERROR (Status)) {
|
---|
91 | goto ON_ERROR;
|
---|
92 | }
|
---|
93 |
|
---|
94 | //
|
---|
95 | // Get the information of REST service provided by this EFI REST EX driver
|
---|
96 | //
|
---|
97 | Status = RestEx->GetService (
|
---|
98 | RestEx,
|
---|
99 | &RestExServiceInfo
|
---|
100 | );
|
---|
101 | if (EFI_ERROR (Status)) {
|
---|
102 | goto ON_ERROR;
|
---|
103 | }
|
---|
104 |
|
---|
105 | //
|
---|
106 | // Check REST EX property.
|
---|
107 | //
|
---|
108 | switch (ConfigType) {
|
---|
109 | case EfiRestExConfigHttp:
|
---|
110 | LenOfConfig = sizeof (EFI_REST_EX_HTTP_CONFIG_DATA);
|
---|
111 | break;
|
---|
112 |
|
---|
113 | case EfiRestExConfigUnspecific:
|
---|
114 | LenOfConfig = REST_EX_CONFIG_DATA_LEN_UNKNOWN;
|
---|
115 | break;
|
---|
116 |
|
---|
117 | default:
|
---|
118 | goto ON_ERROR;
|
---|
119 | }
|
---|
120 |
|
---|
121 | if ((RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceAccessMode != AccessMode) ||
|
---|
122 | (RestExServiceInfo->EfiRestExServiceInfoV10.RestServiceType != ServiceType) ||
|
---|
123 | (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigType != ConfigType) ||
|
---|
124 | ((LenOfConfig != REST_EX_CONFIG_DATA_LEN_UNKNOWN) && (RestExServiceInfo->EfiRestExServiceInfoV10.RestExConfigDataLength != LenOfConfig)))
|
---|
125 | {
|
---|
126 | goto ON_ERROR;
|
---|
127 | }
|
---|
128 |
|
---|
129 | //
|
---|
130 | // This is proper REST EX instance.
|
---|
131 | //
|
---|
132 | *ChildInstanceHandle = ChildHandle;
|
---|
133 | return EFI_SUCCESS;
|
---|
134 |
|
---|
135 | ON_ERROR:;
|
---|
136 | NetLibDestroyServiceChild (
|
---|
137 | Controller,
|
---|
138 | Image,
|
---|
139 | &gEfiRestExServiceBindingProtocolGuid,
|
---|
140 | ChildHandle
|
---|
141 | );
|
---|
142 | return EFI_NOT_FOUND;
|
---|
143 | }
|
---|