1 /** @file
2   RedfishRestExDxe support functions definitions.
3 
4   Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5   (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
6 
7   SPDX-License-Identifier: BSD-2-Clause-Patent
8 
9 **/
10 
11 #ifndef EFI_REDFISH_RESTEX_DRIVER_H_
12 #define EFI_REDFISH_RESTEX_DRIVER_H_
13 
14 ///
15 /// Libraries classes
16 ///
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/DevicePathLib.h>
21 #include <Library/HttpIoLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/NetLib.h>
24 #include <Library/UefiLib.h>
25 #include <Library/UefiBootServicesTableLib.h>
26 #include <Library/UefiDriverEntryPoint.h>
27 
28 ///
29 /// UEFI Driver Model Protocols
30 ///
31 #include <Protocol/DriverBinding.h>
32 #include <Protocol/RestEx.h>
33 #include <Protocol/ServiceBinding.h>
34 
35 ///
36 /// Protocol instances
37 ///
enter_context(MPL * mpl)38 extern EFI_COMPONENT_NAME_PROTOCOL   gRedfishRestExComponentName;
39 extern EFI_COMPONENT_NAME2_PROTOCOL  gRedfishRestExComponentName2;
40 extern EFI_UNICODE_STRING_TABLE      *gRedfishRestExControllerNameTable;
41 
42 extern EFI_DRIVER_BINDING_PROTOCOL   gRedfishRestExDriverBinding;
43 extern EFI_SERVICE_BINDING_PROTOCOL  mRedfishRestExServiceBinding;
44 extern EFI_REST_EX_PROTOCOL          mRedfishRestExProtocol;
45 ///
46 /// RestEx service block
47 ///
48 typedef struct _RESTEX_SERVICE  RESTEX_SERVICE;
49 
50 ///
51 /// RestEx instance block
52 ///
53 typedef struct _RESTEX_INSTANCE RESTEX_INSTANCE;
54 
55 ///
56 /// Driver Version
57 ///
58 #define REDFISH_RESTEX_DRIVER_VERSION  0x0100
59 
60 #define RESTEX_SERVICE_SIGNATURE    SIGNATURE_32 ('R', 'E', 'S', 'S')
print_context(MPL * mpl)61 #define RESTEX_INSTANCE_SIGNATURE   SIGNATURE_32 ('R', 'E', 'I', 'S')
62 
63 #define RESTEX_SERVICE_FROM_THIS(a)   \
64   CR (a, RESTEX_SERVICE, ServiceBinding, RESTEX_SERVICE_SIGNATURE)
65 
66 #define RESTEX_INSTANCE_FROM_THIS(a)  \
67   CR (a, RESTEX_INSTANCE, RestEx, RESTEX_INSTANCE_SIGNATURE)
68 
69 
70 #define RESTEX_STATE_UNCONFIGED     0
71 #define RESTEX_STATE_CONFIGED       1
72 
73 struct _RESTEX_SERVICE {
74   UINT32                        Signature;
75   EFI_SERVICE_BINDING_PROTOCOL  ServiceBinding;
76 
77   UINT16                        RestExChildrenNum;
78   LIST_ENTRY                    RestExChildrenList;
79 
80   EFI_HANDLE                    ControllerHandle;
81   EFI_HANDLE                    ImageHandle;
82 
83   //
84   // Use to establish the parent-child relationship.
85   //
86   EFI_HANDLE                    HttpChildHandle;
87 
88   UINT32                        Id;
89 
90   EFI_REST_EX_SERVICE_INFO      RestExServiceInfo;
91 };
92 
93 #define RESTEX_INSTANCE_FLAGS_TLS_RETRY       0x00000001
94 #define RESTEX_INSTANCE_FLAGS_TCP_ERROR_RETRY 0x00000002
95 
96 struct _RESTEX_INSTANCE {
97   UINT32                        Signature;
98   LIST_ENTRY                    Link;
99 
100   EFI_REST_EX_PROTOCOL          RestEx;
101 
102   INTN                          State;
103   BOOLEAN                       InDestroy;
104 
105   RESTEX_SERVICE                *Service;
106   EFI_HANDLE                    ChildHandle;
107 
108   EFI_REST_EX_CONFIG_DATA       ConfigData;
append_char(MPL * mpl)109 
110   //
111   // HTTP_IO to access the HTTP service
112   //
113   HTTP_IO                       HttpIo;
114 
115   UINT32                        Flags;
116 };
117 
118 typedef struct {
119   EFI_SERVICE_BINDING_PROTOCOL  *ServiceBinding;
120   UINTN                         NumberOfChildren;
121   EFI_HANDLE                    *ChildHandleBuffer;
122 } RESTEX_DESTROY_CHILD_IN_HANDLE_BUF_CONTEXT;
123 
124 /**
125   Provides a simple HTTP-like interface to send and receive resources from a REST service.
126 
127   The SendReceive() function sends an HTTP request to this REST service, and returns a
128   response when the data is retrieved from the service. RequestMessage contains the HTTP
129   request to the REST resource identified by RequestMessage.Request.Url. The
130   ResponseMessage is the returned HTTP response for that request, including any HTTP
131   status.
132 
133   @param[in]  This                Pointer to EFI_REST_EX_PROTOCOL instance for a particular
134                                   REST service.
135   @param[in]  RequestMessage      Pointer to the HTTP request data for this resource
136   @param[out] ResponseMessage     Pointer to the HTTP response data obtained for this requested.
137 
138   @retval EFI_SUCCESS             operation succeeded.
139   @retval EFI_INVALID_PARAMETER   This, RequestMessage, or ResponseMessage are NULL.
140   @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred.
get_token(MPL * mpl)141 
142 **/
143 EFI_STATUS
144 EFIAPI
145 RedfishRestExSendReceive (
146   IN      EFI_REST_EX_PROTOCOL   *This,
147   IN      EFI_HTTP_MESSAGE       *RequestMessage,
148   OUT     EFI_HTTP_MESSAGE       *ResponseMessage
149   );
150 
151 /**
152   Obtain the current time from this REST service instance.
153 
154   The GetServiceTime() function is an optional interface to obtain the current time from
155   this REST service instance. If this REST service does not support to retrieve the time,
156   this function returns EFI_UNSUPPORTED. This function must returns EFI_UNSUPPORTED if
157   EFI_REST_EX_SERVICE_TYPE returned in EFI_REST_EX_SERVICE_INFO from GetService() is
158   EFI_REST_EX_SERVICE_UNSPECIFIC.
159 
160   @param[in]  This                Pointer to EFI_REST_EX_PROTOCOL instance for a particular
161                                   REST service.
162   @param[out] Time                A pointer to storage to receive a snapshot of the current time of
163                                   the REST service.
164 
165   @retval EFI_SUCCESS             operation succeeded.
166   @retval EFI_INVALID_PARAMETER   This or Time are NULL.
167   @retval EFI_UNSUPPORTED         The RESTful service does not support returning the time.
168   @retval EFI_DEVICE_ERROR        An unexpected system or network error occurred.
169   @retval EFI_NOT_READY           The configuration of this instance is not set yet. Configure() must
170                                   be executed and returns successfully prior to invoke this function.
171 
172 **/
173 EFI_STATUS
174 EFIAPI
175 RedfishRestExGetServiceTime (
176   IN      EFI_REST_EX_PROTOCOL   *This,
177   OUT     EFI_TIME               *Time
178   );
179 
180 /**
181   This function returns the information of REST service provided by this EFI REST EX driver instance.
182 
183   The information such as the type of REST service and the access mode of REST EX driver instance
184   (In-band or Out-of-band) are described in EFI_REST_EX_SERVICE_INFO structure. For the vendor-specific
185   REST service, vendor-specific REST service information is returned in VendorSpecifcData.
186   REST EX driver designer is well know what REST service this REST EX driver instance intends to
187   communicate with. The designer also well know this driver instance is used to talk to BMC through
188   specific platform mechanism or talk to REST server through UEFI HTTP protocol. REST EX driver is
189   responsible to fill up the correct information in EFI_REST_EX_SERVICE_INFO. EFI_REST_EX_SERVICE_INFO
190   is referred by EFI REST clients to pickup the proper EFI REST EX driver instance to get and set resource.
191   GetService() is a basic and mandatory function which must be able to use even Configure() is not invoked
192   in previously.
193 
194   @param[in]  This                Pointer to EFI_REST_EX_PROTOCOL instance for a particular
195                                   REST service.
196   @param[out] RestExServiceInfo   Pointer to receive a pointer to EFI_REST_EX_SERVICE_INFO structure. The
197                                   format of EFI_REST_EX_SERVICE_INFO is version controlled for the future
198                                   extension. The version of EFI_REST_EX_SERVICE_INFO structure is returned
199                                   in the header within this structure. EFI REST client refers to the correct
200                                   format of structure according to the version number. The pointer to
201                                   EFI_REST_EX_SERVICE_INFO is a memory block allocated by EFI REST EX driver
202                                   instance. That is caller's responsibility to free this memory when this
203                                   structure is no longer needed. Refer to Related Definitions below for the
204                                   definitions of EFI_REST_EX_SERVICE_INFO structure.
205 
206   @retval EFI_SUCCESS             EFI_REST_EX_SERVICE_INFO is returned in RestExServiceInfo. This function
207                                   is not supported in this REST EX Protocol driver instance.
208   @retval EFI_UNSUPPORTED         This function is not supported in this REST EX Protocol driver instance.
209 
210 **/
211 EFI_STATUS
212 EFIAPI
213 RedfishRestExGetService (
214   IN   EFI_REST_EX_PROTOCOL      *This,
215   OUT  EFI_REST_EX_SERVICE_INFO  **RestExServiceInfo
216   );
217 
218 /**
219   This function returns operational configuration of current EFI REST EX child instance.
220 
221   This function returns the current configuration of EFI REST EX child instance. The format of
222   operational configuration depends on the implementation of EFI REST EX driver instance. For
223   example, HTTP-aware EFI REST EX driver instance uses EFI HTTP protocol as the undying protocol
224   to communicate with REST service. In this case, the type of configuration is
225   EFI_REST_EX_CONFIG_TYPE_HTTP returned from GetService(). EFI_HTTP_CONFIG_DATA is used as EFI REST
226   EX configuration format and returned to EFI REST client. User has to type cast RestExConfigData
227   to EFI_HTTP_CONFIG_DATA. For those non HTTP-aware REST EX driver instances, the type of configuration
228   is EFI_REST_EX_CONFIG_TYPE_UNSPECIFIC returned from GetService(). In this case, the format of
229   returning data could be non industrial. Instead, the format of configuration data is system/platform
230   specific definition such as BMC mechanism used in EFI REST EX driver instance. EFI REST client and
231   EFI REST EX driver instance have to refer to the specific system /platform spec which is out of UEFI scope.
232 
233   @param[in]  This                This is the EFI_REST_EX_PROTOCOL instance.
234   @param[out] RestExConfigData    Pointer to receive a pointer to EFI_REST_EX_CONFIG_DATA.
235                                   The memory allocated for configuration data should be freed
236                                   by caller. See Related Definitions for the details.
237 
238   @retval EFI_SUCCESS             EFI_REST_EX_CONFIG_DATA is returned in successfully.
239   @retval EFI_UNSUPPORTED         This function is not supported in this REST EX Protocol driver instance.
240   @retval EFI_NOT_READY           The configuration of this instance is not set yet. Configure() must be
241                                   executed and returns successfully prior to invoke this function.
242 
243 **/
244 EFI_STATUS
245 EFIAPI
246 RedfishRestExGetModeData (
247   IN  EFI_REST_EX_PROTOCOL      *This,
248   OUT EFI_REST_EX_CONFIG_DATA   *RestExConfigData
249   );
250 
251 /**
252   This function is used to configure EFI REST EX child instance.
253 
254   This function is used to configure the setting of underlying protocol of REST EX child
255   instance. The type of configuration is according to the implementation of EFI REST EX
256   driver instance. For example, HTTP-aware EFI REST EX driver instance uses EFI HTTP protocol
257   as the undying protocol to communicate with REST service. The type of configuration is
258   EFI_REST_EX_CONFIG_TYPE_HTTP and RestExConfigData is the same format with EFI_HTTP_CONFIG_DATA.
259   Akin to HTTP configuration, REST EX child instance can be configure to use different HTTP
260   local access point for the data transmission. Multiple REST clients may use different
261   configuration of HTTP to distinguish themselves, such as to use the different TCP port.
262   For those non HTTP-aware REST EX driver instance, the type of configuration is
263   EFI_REST_EX_CONFIG_TYPE_UNSPECIFIC. RestExConfigData refers to the non industrial standard.
264   Instead, the format of configuration data is system/platform specific definition such as BMC.
265   In this case, EFI REST client and EFI REST EX driver instance have to refer to the specific
266   system/platform spec which is out of the UEFI scope. Besides GetService()function, no other
267   EFI REST EX functions can be executed by this instance until Configure()is executed and returns
268   successfully. All other functions must returns EFI_NOT_READY if this instance is not configured
269   yet. Set RestExConfigData to NULL means to put EFI REST EX child instance into the unconfigured
270   state.
271 
272   @param[in]  This                This is the EFI_REST_EX_PROTOCOL instance.
273   @param[in]  RestExConfigData    Pointer to EFI_REST_EX_CONFIG_DATA. See Related Definitions in
274                                   GetModeData() protocol interface.
275 
276   @retval EFI_SUCCESS             EFI_REST_EX_CONFIG_DATA is set in successfully.
277   @retval EFI_DEVICE_ERROR        Configuration for this REST EX child instance is failed with the given
278                                   EFI_REST_EX_CONFIG_DATA.
279   @retval EFI_UNSUPPORTED         This function is not supported in this REST EX Protocol driver instance.
280 
281 **/
282 EFI_STATUS
283 EFIAPI
284 RedfishRestExConfigure (
285   IN  EFI_REST_EX_PROTOCOL    *This,
286   IN  EFI_REST_EX_CONFIG_DATA RestExConfigData
287   );
288 
289 /**
290   This function sends REST request to REST service and signal caller's event asynchronously when
291   the final response is received by REST EX Protocol driver instance.
292 
293   The essential design of this function is to handle asynchronous send/receive implicitly according
294   to REST service asynchronous request mechanism. Caller will get the notification once the response
295   is returned from REST service.
296 
297   @param[in]  This                  This is the EFI_REST_EX_PROTOCOL instance.
298   @param[in]  RequestMessage        This is the HTTP request message sent to REST service. Set RequestMessage
299                                     to NULL to cancel the previous asynchronous request associated with the
300                                     corresponding RestExToken. See descriptions for the details.
301   @param[in]  RestExToken           REST EX token which REST EX Protocol instance uses to notify REST client
302                                     the status of response of asynchronous REST request. See related definition
303                                     of EFI_REST_EX_TOKEN.
304   @param[in]  TimeOutInMilliSeconds The pointer to the timeout in milliseconds which REST EX Protocol driver
305                                     instance refers as the duration to drop asynchronous REST request. NULL
306                                     pointer means no timeout for this REST request. REST EX Protocol driver
307                                     signals caller's event with EFI_STATUS set to EFI_TIMEOUT in RestExToken
308                                     if REST EX Protocol can't get the response from REST service within
309                                     TimeOutInMilliSeconds.
310 
311   @retval EFI_SUCCESS               Asynchronous REST request is established.
312   @retval EFI_UNSUPPORTED           This REST EX Protocol driver instance doesn't support asynchronous request.
313   @retval EFI_TIMEOUT               Asynchronous REST request is not established and timeout is expired.
314   @retval EFI_ABORT                 Previous asynchronous REST request has been canceled.
315   @retval EFI_DEVICE_ERROR          Otherwise, returns EFI_DEVICE_ERROR for other errors according to HTTP Status Code.
316   @retval EFI_NOT_READY             The configuration of this instance is not set yet. Configure() must be executed
317                                     and returns successfully prior to invoke this function.
318 
319 **/
320 EFI_STATUS
321 EFIAPI
322 RedfishRestExAyncSendReceive (
323   IN      EFI_REST_EX_PROTOCOL   *This,
324   IN      EFI_HTTP_MESSAGE       *RequestMessage OPTIONAL,
325   IN      EFI_REST_EX_TOKEN      *RestExToken,
326   IN      UINTN                  *TimeOutInMilliSeconds OPTIONAL
327   );
328 
329 /**
330   This function sends REST request to a REST Event service and signals caller's event
331   token asynchronously when the URI resource change event is received by REST EX
332   Protocol driver instance.
333 
334   The essential design of this function is to monitor event implicitly according to
335   REST service event service mechanism. Caller will get the notification if certain
336   resource is changed.
337 
338   @param[in]  This                  This is the EFI_REST_EX_PROTOCOL instance.
339   @param[in]  RequestMessage        This is the HTTP request message sent to REST service. Set RequestMessage
340                                     to NULL to cancel the previous event service associated with the corresponding
341                                     RestExToken. See descriptions for the details.
342   @param[in]  RestExToken           REST EX token which REST EX Protocol driver instance uses to notify REST client
343                                     the URI resource which monitored by REST client has been changed. See the related
344                                     definition of EFI_REST_EX_TOKEN in EFI_REST_EX_PROTOCOL.AsyncSendReceive().
345 
346   @retval EFI_SUCCESS               Asynchronous REST request is established.
347   @retval EFI_UNSUPPORTED           This REST EX Protocol driver instance doesn't support asynchronous request.
348   @retval EFI_ABORT                 Previous asynchronous REST request has been canceled or event subscription has been
349                                     delete from service.
350   @retval EFI_DEVICE_ERROR          Otherwise, returns EFI_DEVICE_ERROR for other errors according to HTTP Status Code.
351   @retval EFI_NOT_READY             The configuration of this instance is not set yet. Configure() must be executed
352                                     and returns successfully prior to invoke this function.
353 
354 **/
355 EFI_STATUS
356 EFIAPI
357 RedfishRestExEventService (
358   IN      EFI_REST_EX_PROTOCOL   *This,
359   IN      EFI_HTTP_MESSAGE       *RequestMessage OPTIONAL,
360   IN      EFI_REST_EX_TOKEN      *RestExToken
361   );
362 /**
363   Create a new TLS session becuase the previous on is closed.
364   status.
365 
366   @param[in]  Instance            Pointer to EFI_REST_EX_PROTOCOL instance for a particular
367                                   REST service.
368   @retval EFI_SUCCESS             operation succeeded.
369   @retval EFI Errors              Other errors.
370 
371 **/
372 EFI_STATUS
373 ResetHttpTslSession (
374   IN   RESTEX_INSTANCE  *Instance
375 );
376 
377 
378 /**
379   Callback function which provided by user to remove one node in NetDestroyLinkList process.
380 
381   @param[in]    Entry           The entry to be removed.
382   @param[in]    Context         Pointer to the callback context corresponds to the Context in NetDestroyLinkList.
383 
384   @retval EFI_SUCCESS           The entry has been removed successfully.
385   @retval Others                Fail to remove the entry.
386 
387 **/
388 EFI_STATUS
389 EFIAPI
390 RestExDestroyChildEntryInHandleBuffer (
391   IN LIST_ENTRY         *Entry,
392   IN VOID               *Context
393   );
394 
395 /**
396   Destroy the RestEx instance and recycle the resources.
397 
398   @param[in]  Instance        The pointer to the RestEx instance.
399 
400 **/
401 VOID
402 RestExDestroyInstance (
403   IN RESTEX_INSTANCE         *Instance
404   );
405 
406 /**
407   Create the RestEx instance and initialize it.
408 
409   @param[in]  Service              The pointer to the RestEx service.
410   @param[out] Instance             The pointer to the RestEx instance.
411 
412   @retval EFI_OUT_OF_RESOURCES   Failed to allocate resources.
413   @retval EFI_SUCCESS            The RestEx instance is created.
414 
415 **/
416 EFI_STATUS
417 RestExCreateInstance (
418   IN  RESTEX_SERVICE         *Service,
419   OUT RESTEX_INSTANCE        **Instance
420   );
421 
422 
423 /**
424   Release all the resource used the RestEx service binding instance.
425 
426   @param  RestExSb                The RestEx service binding instance.
427 
428 **/
429 VOID
430 RestExDestroyService (
431   IN RESTEX_SERVICE     *RestExSb
432   );
433 
434 /**
435   Create then initialize a RestEx service binding instance.
436 
unget_token(MPL * mpl)437   @param[in]   Controller       The controller to install the RestEx service
438                                 binding on.
439   @param[in]   Image            The driver binding image of the RestEx driver.
440   @param[out]  Service          The variable to receive the created service
441                                 binding instance.
442 
443   @retval EFI_OUT_OF_RESOURCES   Failed to allocate resource to create the instance.
444   @retval EFI_SUCCESS            The service instance is created for the controller.
445 
446 **/
447 EFI_STATUS
448 RestExCreateService (
449   IN     EFI_HANDLE            Controller,
450   IN     EFI_HANDLE            Image,
451   OUT    RESTEX_SERVICE        **Service
452   );
453 
454 /**
455   This is the declaration of an EFI image entry point. This entry point is
456   the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
457   both device drivers and bus drivers.
458 
is_keyword(MPL * mpl,char * keyword)459   @param[in]   ImageHandle     The firmware allocated handle for the UEFI image.
460   @param[in]   SystemTable     A pointer to the EFI System Table.
461 
462   @retval EFI_SUCCESS           The operation completed successfully.
463   @retval Others                An unexpected error occurred.
464 **/
465 EFI_STATUS
466 EFIAPI
467 RedfishRestExDriverEntryPoint (
468   IN EFI_HANDLE        ImageHandle,
469   IN EFI_SYSTEM_TABLE  *SystemTable
470   );
471 
472 /**
473   Tests to see if this driver supports a given controller. If a child device is provided,
474   it further tests to see if this driver supports creating a handle for the specified child device.
475 
476   This function checks to see if the driver specified by This supports the device specified by
477   ControllerHandle. Drivers will typically use the device path attached to
478   ControllerHandle and/or the services from the bus I/O abstraction attached to
479   ControllerHandle to determine if the driver supports ControllerHandle. This function
480   may be called many times during platform initialization. In order to reduce boot times, the tests
481   performed by this function must be very small, and take as little time as possible to execute. This
482   function must not change the state of any hardware devices, and this function must be aware that the
483   device specified by ControllerHandle may already be managed by the same driver or a
484   different driver. This function must match its calls to AllocatePages() with FreePages(),
485   AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
486   Because ControllerHandle may have been previously started by the same driver, if a protocol is
487   already in the opened state, then it must not be closed with CloseProtocol(). This is required
488   to guarantee the state of ControllerHandle is not modified by this function.
489 
490   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
491   @param[in]  ControllerHandle     The handle of the controller to test. This handle
492                                    must support a protocol interface that supplies
493                                    an I/O abstraction to the driver.
494   @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This
495                                    parameter is ignored by device drivers, and is optional for bus
496                                    drivers. For bus drivers, if this parameter is not NULL, then
make_code(MPL * mpl,int op,OPERANDS * arg,int type,int dim)497                                    the bus driver must determine if the bus controller specified
498                                    by ControllerHandle and the child controller specified
499                                    by RemainingDevicePath are both supported by this
500                                    bus driver.
501 
502   @retval EFI_SUCCESS              The device specified by ControllerHandle and
503                                    RemainingDevicePath is supported by the driver specified by This.
504   @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and
505                                    RemainingDevicePath is already being managed by the driver
506                                    specified by This.
507   @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and
508                                    RemainingDevicePath is already being managed by a different
509                                    driver or an application that requires exclusive access.
510                                    Currently not implemented.
511   @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and
512                                    RemainingDevicePath is not supported by the driver specified by This.
513 **/
514 EFI_STATUS
515 EFIAPI
516 RedfishRestExDriverBindingSupported (
517   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
518   IN EFI_HANDLE                   ControllerHandle,
519   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
520   );
521 
522 /**
523   Starts a device controller or a bus controller.
524 
525   The Start() function is designed to be invoked from the EFI boot service ConnectController().
526   As a result, much of the error checking on the parameters to Start() has been moved into this
527   common boot service. It is legal to call Start() from other locations,
528   but the following calling restrictions must be followed, or the system behavior will not be deterministic.
529   1. ControllerHandle must be a valid EFI_HANDLE.
530   2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
531      EFI_DEVICE_PATH_PROTOCOL.
532   3. Prior to calling Start(), the Supported() function for the driver specified by This must
533      have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
534 
535   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
536   @param[in]  ControllerHandle     The handle of the controller to start. This handle
537                                    must support a protocol interface that supplies
538                                    an I/O abstraction to the driver.
539   @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This
540                                    parameter is ignored by device drivers, and is optional for bus
541                                    drivers. For a bus driver, if this parameter is NULL, then handles
542                                    for all the children of Controller are created by this driver.
543                                    If this parameter is not NULL and the first Device Path Node is
544                                    not the End of Device Path Node, then only the handle for the
545                                    child device specified by the first Device Path Node of
546                                    RemainingDevicePath is created by this driver.
547                                    If the first Device Path Node of RemainingDevicePath is
548                                    the End of Device Path Node, no child handle is created by this
549                                    driver.
550 
551   @retval EFI_SUCCESS              The device was started.
552   @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.
553   @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.
554   @retval Others                   The driver failded to start the device.
555 
556 **/
557 EFI_STATUS
558 EFIAPI
559 RedfishRestExDriverBindingStart (
560   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
561   IN EFI_HANDLE                   ControllerHandle,
562   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
563   );
564 
565 /**
566   Stops a device controller or a bus controller.
567 
568   The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
569   As a result, much of the error checking on the parameters to Stop() has been moved
570   into this common boot service. It is legal to call Stop() from other locations,
571   but the following calling restrictions must be followed, or the system behavior will not be deterministic.
572   1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
573      same driver's Start() function.
574   2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
575      EFI_HANDLE. In addition, all of these handles must have been created in this driver's
576      Start() function, and the Start() function must have called OpenProtocol() on
577      ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
578 
579   @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
580   @param[in]  ControllerHandle  A handle to the device being stopped. The handle must
581                                 support a bus specific I/O protocol for the driver
582                                 to use to stop the device.
583   @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.
584   @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL
585                                 if NumberOfChildren is 0.
586 
587   @retval EFI_SUCCESS           The device was stopped.
588   @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.
589 
590 **/
591 EFI_STATUS
592 EFIAPI
593 RedfishRestExDriverBindingStop (
594   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
595   IN EFI_HANDLE                   ControllerHandle,
596   IN UINTN                        NumberOfChildren,
597   IN EFI_HANDLE                   *ChildHandleBuffer OPTIONAL
598   );
599 
600 /**
601   Creates a child handle and installs a protocol.
602 
603   The CreateChild() function installs a protocol on ChildHandle.
604   If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
605   If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
606 
607   @param[in] This        Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
608   @param[in] ChildHandle Pointer to the handle of the child to create. If it is NULL,
609                          then a new handle is created. If it is a pointer to an existing UEFI handle,
610                          then the protocol is added to the existing UEFI handle.
611 
612   @retval EFI_SUCCES            The protocol was added to ChildHandle.
613   @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
614   @retval EFI_OUT_OF_RESOURCES  There are not enough resources available to create
615                                 the child
616   @retval other                 The child handle was not created
617 
618 **/
619 EFI_STATUS
620 EFIAPI
621 RedfishRestExServiceBindingCreateChild (
622   IN EFI_SERVICE_BINDING_PROTOCOL  *This,
623   IN EFI_HANDLE                    *ChildHandle
624   );
625 
626 /**
627   Destroys a child handle with a protocol installed on it.
628 
629   The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
630   that was installed by CreateChild() from ChildHandle. If the removed protocol is the
631   last protocol on ChildHandle, then ChildHandle is destroyed.
632 
633   @param[in] This        Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
634   @param[in] ChildHandle Handle of the child to destroy
635 
636   @retval EFI_SUCCES            The protocol was removed from ChildHandle.
637   @retval EFI_UNSUPPORTED       ChildHandle does not support the protocol that is being removed.
638   @retval EFI_INVALID_PARAMETER Child handle is NULL.
639   @retval EFI_ACCESS_DENIED     The protocol could not be removed from the ChildHandle
640                                 because its services are being used.
641   @retval other                 The child handle was not destroyed
642 
643 **/
644 EFI_STATUS
645 EFIAPI
646 RedfishRestExServiceBindingDestroyChild (
647   IN EFI_SERVICE_BINDING_PROTOCOL  *This,
648   IN EFI_HANDLE                    ChildHandle
649   );
650 #endif
651