1 /** @file
2   The prototype of driver binding and service binding protocol for TCP driver.
3 
4   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
5 
6   This program and the accompanying materials
7   are licensed and made available under the terms and conditions of the BSD License
8   which accompanies this distribution.  The full text of the license may be found at
9   http://opensource.org/licenses/bsd-license.php.
10 
11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #ifndef _TCP_DRIVER_H_
17 #define _TCP_DRIVER_H_
18 
19 #define TCP_DRIVER_SIGNATURE   SIGNATURE_32 ('T', 'C', 'P', 'D')
20 
21 #define TCP_PORT_KNOWN         1024
22 #define TCP_PORT_USER_RESERVED 65535
23 
24 typedef struct _TCP_HEARTBEAT_TIMER {
25   EFI_EVENT  TimerEvent;
26   INTN       RefCnt;
27 } TCP_HEARTBEAT_TIMER;
28 
29 typedef struct _TCP_SERVICE_DATA {
30   UINT32                        Signature;
31   EFI_HANDLE                    ControllerHandle;
32   EFI_HANDLE                    DriverBindingHandle;
33   UINT8                         IpVersion;
34   IP_IO                         *IpIo;
35   EFI_SERVICE_BINDING_PROTOCOL  ServiceBinding;
36   LIST_ENTRY                    SocketList;
37 } TCP_SERVICE_DATA;
38 
39 typedef struct _TCP_PROTO_DATA {
40   TCP_SERVICE_DATA  *TcpService;
41   TCP_CB            *TcpPcb;
42 } TCP_PROTO_DATA;
43 
44 #define TCP_SERVICE_FROM_THIS(a) \
45   CR ( \
46   (a), \
47   TCP_SERVICE_DATA, \
48   ServiceBinding, \
49   TCP_DRIVER_SIGNATURE \
50   )
51 
52 //
53 // Function prototype for the driver's entry point
54 //
55 
56 /**
57   The entry point for Tcp driver, used to install Tcp driver on the ImageHandle.
58 
59   @param[in]  ImageHandle   The firmware allocated handle for this driver image.
60   @param[in]  SystemTable   Pointer to the EFI system table.
61 
62   @retval EFI_SUCCESS   The driver loaded.
63   @retval other         The driver did not load.
64 
65 **/
66 EFI_STATUS
67 EFIAPI
68 TcpDriverEntryPoint (
69   IN EFI_HANDLE        ImageHandle,
70   IN EFI_SYSTEM_TABLE  *SystemTable
71   );
72 
73 //
74 // Function prototypes for the Driver Binding Protocol
75 //
76 
77 /**
78   Test to see if this driver supports ControllerHandle.
79 
80   @param[in]  This                Protocol instance pointer.
81   @param[in]  ControllerHandle    Handle of the device to test.
82   @param[in]  RemainingDevicePath Optional parameter use to pick a specific
83                                   child device to start.
84 
85   @retval EFI_SUCCESS             This driver supports this device.
86   @retval EFI_ALREADY_STARTED     This driver is already running on this device.
87   @retval other                   This driver does not support this device.
88 
89 **/
90 EFI_STATUS
91 EFIAPI
92 Tcp4DriverBindingSupported (
93   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
94   IN EFI_HANDLE                   ControllerHandle,
95   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
96   );
97 
98 /**
99   Start this driver on ControllerHandle.
100 
101   @param[in]  This                   Protocol instance pointer.
102   @param[in]  ControllerHandle       Handle of device to bind driver to.
103   @param[in]  RemainingDevicePath    Optional parameter use to pick a specific child
104                                      device to start.
105 
106   @retval EFI_SUCCESS            The driver was added to ControllerHandle.
107   @retval EFI_OUT_OF_RESOURCES   There are not enough resources to start the
108                                  driver.
109   @retval other                  The driver cannot be added to ControllerHandle.
110 
111 **/
112 EFI_STATUS
113 EFIAPI
114 Tcp4DriverBindingStart (
115   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
116   IN EFI_HANDLE                   ControllerHandle,
117   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
118   );
119 
120 /**
121   Stop this driver on ControllerHandle.
122 
123   @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
124   @param[in]  ControllerHandle  A handle to the device being stopped. The handle must
125                                 support a bus specific I/O protocol for the driver
126                                 to use to stop the device.
127   @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.
128   @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL
129                                 if NumberOfChildren is 0.
130 
131   @retval EFI_SUCCESS           The device was stopped.
132   @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.
133 
134 **/
135 EFI_STATUS
136 EFIAPI
137 Tcp4DriverBindingStop (
138   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
139   IN  EFI_HANDLE                   ControllerHandle,
140   IN  UINTN                        NumberOfChildren,
141   IN  EFI_HANDLE                   *ChildHandleBuffer OPTIONAL
142   );
143 
144 /**
145   Test to see if this driver supports ControllerHandle.
146 
147   @param[in]  This                Protocol instance pointer.
148   @param[in]  ControllerHandle    Handle of the device to test.
149   @param[in]  RemainingDevicePath Optional parameter use to pick a specific
150                                   child device to start.
151 
152   @retval EFI_SUCCESS             This driver supports this device.
153   @retval EFI_ALREADY_STARTED     This driver is already running on this device.
154   @retval other                   This driver does not support this device.
155 
156 **/
157 EFI_STATUS
158 EFIAPI
159 Tcp6DriverBindingSupported (
160   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
161   IN EFI_HANDLE                   ControllerHandle,
162   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
163   );
164 
165 /**
166   Start this driver on ControllerHandle.
167 
168   @param[in]  This                   Protocol instance pointer.
169   @param[in]  ControllerHandle       Handle of device to bind driver to.
170   @param[in]  RemainingDevicePath    Optional parameter use to pick a specific child
171                                      device to start.
172 
173   @retval EFI_SUCCESS            The driver was added to ControllerHandle.
174   @retval EFI_OUT_OF_RESOURCES   There are not enough resources to start the
175                                  driver.
176   @retval other                  The driver cannot be added to ControllerHandle.
177 
178 **/
179 EFI_STATUS
180 EFIAPI
181 Tcp6DriverBindingStart (
182   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
183   IN EFI_HANDLE                   ControllerHandle,
184   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
185   );
186 
187 /**
188   Stop this driver on ControllerHandle.
189 
190   @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
191   @param[in]  ControllerHandle  A handle to the device being stopped. The handle must
192                                 support a bus specific I/O protocol for the driver
193                                 to use to stop the device.
194   @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.
195   @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL
196                                 if NumberOfChildren is 0.
197 
198   @retval EFI_SUCCESS           The device was stopped.
199   @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.
200 
201 **/
202 EFI_STATUS
203 EFIAPI
204 Tcp6DriverBindingStop (
205   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
206   IN  EFI_HANDLE                   ControllerHandle,
207   IN  UINTN                        NumberOfChildren,
208   IN  EFI_HANDLE                   *ChildHandleBuffer OPTIONAL
209   );
210 
211 /**
212   The Callback funtion called after the TCP socket is created.
213 
214   @param[in]  This            Pointer to the socket just created.
215   @param[in]  Context         The context of the socket.
216 
217   @retval EFI_SUCCESS         This protocol is installed successfully.
218   @retval other               An error occured.
219 
220 **/
221 EFI_STATUS
222 TcpCreateSocketCallback (
223   IN SOCKET  *This,
224   IN VOID    *Context
225   );
226 
227 /**
228   The callback function called before the TCP socket is to be destroyed.
229 
230   @param[in]  This                   The TCP socket to be destroyed.
231   @param[in]  Context                The context of the socket.
232 
233 **/
234 VOID
235 TcpDestroySocketCallback (
236   IN SOCKET  *This,
237   IN VOID    *Context
238   );
239 
240 //
241 // Function ptototypes for the ServiceBinding Prococol
242 //
243 
244 /**
245   Creates a child handle with a set of TCP services.
246 
247   The CreateChild() function installs a protocol on ChildHandle.
248   If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
249   If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
250 
251   @param[in]      This          Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
252   @param[in, out] ChildHandle   Pointer to the handle of the child to create.
253                                 If it is NULL, then a new handle is created.
254                                 If it is a pointer to an existing UEFI handle,
255                                 then the protocol is added to the existing UEFI handle.
256 
257   @retval EFI_SUCCES            The protocol was added to ChildHandle.
258   @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
259   @retval EFI_OUT_OF_RESOURCES  There are not enough resources available to create
260                                 the child.
261   @retval other                 The child handle was not created.
262 
263 **/
264 EFI_STATUS
265 EFIAPI
266 TcpServiceBindingCreateChild (
267   IN     EFI_SERVICE_BINDING_PROTOCOL  *This,
268   IN OUT EFI_HANDLE                    *ChildHandle
269   );
270 
271 /**
272   Destroys a child handle with a set of TCP services.
273 
274   The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
275   that was installed by CreateChild() from ChildHandle. If the removed protocol is the
276   last protocol on ChildHandle, then ChildHandle is destroyed.
277 
278   @param  This        Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
279   @param  ChildHandle Handle of the child to destroy.
280 
281   @retval EFI_SUCCES            The protocol was removed from ChildHandle.
282   @retval EFI_UNSUPPORTED       ChildHandle does not support the protocol that is being removed.
283   @retval EFI_INVALID_PARAMETER The child handle is NULL.
284   @retval EFI_ACCESS_DENIED     The protocol could not be removed from the ChildHandle
285                                 because its services are being used.
286   @retval other                 The child handle was not destroyed.
287 
288 **/
289 EFI_STATUS
290 EFIAPI
291 TcpServiceBindingDestroyChild (
292   IN EFI_SERVICE_BINDING_PROTOCOL  *This,
293   IN EFI_HANDLE                    ChildHandle
294   );
295 
296 #endif
297