]>
Commit | Line | Data |
---|---|---|
8a67d61d | 1 | /** @file\r |
dab714aa | 2 | Tcp driver function.\r |
8a67d61d | 3 | \r |
fb115c61 | 4 | Copyright (c) 2005 - 2009, Intel Corporation<BR>\r |
8a67d61d | 5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
dfc1f033 | 8 | http://opensource.org/licenses/bsd-license.php<BR>\r |
8a67d61d | 9 | \r |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
8a67d61d | 13 | **/\r |
14 | \r | |
15 | #include "Tcp4Main.h"\r | |
16 | \r | |
17 | \r | |
120db52c | 18 | UINT16 mTcp4RandomPort;\r |
83cbd279 | 19 | extern EFI_COMPONENT_NAME_PROTOCOL gTcp4ComponentName;\r |
20 | extern EFI_COMPONENT_NAME2_PROTOCOL gTcp4ComponentName2;\r | |
8a67d61d | 21 | \r |
22 | TCP4_HEARTBEAT_TIMER mTcp4Timer = {\r | |
23 | NULL,\r | |
24 | 0\r | |
25 | };\r | |
26 | \r | |
27 | EFI_TCP4_PROTOCOL mTcp4ProtocolTemplate = {\r | |
28 | Tcp4GetModeData,\r | |
29 | Tcp4Configure,\r | |
30 | Tcp4Routes,\r | |
31 | Tcp4Connect,\r | |
32 | Tcp4Accept,\r | |
33 | Tcp4Transmit,\r | |
34 | Tcp4Receive,\r | |
35 | Tcp4Close,\r | |
36 | Tcp4Cancel,\r | |
37 | Tcp4Poll\r | |
38 | };\r | |
39 | \r | |
40 | SOCK_INIT_DATA mTcp4DefaultSockData = {\r | |
f6b7393c | 41 | SockStream,\r |
42 | 0,\r | |
8a67d61d | 43 | NULL,\r |
44 | TCP_BACKLOG,\r | |
45 | TCP_SND_BUF_SIZE,\r | |
46 | TCP_RCV_BUF_SIZE,\r | |
47 | &mTcp4ProtocolTemplate,\r | |
4f6e31e4 | 48 | Tcp4CreateSocketCallback,\r |
49 | Tcp4DestroySocketCallback,\r | |
50 | NULL,\r | |
51 | NULL,\r | |
52 | 0,\r | |
8a67d61d | 53 | Tcp4Dispatcher,\r |
54 | NULL,\r | |
55 | };\r | |
56 | \r | |
57 | EFI_DRIVER_BINDING_PROTOCOL mTcp4DriverBinding = {\r | |
58 | Tcp4DriverBindingSupported,\r | |
59 | Tcp4DriverBindingStart,\r | |
60 | Tcp4DriverBindingStop,\r | |
61 | 0xa,\r | |
62 | NULL,\r | |
63 | NULL\r | |
64 | };\r | |
65 | \r | |
66 | EFI_SERVICE_BINDING_PROTOCOL mTcp4ServiceBinding = {\r | |
67 | Tcp4ServiceBindingCreateChild,\r | |
68 | Tcp4ServiceBindingDestroyChild\r | |
69 | };\r | |
70 | \r | |
71 | \r | |
72 | /**\r | |
73 | Create and start the heartbeat timer for TCP driver.\r | |
74 | \r | |
8a67d61d | 75 | @retval EFI_SUCCESS The timer is successfully created and started.\r |
76 | @retval other The timer is not created.\r | |
77 | \r | |
78 | **/\r | |
8a67d61d | 79 | EFI_STATUS\r |
80 | Tcp4CreateTimer (\r | |
81 | VOID\r | |
82 | )\r | |
83 | {\r | |
84 | EFI_STATUS Status;\r | |
85 | \r | |
86 | Status = EFI_SUCCESS;\r | |
87 | \r | |
88 | if (mTcp4Timer.RefCnt == 0) {\r | |
89 | \r | |
90 | Status = gBS->CreateEvent (\r | |
91 | EVT_TIMER | EVT_NOTIFY_SIGNAL,\r | |
e48e37fc | 92 | TPL_NOTIFY,\r |
8a67d61d | 93 | TcpTicking,\r |
94 | NULL,\r | |
95 | &mTcp4Timer.TimerEvent\r | |
96 | );\r | |
97 | if (!EFI_ERROR (Status)) {\r | |
98 | \r | |
99 | Status = gBS->SetTimer (\r | |
100 | mTcp4Timer.TimerEvent,\r | |
101 | TimerPeriodic,\r | |
102 | (UINT64) (TICKS_PER_SECOND / TCP_TICK_HZ)\r | |
103 | );\r | |
104 | }\r | |
105 | }\r | |
106 | \r | |
107 | if (!EFI_ERROR (Status)) {\r | |
108 | \r | |
109 | mTcp4Timer.RefCnt++;\r | |
110 | }\r | |
111 | \r | |
112 | return Status;\r | |
113 | }\r | |
114 | \r | |
115 | \r | |
116 | /**\r | |
117 | Stop and destroy the heartbeat timer for TCP driver.\r | |
85511ddf | 118 | \r |
8a67d61d | 119 | **/\r |
8a67d61d | 120 | VOID\r |
120db52c | 121 | Tcp4DestroyTimer (\r |
122 | VOID\r | |
123 | )\r | |
8a67d61d | 124 | {\r |
125 | ASSERT (mTcp4Timer.RefCnt > 0);\r | |
126 | \r | |
127 | mTcp4Timer.RefCnt--;\r | |
128 | \r | |
129 | if (mTcp4Timer.RefCnt > 0) {\r | |
130 | return;\r | |
131 | }\r | |
132 | \r | |
133 | gBS->SetTimer (mTcp4Timer.TimerEvent, TimerCancel, 0);\r | |
134 | gBS->CloseEvent (mTcp4Timer.TimerEvent);\r | |
135 | mTcp4Timer.TimerEvent = NULL;\r | |
136 | }\r | |
137 | \r | |
85511ddf | 138 | /**\r |
120db52c | 139 | The entry point for Tcp4 driver, used to install Tcp4 driver on the ImageHandle.\r |
85511ddf | 140 | \r |
141 | @param ImageHandle The firmware allocated handle for this\r | |
142 | driver image.\r | |
143 | @param SystemTable Pointer to the EFI system table.\r | |
144 | \r | |
145 | @retval EFI_SUCCESS Driver loaded.\r | |
146 | @retval other Driver not loaded.\r | |
8a67d61d | 147 | \r |
85511ddf | 148 | **/\r |
8a67d61d | 149 | EFI_STATUS\r |
150 | EFIAPI\r | |
151 | Tcp4DriverEntryPoint (\r | |
152 | IN EFI_HANDLE ImageHandle,\r | |
153 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
154 | )\r | |
8a67d61d | 155 | {\r |
156 | EFI_STATUS Status;\r | |
157 | UINT32 Seed;\r | |
158 | \r | |
159 | //\r | |
160 | // Install the TCP4 Driver Binding Protocol\r | |
161 | //\r | |
83cbd279 | 162 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
8a67d61d | 163 | ImageHandle,\r |
164 | SystemTable,\r | |
165 | &mTcp4DriverBinding,\r | |
166 | ImageHandle,\r | |
167 | &gTcp4ComponentName,\r | |
83cbd279 | 168 | &gTcp4ComponentName2\r |
8a67d61d | 169 | );\r |
da1d0201 | 170 | ASSERT_EFI_ERROR (Status);\r |
8a67d61d | 171 | //\r |
172 | // Initialize ISS and random port.\r | |
173 | //\r | |
174 | Seed = NetRandomInitSeed ();\r | |
175 | mTcpGlobalIss = NET_RANDOM (Seed) % mTcpGlobalIss;\r | |
120db52c | 176 | mTcp4RandomPort = (UINT16) (TCP4_PORT_KNOWN +\r |
4eb65aff | 177 | (UINT16) (NET_RANDOM(Seed) % TCP4_PORT_KNOWN));\r |
8a67d61d | 178 | \r |
179 | return Status;\r | |
180 | }\r | |
181 | \r | |
182 | \r | |
183 | /**\r | |
dfc1f033 | 184 | Tests to see if this driver supports a given controller.\r |
185 | \r | |
186 | If a child device is provided, it further tests to see if this driver supports \r | |
187 | creating a handle for the specified child device.\r | |
188 | \r | |
189 | @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
190 | @param ControllerHandle The handle of the controller to test. This handle \r | |
191 | must support a protocol interface that supplies \r | |
192 | an I/O abstraction to the driver.\r | |
193 | @param RemainingDevicePath A pointer to the remaining portion of a device path. \r | |
194 | This parameter is ignored by device drivers, and is optional for bus drivers.\r | |
195 | \r | |
196 | \r | |
197 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
198 | RemainingDevicePath is supported by the driver \r | |
199 | specified by This.\r | |
200 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
201 | RemainingDevicePath is already being managed by \r | |
202 | the driver specified by This.\r | |
203 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
204 | RemainingDevicePath is already being managed by a \r | |
205 | different driver or an application that requires \r | |
206 | exclusive access.\r | |
207 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
208 | RemainingDevicePath is not supported by the driver \r | |
209 | specified by This.\r | |
210 | \r | |
8a67d61d | 211 | **/\r |
212 | EFI_STATUS\r | |
213 | EFIAPI\r | |
214 | Tcp4DriverBindingSupported (\r | |
120db52c | 215 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
8a67d61d | 216 | IN EFI_HANDLE ControllerHandle,\r |
120db52c | 217 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r |
8a67d61d | 218 | )\r |
219 | {\r | |
220 | EFI_STATUS Status;\r | |
221 | \r | |
222 | //\r | |
223 | // Test for the Tcp4ServiceBinding Protocol\r | |
224 | //\r | |
225 | Status = gBS->OpenProtocol (\r | |
226 | ControllerHandle,\r | |
227 | &gEfiTcp4ServiceBindingProtocolGuid,\r | |
228 | NULL,\r | |
229 | This->DriverBindingHandle,\r | |
230 | ControllerHandle,\r | |
231 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
232 | );\r | |
233 | if (!EFI_ERROR (Status)) {\r | |
234 | return EFI_ALREADY_STARTED;\r | |
235 | }\r | |
236 | \r | |
237 | //\r | |
238 | // Test for the Ip4 Protocol\r | |
239 | //\r | |
240 | Status = gBS->OpenProtocol (\r | |
241 | ControllerHandle,\r | |
242 | &gEfiIp4ServiceBindingProtocolGuid,\r | |
243 | NULL,\r | |
244 | This->DriverBindingHandle,\r | |
245 | ControllerHandle,\r | |
246 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
247 | );\r | |
248 | \r | |
249 | return Status;\r | |
250 | }\r | |
251 | \r | |
252 | \r | |
253 | /**\r | |
dfc1f033 | 254 | Start this driver on ControllerHandle. \r |
255 | \r | |
256 | The Start() function is designed to be invoked from the EFI boot service \r | |
257 | ConnectController(). As a result, much of the error checking on the parameters \r | |
258 | to Start() has been moved into this common boot service. It is legal to call \r | |
259 | Start() from other locations, but the following calling restrictions must be \r | |
260 | followed or the system behavior will not be deterministic.\r | |
261 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
262 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally \r | |
263 | aligned EFI_DEVICE_PATH_PROTOCOL.\r | |
264 | 3. Prior to calling Start(), the Supported() function for the driver specified \r | |
265 | by This must have been called with the same calling parameters, and Supported() \r | |
266 | must have returned EFI_SUCCESS.\r | |
267 | \r | |
268 | @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
269 | @param ControllerHandle The handle of the controller to start. This handle \r | |
270 | must support a protocol interface that supplies \r | |
271 | an I/O abstraction to the driver.\r | |
272 | @param RemainingDevicePath A pointer to the remaining portion of a device path. \r | |
273 | This parameter is ignored by device drivers, and is \r | |
274 | optional for bus drivers.\r | |
275 | \r | |
276 | @retval EFI_SUCCESS The device was started.\r | |
277 | @retval EFI_ALREADY_STARTED The device could not be started due to a device error.\r | |
278 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack \r | |
279 | of resources.\r | |
8a67d61d | 280 | \r |
281 | **/\r | |
282 | EFI_STATUS\r | |
283 | EFIAPI\r | |
284 | Tcp4DriverBindingStart (\r | |
120db52c | 285 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
8a67d61d | 286 | IN EFI_HANDLE ControllerHandle,\r |
120db52c | 287 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r |
8a67d61d | 288 | )\r |
289 | {\r | |
290 | EFI_STATUS Status;\r | |
291 | TCP4_SERVICE_DATA *TcpServiceData;\r | |
292 | IP_IO_OPEN_DATA OpenData;\r | |
293 | \r | |
e48e37fc | 294 | TcpServiceData = AllocateZeroPool (sizeof (TCP4_SERVICE_DATA));\r |
8a67d61d | 295 | \r |
296 | if (NULL == TcpServiceData) {\r | |
e48e37fc | 297 | DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Have no enough"\r |
dfc1f033 | 298 | " resource to create a Tcp Servcie Data\n"));\r |
8a67d61d | 299 | \r |
300 | return EFI_OUT_OF_RESOURCES;\r | |
301 | }\r | |
302 | \r | |
303 | //\r | |
304 | // Create a new IP IO to Consume it\r | |
305 | //\r | |
fb115c61 | 306 | TcpServiceData->IpIo = IpIoCreate (\r |
307 | This->DriverBindingHandle,\r | |
308 | ControllerHandle,\r | |
309 | IP_VERSION_4\r | |
310 | );\r | |
8a67d61d | 311 | if (NULL == TcpServiceData->IpIo) {\r |
312 | \r | |
e48e37fc | 313 | DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Have no enough"\r |
dfc1f033 | 314 | " resource to create an Ip Io\n"));\r |
8a67d61d | 315 | \r |
316 | Status = EFI_OUT_OF_RESOURCES;\r | |
c4a62a12 | 317 | goto ON_ERROR;\r |
8a67d61d | 318 | }\r |
319 | \r | |
320 | //\r | |
321 | // Configure and start IpIo.\r | |
322 | //\r | |
e48e37fc | 323 | ZeroMem (&OpenData, sizeof (IP_IO_OPEN_DATA));\r |
8a67d61d | 324 | \r |
fb115c61 | 325 | CopyMem (\r |
326 | &OpenData.IpConfigData.Ip4CfgData,\r | |
327 | &mIp4IoDefaultIpConfigData,\r | |
328 | sizeof (EFI_IP4_CONFIG_DATA)\r | |
329 | );\r | |
330 | \r | |
331 | OpenData.IpConfigData.Ip4CfgData.DefaultProtocol = EFI_IP_PROTO_TCP;\r | |
8a67d61d | 332 | \r |
333 | OpenData.PktRcvdNotify = Tcp4RxCallback;\r | |
334 | Status = IpIoOpen (TcpServiceData->IpIo, &OpenData);\r | |
335 | \r | |
336 | if (EFI_ERROR (Status)) {\r | |
c4a62a12 | 337 | goto ON_ERROR;\r |
8a67d61d | 338 | }\r |
339 | \r | |
340 | //\r | |
341 | // Create the timer event used by TCP driver\r | |
342 | //\r | |
343 | Status = Tcp4CreateTimer ();\r | |
344 | if (EFI_ERROR (Status)) {\r | |
345 | \r | |
e48e37fc | 346 | DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Create TcpTimer"\r |
8a67d61d | 347 | " Event failed with %r\n", Status));\r |
348 | \r | |
c4a62a12 | 349 | goto ON_ERROR;\r |
8a67d61d | 350 | }\r |
351 | \r | |
352 | //\r | |
353 | // Install the Tcp4ServiceBinding Protocol on the\r | |
354 | // controller handle\r | |
355 | //\r | |
356 | TcpServiceData->Tcp4ServiceBinding = mTcp4ServiceBinding;\r | |
357 | \r | |
358 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
359 | &ControllerHandle,\r | |
360 | &gEfiTcp4ServiceBindingProtocolGuid,\r | |
361 | &TcpServiceData->Tcp4ServiceBinding,\r | |
362 | NULL\r | |
363 | );\r | |
364 | if (EFI_ERROR (Status)) {\r | |
365 | \r | |
e48e37fc | 366 | DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStart: Install Tcp4 Service Binding"\r |
8a67d61d | 367 | " Protocol failed for %r\n", Status));\r |
368 | \r | |
c4a62a12 | 369 | Tcp4DestroyTimer ();\r |
370 | goto ON_ERROR;\r | |
8a67d61d | 371 | }\r |
372 | \r | |
373 | //\r | |
374 | // Initialize member in TcpServiceData\r | |
375 | //\r | |
376 | TcpServiceData->ControllerHandle = ControllerHandle;\r | |
377 | TcpServiceData->Signature = TCP4_DRIVER_SIGNATURE;\r | |
378 | TcpServiceData->DriverBindingHandle = This->DriverBindingHandle;\r | |
379 | \r | |
e48e37fc | 380 | InitializeListHead (&TcpServiceData->SocketList);\r |
c4a62a12 | 381 | \r |
8a67d61d | 382 | TcpSetVariableData (TcpServiceData);\r |
383 | \r | |
384 | return EFI_SUCCESS;\r | |
385 | \r | |
c4a62a12 | 386 | ON_ERROR:\r |
8a67d61d | 387 | \r |
c4a62a12 | 388 | if (TcpServiceData->IpIo != NULL) {\r |
389 | IpIoDestroy (TcpServiceData->IpIo);\r | |
390 | }\r | |
8a67d61d | 391 | \r |
e48e37fc | 392 | gBS->FreePool (TcpServiceData);\r |
8a67d61d | 393 | \r |
394 | return Status;\r | |
395 | }\r | |
396 | \r | |
397 | \r | |
398 | /**\r | |
399 | Stop this driver on ControllerHandle.\r | |
dfc1f033 | 400 | \r |
401 | The Stop() function is designed to be invoked from the EFI boot service \r | |
402 | DisconnectController(). As a result, much of the error checking on the parameters \r | |
403 | to Stop() has been moved into this common boot service. It is legal to call Stop() \r | |
404 | from other locations, but the following calling restrictions must be followed \r | |
405 | or the system behavior will not be deterministic.\r | |
406 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call \r | |
407 | to this same driver's Start() function.\r | |
408 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
409 | EFI_HANDLE. In addition, all of these handles must have been created in this \r | |
410 | driver's Start() function, and the Start() function must have called OpenProtocol() \r | |
411 | on ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
412 | \r | |
413 | @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
414 | @param ControllerHandle A handle to the device being stopped. The handle must \r | |
415 | support a bus specific I/O protocol for the driver \r | |
416 | to use to stop the device.\r | |
417 | @param NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
418 | @param ChildHandleBuffer An array of child handles to be freed. May be NULL if \r | |
419 | NumberOfChildren is 0.\r | |
8a67d61d | 420 | \r |
dfc1f033 | 421 | @retval EFI_SUCCESS The device was stopped.\r |
422 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
8a67d61d | 423 | \r |
424 | **/\r | |
425 | EFI_STATUS\r | |
426 | EFIAPI\r | |
427 | Tcp4DriverBindingStop (\r | |
428 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
429 | IN EFI_HANDLE ControllerHandle,\r | |
430 | IN UINTN NumberOfChildren,\r | |
431 | IN EFI_HANDLE *ChildHandleBuffer\r | |
432 | )\r | |
433 | {\r | |
434 | EFI_STATUS Status;\r | |
435 | EFI_HANDLE NicHandle;\r | |
c4a62a12 | 436 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r |
8a67d61d | 437 | TCP4_SERVICE_DATA *TcpServiceData;\r |
8a67d61d | 438 | SOCKET *Sock;\r |
8a67d61d | 439 | \r |
440 | // Find the NicHandle where Tcp4 ServiceBinding Protocol is installed.\r | |
441 | //\r | |
442 | NicHandle = NetLibGetNicHandle (ControllerHandle, &gEfiIp4ProtocolGuid);\r | |
443 | if (NicHandle == NULL) {\r | |
c4a62a12 | 444 | return EFI_DEVICE_ERROR;\r |
8a67d61d | 445 | }\r |
446 | \r | |
447 | //\r | |
448 | // Retrieve the TCP driver Data Structure\r | |
449 | //\r | |
450 | Status = gBS->OpenProtocol (\r | |
451 | NicHandle,\r | |
452 | &gEfiTcp4ServiceBindingProtocolGuid,\r | |
c4a62a12 | 453 | (VOID **) &ServiceBinding,\r |
8a67d61d | 454 | This->DriverBindingHandle,\r |
455 | ControllerHandle,\r | |
456 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
457 | );\r | |
458 | if (EFI_ERROR (Status)) {\r | |
459 | \r | |
e48e37fc | 460 | DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingStop: Locate Tcp4 Service "\r |
8a67d61d | 461 | " Binding Protocol failed with %r\n", Status));\r |
462 | \r | |
c4a62a12 | 463 | return EFI_DEVICE_ERROR;\r |
8a67d61d | 464 | }\r |
465 | \r | |
c4a62a12 | 466 | TcpServiceData = TCP4_FROM_THIS (ServiceBinding);\r |
8a67d61d | 467 | \r |
c4a62a12 | 468 | if (NumberOfChildren == 0) {\r |
8a67d61d | 469 | //\r |
c4a62a12 | 470 | // Uninstall TCP servicebinding protocol\r |
8a67d61d | 471 | //\r |
c4a62a12 | 472 | gBS->UninstallMultipleProtocolInterfaces (\r |
473 | NicHandle,\r | |
474 | &gEfiTcp4ServiceBindingProtocolGuid,\r | |
475 | ServiceBinding,\r | |
476 | NULL\r | |
477 | );\r | |
8a67d61d | 478 | \r |
c4a62a12 | 479 | //\r |
480 | // Destroy the IpIO consumed by TCP driver\r | |
481 | //\r | |
482 | IpIoDestroy (TcpServiceData->IpIo);\r | |
8a67d61d | 483 | \r |
c4a62a12 | 484 | //\r |
485 | // Destroy the heartbeat timer.\r | |
486 | //\r | |
487 | Tcp4DestroyTimer ();\r | |
8a67d61d | 488 | \r |
c4a62a12 | 489 | //\r |
490 | // Clear the variable.\r | |
491 | //\r | |
492 | TcpClearVariableData (TcpServiceData);\r | |
8a67d61d | 493 | \r |
494 | //\r | |
c4a62a12 | 495 | // Release the TCP service data\r |
8a67d61d | 496 | //\r |
e48e37fc | 497 | gBS->FreePool (TcpServiceData);\r |
c4a62a12 | 498 | } else {\r |
8a67d61d | 499 | \r |
e48e37fc | 500 | while (!IsListEmpty (&TcpServiceData->SocketList)) {\r |
c4a62a12 | 501 | Sock = NET_LIST_HEAD (&TcpServiceData->SocketList, SOCKET, Link);\r |
8a67d61d | 502 | \r |
c4a62a12 | 503 | ServiceBinding->DestroyChild (ServiceBinding, Sock->SockHandle);\r |
8a67d61d | 504 | }\r |
505 | }\r | |
506 | \r | |
8a67d61d | 507 | return Status;\r |
508 | }\r | |
509 | \r | |
120db52c | 510 | /**\r |
511 | Open Ip4 and device path protocols for a created socket, and insert it in \r | |
512 | socket list.\r | |
513 | \r | |
514 | @param This Pointer to the socket just created\r | |
515 | @param Context Context of the socket\r | |
516 | \r | |
517 | @retval EFI_SUCCESS This protocol is installed successfully.\r | |
518 | @retval other Some error occured.\r | |
519 | \r | |
520 | **/\r | |
4f6e31e4 | 521 | EFI_STATUS\r |
522 | Tcp4CreateSocketCallback (\r | |
523 | IN SOCKET *This,\r | |
524 | IN VOID *Context\r | |
525 | )\r | |
526 | {\r | |
527 | EFI_STATUS Status;\r | |
528 | TCP4_SERVICE_DATA *TcpServiceData;\r | |
529 | EFI_IP4_PROTOCOL *Ip4;\r | |
530 | \r | |
531 | TcpServiceData = ((TCP4_PROTO_DATA *) This->ProtoReserved)->TcpService;\r | |
532 | \r | |
533 | //\r | |
534 | // Open the default Ip4 protocol of IP_IO BY_DRIVER.\r | |
535 | //\r | |
536 | Status = gBS->OpenProtocol (\r | |
537 | TcpServiceData->IpIo->ChildHandle,\r | |
538 | &gEfiIp4ProtocolGuid,\r | |
539 | (VOID **) &Ip4,\r | |
540 | TcpServiceData->DriverBindingHandle,\r | |
541 | This->SockHandle,\r | |
542 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
543 | );\r | |
544 | if (EFI_ERROR (Status)) {\r | |
545 | return Status;\r | |
546 | }\r | |
547 | \r | |
548 | //\r | |
549 | // Open the device path on the handle where service binding resides on.\r | |
550 | //\r | |
551 | Status = gBS->OpenProtocol (\r | |
552 | TcpServiceData->ControllerHandle,\r | |
553 | &gEfiDevicePathProtocolGuid,\r | |
554 | (VOID **) &This->ParentDevicePath,\r | |
555 | TcpServiceData->DriverBindingHandle,\r | |
556 | This->SockHandle,\r | |
557 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
558 | );\r | |
559 | if (EFI_ERROR (Status)) {\r | |
560 | gBS->CloseProtocol (\r | |
561 | TcpServiceData->IpIo->ChildHandle,\r | |
562 | &gEfiIp4ProtocolGuid,\r | |
563 | TcpServiceData->DriverBindingHandle,\r | |
564 | This->SockHandle\r | |
565 | );\r | |
566 | } else {\r | |
567 | //\r | |
568 | // Insert this socket into the SocketList.\r | |
569 | //\r | |
e48e37fc | 570 | InsertTailList (&TcpServiceData->SocketList, &This->Link);\r |
4f6e31e4 | 571 | }\r |
572 | \r | |
573 | return Status;\r | |
574 | }\r | |
575 | \r | |
120db52c | 576 | /**\r |
577 | Close Ip4 and device path protocols for a socket, and remove it from socket list. \r | |
578 | \r | |
579 | @param This Pointer to the socket to be removed\r | |
580 | @param Context Context of the socket\r | |
581 | \r | |
582 | **/\r | |
4f6e31e4 | 583 | VOID\r |
584 | Tcp4DestroySocketCallback (\r | |
585 | IN SOCKET *This,\r | |
586 | IN VOID *Context\r | |
587 | )\r | |
588 | {\r | |
589 | TCP4_SERVICE_DATA *TcpServiceData;\r | |
590 | \r | |
591 | TcpServiceData = ((TCP4_PROTO_DATA *) This->ProtoReserved)->TcpService;\r | |
592 | \r | |
593 | //\r | |
594 | // Remove this node from the list.\r | |
595 | //\r | |
e48e37fc | 596 | RemoveEntryList (&This->Link);\r |
4f6e31e4 | 597 | \r |
598 | //\r | |
599 | // Close the device path protocol\r | |
600 | //\r | |
601 | gBS->CloseProtocol (\r | |
602 | TcpServiceData->ControllerHandle,\r | |
603 | &gEfiDevicePathProtocolGuid,\r | |
604 | TcpServiceData->DriverBindingHandle,\r | |
605 | This->SockHandle\r | |
606 | );\r | |
607 | \r | |
608 | //\r | |
609 | // Close the Ip4 protocol.\r | |
610 | //\r | |
611 | gBS->CloseProtocol (\r | |
612 | TcpServiceData->IpIo->ChildHandle,\r | |
613 | &gEfiIp4ProtocolGuid,\r | |
614 | TcpServiceData->DriverBindingHandle,\r | |
615 | This->SockHandle\r | |
616 | );\r | |
617 | }\r | |
618 | \r | |
8a67d61d | 619 | /**\r |
dfc1f033 | 620 | Creates a child handle and installs a protocol.\r |
621 | \r | |
622 | The CreateChild() function installs a protocol on ChildHandle. If ChildHandle \r | |
623 | is a pointer to NULL, then a new handle is created and returned in ChildHandle. \r | |
624 | If ChildHandle is not a pointer to NULL, then the protocol installs on the existing \r | |
625 | ChildHandle.\r | |
626 | \r | |
627 | @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r | |
628 | @param ChildHandle Pointer to the handle of the child to create. If it is NULL, then \r | |
629 | a new handle is created. If it is a pointer to an existing UEFI \r | |
630 | handle, then the protocol is added to the existing UEFI handle.\r | |
631 | \r | |
632 | @retval EFI_SUCCES The protocol was added to ChildHandle.\r | |
633 | @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r | |
634 | @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create\r | |
635 | the child.\r | |
636 | @retval other The child handle was not created.\r | |
8a67d61d | 637 | \r |
638 | **/\r | |
639 | EFI_STATUS\r | |
640 | EFIAPI\r | |
641 | Tcp4ServiceBindingCreateChild (\r | |
276dcc1b | 642 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r |
643 | IN OUT EFI_HANDLE *ChildHandle\r | |
8a67d61d | 644 | )\r |
645 | {\r | |
646 | SOCKET *Sock;\r | |
647 | TCP4_SERVICE_DATA *TcpServiceData;\r | |
648 | TCP4_PROTO_DATA TcpProto;\r | |
649 | EFI_STATUS Status;\r | |
8a67d61d | 650 | EFI_TPL OldTpl;\r |
651 | \r | |
652 | if (NULL == This || NULL == ChildHandle) {\r | |
653 | return EFI_INVALID_PARAMETER;\r | |
654 | }\r | |
655 | \r | |
e48e37fc | 656 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
4f6e31e4 | 657 | Status = EFI_SUCCESS;\r |
8a67d61d | 658 | TcpServiceData = TCP4_FROM_THIS (This);\r |
659 | TcpProto.TcpService = TcpServiceData;\r | |
660 | TcpProto.TcpPcb = NULL;\r | |
661 | \r | |
662 | //\r | |
663 | // Create a tcp instance with defualt Tcp default\r | |
664 | // sock init data and TcpProto\r | |
665 | //\r | |
4f6e31e4 | 666 | mTcp4DefaultSockData.ProtoData = &TcpProto;\r |
667 | mTcp4DefaultSockData.DataSize = sizeof (TCP4_PROTO_DATA);\r | |
8a67d61d | 668 | mTcp4DefaultSockData.DriverBinding = TcpServiceData->DriverBindingHandle;\r |
e48e37fc | 669 | \r |
4f6e31e4 | 670 | Sock = SockCreateChild (&mTcp4DefaultSockData);\r |
8a67d61d | 671 | if (NULL == Sock) {\r |
e48e37fc | 672 | DEBUG ((EFI_D_ERROR, "Tcp4DriverBindingCreateChild: "\r |
8a67d61d | 673 | "No resource to create a Tcp Child\n"));\r |
674 | \r | |
675 | Status = EFI_OUT_OF_RESOURCES;\r | |
c4a62a12 | 676 | } else {\r |
4f6e31e4 | 677 | *ChildHandle = Sock->SockHandle;\r |
8a67d61d | 678 | }\r |
679 | \r | |
e48e37fc | 680 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 681 | return Status;\r |
682 | }\r | |
683 | \r | |
684 | \r | |
685 | /**\r | |
dfc1f033 | 686 | Destroys a child handle with a protocol installed on it.\r |
687 | \r | |
688 | The DestroyChild() function does the opposite of CreateChild(). It removes a protocol \r | |
689 | that was installed by CreateChild() from ChildHandle. If the removed protocol is the \r | |
690 | last protocol on ChildHandle, then ChildHandle is destroyed.\r | |
691 | \r | |
692 | @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r | |
693 | @param ChildHandle Handle of the child to destroy\r | |
694 | \r | |
695 | @retval EFI_SUCCES The protocol was removed from ChildHandle.\r | |
696 | @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is \r | |
697 | being removed.\r | |
698 | @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.\r | |
699 | @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r | |
700 | because its services are being used.\r | |
701 | @retval other The child handle was not destroyed.\r | |
702 | \r | |
8a67d61d | 703 | **/\r |
704 | EFI_STATUS\r | |
705 | EFIAPI\r | |
706 | Tcp4ServiceBindingDestroyChild (\r | |
707 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r | |
708 | IN EFI_HANDLE ChildHandle\r | |
709 | )\r | |
710 | {\r | |
711 | EFI_STATUS Status;\r | |
712 | EFI_TCP4_PROTOCOL *Tcp4;\r | |
713 | SOCKET *Sock;\r | |
8a67d61d | 714 | EFI_TPL OldTpl;\r |
715 | \r | |
716 | if (NULL == This || NULL == ChildHandle) {\r | |
717 | return EFI_INVALID_PARAMETER;\r | |
718 | }\r | |
719 | \r | |
e48e37fc | 720 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 721 | \r |
722 | //\r | |
723 | // retrieve the Tcp4 protocol from ChildHandle\r | |
724 | //\r | |
725 | Status = gBS->OpenProtocol (\r | |
726 | ChildHandle,\r | |
727 | &gEfiTcp4ProtocolGuid,\r | |
728 | (VOID **) &Tcp4,\r | |
729 | mTcp4DriverBinding.DriverBindingHandle,\r | |
730 | ChildHandle,\r | |
731 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
732 | );\r | |
733 | if (EFI_ERROR (Status)) {\r | |
734 | Status = EFI_UNSUPPORTED;\r | |
4f6e31e4 | 735 | } else {\r |
736 | //\r | |
737 | // destroy this sock and related Tcp protocol control\r | |
738 | // block\r | |
739 | //\r | |
740 | Sock = SOCK_FROM_THIS (Tcp4);\r | |
e5e12de7 | 741 | \r |
4f6e31e4 | 742 | SockDestroyChild (Sock);\r |
743 | }\r | |
8a67d61d | 744 | \r |
e48e37fc | 745 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 746 | return Status;\r |
747 | }\r | |
4f6e31e4 | 748 | \r |